【问题标题】:How to move n degrees from vector point A along the circumference of a circle? (image included)如何从矢量点 A 沿圆周移动 n 度? (包括图片)
【发布时间】:2014-08-20 17:22:48
【问题描述】:

A、B 和 Center 是 2D 矢量点。

n 是圆从 A 到 B 的周长。

我想得到 B。

我正在寻找一种方法来弹出 A、Center、n 和圆的半径以弹出矢量点 B。

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

【问题讨论】:

标签: vector unity3d geometry pi


【解决方案1】:

所有角度都以弧度表示。你的 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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-05
    • 2019-02-13
    • 2016-10-06
    • 1970-01-01
    • 2014-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多