Language

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.

1 Reply

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