zoukankan      html  css  js  c++  java
  • 物体围绕某个点旋转一定角度

    转自:https://dawnarc.com/2016/06/ue4%E7%BA%BF%E6%80%A7%E4%BB%A3%E6%95%B0%E7%89%A9%E4%BD%93%E5%9B%B4%E7%BB%95%E6%9F%90%E4%B8%AA%E7%82%B9%E6%97%8B%E8%BD%AC%E4%B8%80%E5%AE%9A%E8%A7%92%E5%BA%A6/

    2D上的点围绕某另一个点旋转: If you rotate point (px, py) around point (ox, oy) by angle theta you’ll get:

    p'x = cos(theta) * (px-ox) - sin(theta) * (py-oy) + ox
    p'y = sin(theta) * (px-ox) + cos(theta) * (py-oy) + oy
    

    this is an easy way to rotate a point in 2D.

    =======================================http://stackoverflow.com/questions/13275719/rotate-a-3d-point-around-another-one Try to use vector math. decide in which order you rotate, first along x, then along y perhaps.

    If you rotate along z, [z’ = z]

    x' = x*cos a - y*sin a;
    y' = x*sin a + y*cos a;  
    The same repeated for y-axis: [y'' = y']
    
    x'' = x'*cos b - z' * sin b;
    z'' = z'*sin b + x' * cos b;  
    Again rotating along x-axis: [x''' = x'']
    
    y''' = y'' * cos c - z'' * sin c
    z''' = z'' * sin c + y'' * cos c
    

    And finally the question of rotating around some specific “point”:

    First subtract the point from the coordinates, then apply the rotations and finally add the point back to the result.

    The problem, as far as I see, is a close relative to “gimbal lock”. The angle w_ny can’t be measured relative to the fixed xyz -coordinate system, but to the coordinate system that is rotated by applying the angle w_nx.

    As kakTuZ observed, your code converts point to spherical coordinates. There’s nothing inherently wrong with that – with longitude and latitude one can reach all the places in Earth. And if one doesn’t care about tilting the Earth equatorial plane relative to it’s trajectory around the Sun, it’s ok with me.

    The result of not rotating the next reference axis along the first w_ny is that two points that are 1 km a part of each other at equator, move closer each other at the poles and at latitude of 90 degrees, they touch. Even though the apparent purpose is to keep them 1 km apart where ever they are rotated.

    ================================== UE4中的实现方式

    FVector A;
    FVector B;
    FRotator C;
    

    A点绕B点旋转C之后的坐标:

    B+C.RotateVector(A-B)
    

    其他参考: Quaternions and spatial rotationhttps://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation

    Rotation matrix https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations

  • 相关阅读:
    sql分页 sql server,oracle,db2,mysql
    部分SQL优化
    javascript &&和||的其他用法
    socket 套接字
    网络协议篇
    异常处理
    元类type 反射 函数与方法 双下方法
    私有 实例方法 类方法 静态方法 属性 issubclass isinstance区别
    面向对象的三大特性 鸭子类型 类的约束 super的深度剖析
    继承
  • 原文地址:https://www.cnblogs.com/sevenyuan/p/9373931.html
Copyright © 2011-2022 走看看