本文介绍了如何与QUOT;扣"定向(2D)向量指南针(N,NE,E,SE,S,SW,W,NW)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一大堆的向量垂直于窗口表面的三维建模软件。预计到xy平面,我想知道在哪个方向,他们所面对的,转换到 8罗盘坐标东北东南亚西南西西北的)。

I have a bunch of vectors normal to window surfaces in a 3D modelling software. Projected to the XY-Plane, I would like to know in which direction they are facing, translated to the 8 compass coordinates (North, North-East, East, South-East, South, South-West, West and North-West).

载体的工作是这样的:

  • X轴重新presents东西(与东为正)
  • y轴重新presents北 - 南(与北为正)
  • 在这样
    • (0,1)==北
    • (1,0)==东
    • (0,-1)==南
    • ( - 1,0)==西
    • the X axis represents East-West (with East being positive)
    • the y axis represents North-South (with North being positive)
    • thus
      • (0, 1) == North
      • (1, 0) == East
      • (0,-1) == South
      • (-1,0) == West

      给定一个向量(X,Y)我在寻找最接近的8罗盘坐标。如何做到这一点的任何想法优雅?

      Given a vector (x, y) I am looking for the closest of the 8 compass coordinates. Any ideas on how to do this elegantly?

      推荐答案

      这在Java中,计算值0 ... 7的八个方向:

      This works in Java, computing a value 0...7 for the eight directions:

      import static java.lang.Math.*;    
      
      int compass = (((int) round(atan2(y, x) / (2 * PI / 8))) + 8) % 8;
      

      结果映射到指南针如下:

      The result maps to the compass as follows:

      0 => E
      1 => NE
      2 => N
      3 => NW
      4 => W
      5 => SW
      6 => S
      7 => SE
      

      这篇关于如何与QUOT;扣"定向(2D)向量指南针(N,NE,E,SE,S,SW,W,NW)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 04:23