【问题标题】:How can I get an angle 45 degrees relative to another angleHow can I get an angle 45 degrees relative to another angle
【发布时间】:2022-12-02 01:04:04
【问题描述】:

I need to get the angle of the blue line in the image. Assuming I have the angle of the red line, how would I get that?

【问题讨论】:

  • That would be vector math. Treating the red as a vector from the leftmost point to the rightmost red = {xR - xL, yR - yL};, you'd then do a 2D vector rotation. Note for 45 degrees there's a massive simplification: cos(45 deg) == sin(45 deg) == 1 / sqrt(2). If you want the center of the circle as the origin, then your vector is the outer point - the origin point. Note this does not include scaling (scalar multiplication of the vector) as done in your images.
  • @Rogue But sin(45 deg) is 40.514233 degrees which is not the angle of the blue line? Yes the centre of the circle is the origin.
  • Mental typo, was thinking of 30 deg. sin(45 deg) is 1/sqrt(2) ~= 0.7071, which is a scalar value (no units, i.e. degrees). Definitely not 40.514233.

标签: java game-development angle


【解决方案1】:

For two (directional) vectors v1 and v2 and the angle a between those vectors, the equation

v1 * v2 = |v1||v2| cos a

holds. v1 * v2 denotes the dot product of these vectors and |v| denotes the Euclidean norm of the vector. Thus

a = arccos ((v1 * v2)/|v1||v2|)

Wikipedia has lots of information on the dot product.

Finally, you would need to add the "angle of the red line" to the calculated angle.

All the above assumes angles in radians.

【讨论】:

    猜你喜欢
    • 2022-12-27
    • 2022-12-01
    • 2022-12-01
    • 2022-11-20
    • 2022-12-02
    • 2022-12-02
    • 2022-12-01
    • 2022-12-27
    • 2022-12-01
    相关资源
    最近更新 更多