我们必须找到这个圆弧和圆心的角度。
首先找到半径。
R^2 = (d/2)^2 + (R-d/3)^2 //pythagorean
R = 13/24 * d
Run Code Online (Sandbox Code Playgroud)
现在角
half_angle = arcsin(12/13) ~ 67.4 degrees
angle = 2 * half_angle ~ 135 degrees = 2.35 radians
Run Code Online (Sandbox Code Playgroud)
标准化 perp 向量
uperp = perp / len(perp)
Run Code Online (Sandbox Code Playgroud)
获取圆心
M = (P0 + P1)/2 //chord middle
C = M + uperp * 5/24 * d
Run Code Online (Sandbox Code Playgroud)
起始角度
A0 = atan2(P0.Y-C.Y, P0.X-C.X)
Run Code Online (Sandbox Code Playgroud)
最后坐标
Car.X = C.X + R * Cos(A0 + t * angle)
Car.Y = C.Y + R * Sin(A0 + t * angle)
Run Code Online (Sandbox Code Playgroud)
在 Unity 中,这看起来像:
Vector2 startPosition;
Vector2 endPosition;
Vector2 perp;
float t;
float d = (endPosition - startPosition).magnitude;
float radius = 13f/24f * d;
float angle = 2f * Mathf.Asin(12f/13f);
Vector2 uperp = perp.normalized;
Vector2 M = (startPosition+endPosition)*0.5f;
Vector2 C = M + uperp * 5f/24f * d;
float A0 = Mathf.Atan2(startPosition.y-C.y, startPosition.x-C.x);
float At = A0 + t * angle;
Vector2 newPos = C + radius * new Vector2(Mathf.Cos(At), Mathf.Sin(At));
Run Code Online (Sandbox Code Playgroud)