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.9078-pers.png

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:

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;;

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)

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!