# Finding a point on the edge of a circle from a point offset from its centre in a certain direction

How would I find the point on the edge of a circle (the green point on the diagram below) in a certain direction (indicated by the arrow) from a point inside of the circle (the red point) in Unity? I know the start point inside the circle, the circles circumference and the direction however I'm at a loss on how to calculate this (trigonometry is not my strong suit).

• Google line circle intersection. There are thousands if not millions of articles about this topic. Commented Dec 21, 2022 at 23:09
• How I would approach this: from the point/direction, get a line equation, then use your favourite search engine to find the way to get the intersection between the line and the circle; this will give you 0, 1 or 2 results; use the direction that you have to figure which of the two points is the "correct" one. Commented Dec 21, 2022 at 23:16
• I already spent a long time doing just that @tkausl, all the Unity/C# examples I found revolve around the point being centre of the circle, not offset from the centre. Please do feel free to link to an example though if you find one. Commented Dec 23, 2022 at 12:40

Here is the general method you will want to use.

Here, I assume that the circle center is at coordinate $$(x_0, y_0)$$ the red point is at coordinate $$(x_1, y_1)$$ and your final coordinate is given by $$(x_f, y_f)$$

Also note that the angle $$\theta$$ can be found by finding the angle between the unit vector in the given direction and the unit vector in the y-direction (0, 1).

Solve these systems of equations to get your desired final coordinates

As an example say the circle is centered at (0, 0), and our directional vector is in the +y direction as you've shown in your example (0, 1). Then theta = 0, costheta = 1 and sintheta = 0. Solving we get:

$$x_f = x_1$$ $$y_f = y_1 + ((x_f - x_1)^2 + (y_f - y_1)^2)^{1/2}$$ $$x_f^2 + y_f^2 = r^2$$

Subbing in for y_f we get

$$y_f^2 = r^2 - x_1^2$$

Thus your final position in terms of the radius and position of the red point is $$x_f = x_1$$ $$y_f = \sqrt{r^2 - x_1^2}$$

• Thank you for the detailed response, much appreciated Commented Dec 23, 2022 at 12:36