【问题标题】:How to translate the plane towards the point for X distance?如何将平面平移到 X 距离的点?
【发布时间】:2012-04-13 06:48:07
【问题描述】:
  • 我得到了一个Plane(正常,d)和一个Vector3 点(x,y,z)。
  • 我需要将平面平移到 X 距离的那个点。我该怎么做?

我想出了这个..

plane = Plane.Transform(plane, Matrix.CreateTranslation(

但不知道该放什么。它必须是点积,Plane.Normal 和我的Vector3

编辑:

我在想这个。

public static Plane MoveTo(this Plane p, Vector3 point, float distance)
{
    Vector3 planeVector = p.Normal * p.D;

    Matrix matrix = Matrix.CreateTranslation(Vector3.Normalize(planeVector)) *
        distance * Math.Sign(Vector3.Dot(planeVector, point - planeVector))

    return Plane.Transform(p, matrix);
}

如果有人认为这是错误的或部分错误的,请注意。

【问题讨论】:

  • @hamad 不,我没有,但我使用相同的方法。我只需要一种方法。
  • 那么它对你有用吗?创建一个新矩阵并将其传递给 Plane.Transform()
  • @hamad 我不知道要传递给矩阵创建方法的参数。

标签: c# xna translation plane


【解决方案1】:

点P到平面Pi的距离为:

你应该计算当前的 d(P, pi),减去 X 的数量,然后只需要计算 D 就可以得到新的平面。

编辑:

 // This line has no sense... is useless do that.
 Vector3 planeVector = p.Normal * p.D;  

要知道一个点和一个平面之间的关系,你只需要计算它的方程: R = Ax + By + Cz + D 其中 (A,B,C) 是法线, (x,y,z)重点...

如果 (R == 0) 点包含在平面中
if (R>0) 点在前面 // 反之亦然
if (R

R = plane.DotCoordinate(point);    
distance*=(R>0) ? 1 : -1; // or viceversa, i'm not sure now
Matrix matrix = Matrix.CreateTranslation(plane.Normal * distance);
return Plane.Transform(p, matrix);

【讨论】:

  • 顺便说一句(通过点积),我已经有了从点到平面的距离。我需要一个Vector3-translator。我可以用于平面矩阵平移的值。
  • 只是.. 从 D 中减去还是添加到它?
  • 如果初始距离 d(P,pi) 为 100,并且您想向该点平移 10 个单位,则新距离将为 100-10 = 90... 那么您只需计算"D" 知道 d(P,pi) == 90。
  • 那么如何检测是向前还是向后呢?看看我的编辑,对吗?
  • 不要将平面向量减去点,应该是Matrix matrix = Matrix.CreateTranslation(Vector3.Normalize(planeVector)) * distance * Math.Sign(Vector3.Dot(planeVector, point)), I '没有测试过,但我认为你需要否定符号,(... * -Math.Sign(....) ...)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多