【发布时间】:2017-07-27 23:13:12
【问题描述】:
我正在使用 3D 几何图形使用 php(我知道这不是最佳选择...)。 我有 K 个共面 3D 点,也有 x、y、z 值。它们一起形成一个多边形。我需要对这个多边形进行三角测量。我已经有一个适用于 2D 多边形的工作 delaunay 训练函数。 所以我想旋转给定的点,使它们位于平行于 x,y 平面的平面上。之后,我可以使用 x,y 值对其进行三角测量。下面的伪代码将描述我想如何达到这个目标。
我在此基础上构建了以下代码(我使用了从 OP 接受的答案):https://math.stackexchange.com/questions/180418/calculate-rotation-matrix-to-align-vector-a-to-vector-b-in-3d,但它没有按我的预期工作。为了知道它是否有效,每个映射点都应具有相同的“z”值。 这是一个问题,我如何获得正确的旋转矩阵?还是我犯了概念上的错误?
function matrixRotationMapping(Point $p, Point $q, Point $r)
{
$normalPolygon =calculatePlaneNormal($p, $q, $r);
$v = crossProduct($normalPolygon, new Point(0, 0, 1));
$c = dotProduct($normalPolygon, new Point(0, 0, 1));
$matrix = buildRotationMatrix($v, $c);
return $matrix;
}
function buildRotationMatrix($v, $c)
{
$R2 = new Matrix(array(array(1, -$v->z, $v->y), array($v->z, 1, -$v->x), array(-$v->y, $v->x, 1)));
$costant = 1/(1+$c);
$R3 = multiplyMatrices($R2, $R2);
$R3 = multiplyMatricesWithFactor($R3, $costant);
$finalMatrix = sumMatrices($R2, $R3);
return $finalMatrix;
}
function calc2DMapping($points)
{
$rotationMatrix = matrixRotationMapping($points[0], $points[1], $points[2]);
foreach($points as $point)
{
$mappedPoint = $rotationMatrix->multiplyWithPoint($point);
$mappedPoints[] = new MappedPoint($mappedPoint);
}
}
我找到了另一个有用的问题描述,但我无法实现它:Mapping coordinates from plane given by normal vector to XY plane
提前感谢您的关注。
【问题讨论】:
标签: php algorithm matrix 3d geometry