- Home /

# Get the raod turn radius

So I have two Vector3s A and B they represent the beginning and the end of a road turn (for a racing game). They also look at the direction of the road. Now what I want is given these two vectors to find the radius of the circle that is created.

Here is a visual representation of what I want to find.

Note that in the shape I have vector2s because I dont care about the vector3.y so I have replaced the vector2.y with the vector3.z.

**Answer** by elenzil
·
Oct 23, 2017 at 01:13 AM

nice question.

so you have A and B as points on the circle, and then you also have vA and vB, the vectors *tangent* to the circle at those points. from those, you can create perpendicular vAP and vBP by rotating vA and vB 90º each. since they're perpendicular to the tangents, that means they're *normal* to the surface of the circle, and they will intersect at the center of the circle.

There's a billion line-intersection routines in the world, and LineLineIntersection() from here looks reasonable.

There's a couple edge-cases where this approach won't work: 1. if points A and B are the same, it's impossible to know. also as vA and vB approach being parallel or anti-parallel, the accuracy will decrease. 2. if A and B are on exactly opposite sides of the circle, then the line-intersection approach will not yield a specific solution. I would add some logic before the line-intersection stuff which tests the dot-product of vAN and vBN. (vAN = the normalized version of vA). if that value is close to -1 (eg, less that -0.999, say) then you can conclude that A and B are on opposite sides of the circle, and the center of the circle is (A + B) / 2.

also in general, when you need functions for stuff like line-intersect-line, you can't do better than to visit the pages of Paul Bourke. he's correct and succinct.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.