标题可能是错误的,因为我不知道足够的数学知识来实际用一个小句子描述我的问题。
- 我有一个 3D 矢量闭环,我将其称为“3D 多边形”。
- 我需要对其执行仅 2D 操作,这将返回一个
不同的 2D 点集
- 我需要将这些新的 2D 点转换回 3D。
我目前的尝试如下:
- 获得“最适合”的飞机,最大限度地减少制作“3D”的机会
转换为 2D 时多边形自相交。
- 通过移动平面法线得到两个垂直平面
坐标
- 对于每个 3D 点,获取到平面的距离以获得“轴对齐坐标”
- 将 Y 坐标保存在单独的变量中供以后使用,使用 X 和 Z 进行 2D 操作
- 执行 2D 操作
- 获取新的2D点,并获取最接近的3个原始点的加权平均值来假设新的2D点的高度
- 将“轴对齐坐标”+假定高度乘以
各自平面法线以将 2D 点返回到 3D 空间。
问题是,这不起作用,罪魁祸首似乎是我获得“轴对齐坐标”的部分,因为立即将它们恢复会给出错误的结果
public static List<Vector2> Planify3Dto2DPoints2(Vector3[] points, Vector3 centroid, Plane ply, out Vector3[] oldHeights) {
var pz = ply.normal.z;
var px = ply.normal.x;
var py = ply.normal.y;
Plane plx = new Plane(new Vector3(pz, px, py), 0);
Plane plz = new Plane(new Vector3(py, pz, px), 0);
oldHeights = new Vector3[points.Length];
List<Vector2> m_points = new List<Vector2>();
int i = 0;
foreach (Vector3 v3 in points) {
Vector3 v4 = v3 - centroid;
float x = plx.GetDistanceToPoint(v4);//this part is wrong, attempting to get the v4
float z = plz.GetDistanceToPoint(v4);//vector back from the x, z, y coordinates is not
float y = ply.GetDistanceToPoint(v4);//working. removing x * plx.Normal from v4 before
m_points.Add(new Vector2(x, z));// extracting the z coordinate reduces the error, but does not remove it
oldHeights[i++] = new Vector3(x, z, y);
}
return m_points;
}
public static List<Vector3> Spacefy2Dto3DPoints(Vector2[] points, Vector3 centroid, Plane ply, Vector3[] oldHeights = null) {
List<Vector3> m_points = new List<Vector3>();
var pn = new Vector3(ply.normal.x, ply.normal.y, ply.normal.z);
for (int i = 0; i < points.Length; i++) {
Vector3 mp = MoveInPlane(ply, points[i]);
if (oldHeights != null) {
mp += pn * oldHeights[i].z;//AverageOf3ClosestHeight(points[i], oldHeights); not needed yet, but working fine, it's weighted average
}
mp += centroid;
m_points.Add(mp);
}
return m_points;
}
private static Vector3 MoveInPlane(Plane plane, Vector2 vector2) {
var z = plane.normal.z;
var x = plane.normal.x;
var y = plane.normal.y;
return new Vector3(z, x, y) * vector2.x + new Vector3(y, z, x) * vector2.y;
}