• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Diablo404 · Mar 19, 2013 at 07:25 AM · vector3tangentperpendicularcross

Find the tangent or maybe the perpendicular line?

Hello everyone,

I would like to simulate a graphic perspective work in Unity. Problem is that I'm really not comfortable with Mathematics.

So basically, I want to find the 2 tangents of the sphere, where (in the picture) I use just the top and the bottom.alt text

From the researches I've done, I know the tangent is findable I use my first point to the center of the sphere, and then use Vector3.Cross to find it's perpendicular line and then re use again. But I can't find a way to make it work properly because I don't understand all the mathematics notions included.

Can anyone explain me a bit how to reach that?

Thanks in advance!

Links visited: http://answers.unity3d.com/questions/133680/how-do-you-find-the-tangent-from-a-given-normal.html

http://answers.unity3d.com/questions/338537/great-circle-trajectories-around-a-sphere.html

pers.png (5.1 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Mar 19, 2013 at 08:14 AM 1
Share

"I would like to simulate a graphic perspective work in Unity. Problem is that I'm really not comfortable with $$anonymous$$athematics."

it's probably fair to say you will struggle. You will really need to learn a lot of junior school geometry and arithmetic to do this, so, treat the whole thing as an exercise in learning schoolbook geometry and arithmetic!

Enjoy !

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by robertbu · Mar 19, 2013 at 07:42 AM

Grab three pencils out of your pencil cup. Hold the eraser ends together and allow the points to splay out. You have two rays. Both of those rays are on a plane. If I rotate them around, the plane changes, but as long as they are pointing in separate directions, they the two rays always define a plane. Now take a third pencil place its eraser at the same position as the other two, but perpendicular to the plane defined by the first two. That is the cross product. Whether the third pencil points "up" or "down" will depend on the order you crossed the first two pencils.

From your diagram, you have one of the two "pencils" defined...the ray from the center of the sphere to the point. But that still leaves you with the need to have a second ray. It could be from the center of the sphere to the camera for example. So let's say we have the position of the camera and the position of your point as the two rays. Your code might look like.

 ray1 = point1 - shpere.transform.position;
 ray2 = Camera.main.transform.position - sphere.transform.position;
 axisRay = Vector3.Cross(ray1, ray2);
 tangentPoint1 = axisRay.normalized * sphere_radius + sphere.transform.position;
 tangentPoint2 = -axisRay.normalized * sphere_radius + sphere.transform.position;;
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Diablo404 · Mar 19, 2013 at 07:52 AM 0
Share

Well, that's really near from what I wanted. First, am I correct if I say that I could have used a simple Vector3.Up ins$$anonymous$$d of the Camera.main.transform.position? Can you just explain a little bit about the .normalized ? I don't get it. Exept that, it works really good until a certain angle ( where the sphere is aprox 90°deg of the original point. Thanks for the very quick and helpfull answer!

avatar image robertbu · Mar 19, 2013 at 08:15 AM 0
Share

Any vector will work as long as it is not the same vector (or facing opposite of that vector) as the one from the sphere to the point. You need to different vectors to define the plane. Vector3.normalized returns a vector where the magnitude is 1, so multiplying that by the radius gives a vector from the sphere center to the edge of the sphere. Add the position of the object, and you have a world position.

avatar image Fattie · Mar 19, 2013 at 08:15 AM 0
Share

normalized just means you take a vector, and make it length one.

avatar image sparkzbarca · Mar 19, 2013 at 08:34 AM 0
Share

normalized takes a vector and gives it a magnitude of 1.

magnitude is the length of the line

basically it makes it fit into the unit circle more specifically and this should make it clearer

a normalized vector IS THE SLOPE of the vector. its how much it moves in the x y and z direction every single movement.

its not working well because you can't cross 2 identical lines.

if you imagine a 2d space the tangent is just a line 90 degrees.

however in 3d space it gets wierder.

If you place a pencil through the whole in a cd and draw a line from the pencil to the edge of the cd any line you can draw is tangent.

In 3D space it doesn't make sense to speak of the tangent of a line. Because every line has an infinite amount.

Every direction a clock hand points is always tangent to the screw holding it in.

Ins$$anonymous$$d in 3D space you speak of the tangent OF A PLAN$$anonymous$$

thats an line that is 90 degrees to the face of the plane in any direction.

A plane however cannot be define by a line.

Vector3.cross basicalyl returns the tangent of a plane. (the normal) However it takes 2 vectors only because any two non paralle vectors do in fact define a plane. It really wants 2 planes but in the same sense that you can take two points and connect them and as long as there not the same point get a line. you can take take 2 directions expand them and get a plane. so long as there not the same line. But these are at 90degrees. thats why what you get back is wierd. there are an infinite amount of answers cause your asking for the tangent to a line.

avatar image
1

Answer by Tarlius · Mar 19, 2013 at 08:28 AM

For a distant circle, that would be a good approximation, but for a close circle, it will fall apart. If you use a perpendicular from the centre point, the tangent will be parallel to your first vector (or it won't be a tangent). The right-angle needs to be between your point, the point the tangent touches the circle and the centre.

(Assuming: A = your point; B = Perpendicular point; C = centre) Given that CBA is a right-angle, you have a right angled triangle in ABC. I assume you know how big the circle is, and you said you have the vector from the centre to the point.

From there you can use some simple trig to get the angle ACB. BCA = invCos(BC/CA) You can then multiply the vector AC by quaternions to rotate it (you'll need to do it for + and - the angle), normalise it and multiply by the radius of the circle to get your points.

Normalising makes the "distance" = 1 (ie x^2 + y^2 = 1)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Mar 19, 2013 at 09:36 AM 0
Share

You right. I didn't think it through.

avatar image
0

Answer by Diablo404 · Mar 19, 2013 at 09:19 AM

That's a lot for an answer. Thanks to all the contributors. Of course like Fattie said, I've to learn the basics to get a better understanding of all of this. But the fact is all the answers of this questions are Unity oriented, so it will simplify the practice. Thanks!

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Tarlius · Mar 19, 2013 at 09:33 AM 0
Share

You don't need an in-depth understanding, the libraries already do all the complex number-crunching for you. You just need a basic idea and the motivation to mess around, and pick it up as you go. Just hit/hack it until it works, like any engineer :)

avatar image sparkzbarca · Mar 19, 2013 at 09:47 AM 0
Share

yea just understand that cross means the vector of a plane.

Plane requires 2 lines not parallel

normalize is the slope of a line.

You don't need to know how to normalize just what it is.

or how to cross just the result.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to get a perpendicular vector for wall-jumping 2 Answers

Find segment point perpendicular to plane 1 Answer

How do you find the tangent from a given normal? 2 Answers

How to change Vector3 movement by degrees/to a perpendicular axis? 0 Answers

Perpendicular to a 3D direction vector 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges