i have a line that goes through a circle. how can i find intersection points?
Hi. I have an point on edge of a circle and a direction where that point facing. When i draw a ray from that point i want that line to end at other edge of circle but i don't know how can i calculate that point because that line does not go from center(if it would then length of line would be same as diameter of circle). if i can find the other point then i can calculate the length of it by using chord of circle formula which is what i actually need.

Answer by Hellium · Aug 15, 2019 at 01:45 PM
Let's take the following image representing your situation.

O is the center of the circle
A is the point you know
B is the point you are looking for
v is the direction vector you know
α is the angle between AO and AB vectors
ω is the angle between OA and OB vectors
Because AOB is an isosceles triangle, the OAB and OBA angles are equal. And the sum of the angles of a triangle = 180°.
Pseudo code
 α  = Angle( O - A, v )
 ω  = 180 - 2 * a // because ω + α + α = 180
 BO = Rotate(A - O, ω)
 B  = O + BO
Translated in C#:
 private Vector3 ComputeB( Vector3 circleCenter, Vector3 circleNormal, Vector3 point, Vector3 direction )
 {
     float a = Vector3.SignedAngle( circleCenter - point, direction, circleNormal );
     float w = 0;
     if ( a >= 0 ) w = 180 - 2 * a; // because w + a + a = 180;
     else w = -( 180 + 2 * a );
     Vector3 BO = Quaternion.AngleAxis(w, -circleNormal) * (point - circleCenter);
     return circleCenter + BO;
 }
[SOLVED]Problem was y axis of center wasn't same as other positions and this caused miscalculations on angles.
Old Problem: Hey. Thanks you for your answer but i made few tests and it looks like there is have an offset to point. Can this be because of - 90 degree unity thing because unity handles rotation differently?
(it should be on top of red point on image but it's not and i did give the same direction as line's direction)


The images are broken, can you upload them again?
When I tested, it seemed to work fine.

Your answer
 
 
             Follow this Question
Related Questions
Circle-line Intersection Points 3 Answers
Find "real" rotation of box mesh 0 Answers
Hexagonal geodesic map 0 Answers
Intersection of a Plane and an object 0 Answers
Detecting if line cuts Polygon 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                
