Lerp to a point in a circle given the radius.

alt text

Good day! Above is an illustration of my problem.

What I want to do is Lerp the position and rotation of my main camera from it’s current position to position x. I know about how to lerp the position and rotation. The thing I want to know is how can I find point x given radius (line from center to the farthest object).

The camera must lerp moving backward and slowly facing the center so that it’s distance from the center is the same as the distance of the farthest object from the center.

At first I thought of just lerping the camera to the position of the farthest object, but the screen whirls around in a weird fashion. It also makes me dizzy hahaha.

Can someone help me with this…math? Thank you very much in advance!

EDIT: Also, the farthest object and the camera position is not fixed. It changes from time to time because of the nature of the game. My key terms here are the farthest point, the center, the camera’s current position and the point x which is the unknown.

You know the camera position, and the direction it needs to move. You also know the circle center and radius. So this boils down to a line-circle intersection…

Here is a generalized implementation…

It can probably be greatly simplified for your case, but by brain doesn’t do math on Monday mornings.

Somebody answered my question from the forums and he got it.

alt text

And this is the code.

 Vector3 O, F, A, C;

        float radius = ( O - F ).magnitude;

        float Angle = Mathf.Deg2Rad * ( 180 - Vector3.Angle( O - C, A - C ) );

        float Temp = radius / Mathf.Sin( Angle );

        float CP = Temp * Mathf.Sin( Mathf.PI - Angle - Mathf.Asin( ( O - C ).magnitude / Temp ) );

        Vector3 P = C + ( C - A ).normalized * CP;

Credits to hpjohn. (rather)