如何从矢量点A沿圆周移动n度?(包括图片)

Sky*_*nor 5 geometry pi vector unity-game-engine

在此输入图像描述

A,B和Center是2D矢量点.

n是从A到B的圆周长.

我想得到B.

我正在寻找一种方法来弹出A,中心,n和圆的半径以弹出矢量点B.

(我使用Mathf在Unity中使用C#进行编码,但我不需要代码作为答案,只需要一些基本步骤就可以提供更多帮助,谢谢)

Ima*_*ler 3

所有角度均以弧度为单位。你的 n 就是所谓的圆弧。

public Vector2 RotateByArc(Vector2 Center, Vector2 A, float arc)
{
    //calculate radius
    float radius = Vector2.Distance(Center, A);

    //calculate angle from arc
    float angle = arc / radius;

    Vector2 B = RotateByRadians(Center, A, angle);

    return B;
}

public Vector2 RotateByRadians(Vector2 Center, Vector2 A, float angle)
{
    //Move calculation to 0,0
    Vector2 v = A - Center;

    //rotate x and y
    float x = v.x * Mathf.Cos(angle) + v.y * Mathf.Sin(angle);
    float y = v.y * Mathf.Cos(angle) - v.x * Mathf.Sin(angle);

    //move back to center
    Vector2 B = new Vector2(x, y) + Center;

    return B;
}
Run Code Online (Sandbox Code Playgroud)