2024-12-11【Math】Vector2 Local XY

    // Returns the local direction of V2 relative to V1
    public static Vector2 GetLocalDirection(Vector2 V1, Vector2 V2)
    {
        // Normalize V1 to ensure it represents forward direction
        Vector2 forward = V1.normalized;

        // Calculate the right-hand perpendicular vector
        Vector2 right = new Vector2(forward.y, -forward.x);

        // Compute the difference vector from V1 to V2
        Vector2 difference = V2 - V1;

        // Project the difference onto the forward and right vectors
        float localY = Vector2.Dot(difference, forward); // Projection onto forward
        float localX = Vector2.Dot(difference, right);   // Projection onto right

        // Return the local direction
        return new Vector2(localX, localY);
    }
image.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 评:部分聚会处批于闹剧 接连好长一段时间,明星传道人于宏洁被大陆多处聚会处群殴了。事情的起因好像始于出生上海聚会处...
    92ebde2ecb21阅读 9,315评论 4 2
  • 对于生命本身来说,自由舒展算是其最为理想的生存状态。与之相应的是,人类文明的所有创建,也应当以此为价值导向,因为只...
    来者2024阅读 536评论 0 3
  • 一、Widget的生命周期 1、StatelessWidget 2、StatefullWidget 二、Flutt...
    woniu阅读 1,131评论 0 0
  • 周中5天积累的能量,总是在周末2天消耗殆尽。 打女儿升入初中,深感我好像已没有能力忍住那一声声吼叫,以至于矛盾激化...
    RunningAn阅读 43评论 0 0
  • 冯唐说:“如果你熬到一个人喝茶,一个人散步,一个人旅行,一个人看书,没有电话,没有邀约,没有聚会,没有一些所谓的社...
    佳依我心阅读 694评论 0 2