【问题标题】:Get a point based on the normals of three planes and the distance of the point from them根据三个平面的法线和点到它们的距离获取一个点
【发布时间】:2016-06-21 06:04:35
【问题描述】:

我有三个平面的法线,它们彼此成 90 度并通过原点。

我也有一个点到三个平面的距离。如何确定 C# 中点的位置?

这就是我目前所拥有的......

    public static Vector3 RealWorldSpaceToOtherSpace(Vector3 realspace, Vector4 clipplane)
    {
        // Work out the normal vectors of 3 imaginary planes
        Vector3 floor = new Vector3(clipplane.X, clipplane.Y, clipplane.Z);
        Vector3 centre = new Vector3(1f, -clipplane.X / clipplane.Y, 0f);
        Vector3 wall = Vector3.Cross(floor, centre);

        // Get distances from the planes
        float distanceToFloor = realspace.y;
        float distanceToCentre = realspace.x;
        float distanceToWall = realspace.z;

        //   ?
        //   ?  do stuff here
        //   ?

        // return ????
    }

【问题讨论】:

    标签: c# unity3d geometry


    【解决方案1】:

    由于平面彼此成 90 度,并经过原点,所以它们的法线与原点相同形成一个正交坐标系。因此,到每个平面的距离是沿轴的点的坐标,对应于新坐标系中平面的(归一化)法线。

    因此找到每个平面的归一化法线,乘以到该平面的相应距离,然后相加找到点。

    需要注意的是,您需要知道该点在每个平面的哪个;如果在法线的另一边,在对应的距离前加减号。

    【讨论】:

      【解决方案2】:

      当给定点到一个平面的距离时。该点现在可以位于与您的第一个平面定义距离的平面内的任何一点,因此您已将位置从 3 个维度内的任何位置缩小到只有 2 个维度的第 3 个维度的这些子集的任何位置..

      当您获得从该点到第二个平面的距离时。您现在拥有相同的信息,即该点所在的平面。你会注意到这两个平原相交并形成一条线。无需存储此行。只需知道您已将可能点的位置缩小到 1 维即可。

      最后你得到了从点到第三个平面的距离。您可以在距原始平面定义的距离处创建新平面,并且该平面应与其他 2 个新平面相交。所有三个平面将在一个点相交,这将是该点的位置。

      谢天谢地,我们可以将距离添加到平面矢量以创建新平面。然后我们最终可以通过使用每个平面的相关尺寸来获得点的位置,从而得到点的位置。

      public static Vector3 RealWorldSpaceToOtherSpace(Vector3 realspace, Vector4 clipplane)
      {
          // Work out the normal vectors of 3 imaginary planes
          Vector3 floor = new Vector3(clipplane.X, clipplane.Y, clipplane.Z);
          Vector3 centre = new Vector3(1f, -clipplane.X / clipplane.Y, 0f);
          Vector3 wall = Vector3.Cross(floor, centre);
      
          // Get distances from the planes
          // Distance is represented as a Vector, since it needs to hold
          // the direction in 3d space.
          Vector3 distanceToFloor = new Vector3(0f,   realspace.y ,0f,);
          Vector3 distanceToCentre = new Vector3(     realspace.x ,0f,0f,);
          Vector3 distanceToWall = new Vector3(0f,0f, realspace.z );
      
          // Create planes that contain all the possible positions of the point
          // based on the distance from point to the corresponding plane.
          Vector3 pointY = floor + distanceToFloor;
          Vector3 pointX = centre + distanceToCentre;
          Vector3 pointZ = wall + distanceToWall;
      
          // Now that we have all 3 point's dimensions, we can create a new vector that will hold its position.
          Vector3 point = new Vector3(pointX.x,pointY.y, pointZ.z);
      
          return point
      }
      

      请注意,Unity 中有一个 plane 结构。

      【讨论】:

        猜你喜欢
        • 2013-11-02
        • 1970-01-01
        • 2013-01-18
        • 2010-12-23
        • 1970-01-01
        • 1970-01-01
        • 2015-09-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多