【问题标题】:3d vector calculation in WPFWPF 中的 3d 矢量计算
【发布时间】:2009-08-12 00:42:00
【问题描述】:

我在 3d WPF 中绘制了两个球体,它们的点如下 半径为 0.10 的 Point3D(0,0,0) 和 Point3D(-1.0,1.0,2.0)

现在我想绘制一个连接这些球体的圆柱体,我唯一拥有的就是半径 0.02。我想知道如何计算这个圆柱体的 3d 点、高度、方向等。

我尝试找到中间点 btw 球体点,它将圆柱体放置在这两个球体的中间,但方向不正确。我正在尝试在下面的代码中使用旋转。

    Vector3D v1 = new Vector3D(0, 0, 0);
    Vector3D v2 = new Vector3D(1.0, -1.0, 2.0);

    Vector3D center = v1+ v2/2;
    Vector3D axis = Vector3D.CrossProduct(v1, v2);
    double angle = Vector3D.AngleBetween(v1, v2);
    AxisAngleRotation3D axisAngle = new AxisAngleRotation3D(axis, angle);
    RotateTransform3D myRotateTransform = new RotateTransform3D(axisAngle, center);
    center.X = myRotateTransform.CenterX;
    center.Y = myRotateTransform.CenterY;
    center.Z = myRotateTransform.CenterZ;

但是双角 = Vector3D.AngleBetween(v1, v2);拉塞尔NaN

如果有人能帮忙做这件事,那就太好了。 提前致谢。

【问题讨论】:

  • 我不是数学家,但定义为 (0, 0, 0) 的向量没有大小和“无处或处处”的方向。要找到两个向量之间的角度,这两个向量都必须定义一个方向。所以你永远无法找到零向量和另一个向量之间的角度。

标签: c# wpf 3d


【解决方案1】:

您可以简单地使用RotateTransform3D 将圆柱体旋转到所需的方向。

您可以将转换应用于两个属性之一here 是选项的说明

【讨论】:

  • 嗨西蒙-我如何从这两个球体点计算所需的方向?
  • 您可能只想使用 AxisAngleRotation3d 创建旋转变换,它描述了要旋转的轴(这将确定旋转方向)和旋转角度(即“如何远”围绕对象旋转的那个轴)
【解决方案2】:

你需要的方向是球心之间的向量:

direction.x = sphere1.Center.x - sphere2.Center.x;
direction.y = sphere1.Center.y - sphere2.Center.y;
direction.x = sphere1.Center.z - sphere2.Center.z;

然后将这些除以向量的长度得到单位向量:

double length = Math.Sqrt(direction.x * direction.x +
                          direction.y * direction.y +
                          direction.z * direction.z);

direction.x /= length;
direction.y /= length;
direction.z /= length;

然后你可以用它来计算你的旋转矩阵。

【讨论】:

    猜你喜欢
    • 2018-06-26
    • 1970-01-01
    • 2019-01-23
    • 1970-01-01
    • 2017-02-28
    • 2014-05-28
    • 1970-01-01
    • 2019-05-21
    • 2011-10-31
    相关资源
    最近更新 更多