duanji1902 2010-06-16 15:04
浏览 57

描述点之间的相对角度(如行车路线)

I have a list of points with x, y coordinates. I know how to get the distance between points with sqrt(pow($x2 - $x1, 2) + pow($y2 - $y1, 2)) and the angle between points with atan2(y1 - y2, x1 - x2).

How can I calculate the relative angle between the points (left, right, straight)? So, if I'm at point 1, what is the relative direction to point 2, then 2 to 3, 3 to 4, etc...

Thanks for any help!

  • 写回答

3条回答 默认 最新

  • doudi2005 2010-06-16 15:06
    关注

    Call atan2($y1 - $y2, $x1 - $x2)

    If it's between π/2 and 3π/2, it's straight.
    If it's more than 3π/2 or less than -3π/2, it's a left turn.
    If it's between -π/2 and π/2, it's a right turn.

    Here is a diagram:

     {3π/2}-------{π/2}-------{π/4}
          | +-----[ +y]-----+ | 
          | |               | | 
          | |               | | 
        {π} [-x]  [0,0]  [+x] {0} 
          | |               | | 
          | |               | | 
          | +-----[ -y]-----+ |
    {-3π/2}-------{-π/2}------{-π/4}
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭