public static Trafo3d FromNormalFrame(V3d origin, V3d normal) { M44d forward, backward; M44d.NormalFrame(origin, normal, out forward, out backward); return(new Trafo3d(forward, backward)); }
/// <summary> /// 2D plane space to 3D world space. /// Plane space is defined by a normal-frame from Point and Normal of the plane. /// </summary> public static M44d GetPlaneToWorld(this Plane3d self) { M44d local2global, _; M44d.NormalFrame(self.Point, self.Normal, out local2global, out _); return(local2global); }
/// <summary> /// 3D world space to 2D plane space. /// Plane space is defined by a normal-frame from Point and Normal of the plane. /// </summary> public static M44d GetWorldToPlane(this Plane3d self) { M44d _, global2local; M44d.NormalFrame(self.Point, self.Normal, out _, out global2local); return(global2local); }
public static List <int[]> ComputeNonConcaveSubPolygons( this Polygon3d polygon, double absoluteEpsilon) { V3d normal = polygon.ComputeDoubleAreaNormal(); double len2 = normal.LengthSquared; if (len2 < absoluteEpsilon * absoluteEpsilon) { return(new int[polygon.PointCount].SetByIndex(i => i).IntoList()); } M44d.NormalFrame(V3d.Zero, normal * (1.0 / Fun.Sqrt(len2)), out M44d local2global, out M44d global2local); var polygon2d = polygon.ToPolygon2d(p => global2local.TransformPos(p).XY); return(polygon2d.ComputeNonConcaveSubPolygons(absoluteEpsilon)); }
public static List <int[]> ComputeNonConcaveSubPolygons( this V3d[] vertexArray, int polyCount, V3d[] normalArray, int[] firstIndices, int[] vertexIndices, List <int> faceBackMap, double absoluteEpsilon) { var polyList = new List <int[]>(); var eps2 = absoluteEpsilon * absoluteEpsilon; for (int fvi = 0, fi = 0; fi < polyCount; fi++) { int fve = firstIndices[fi + 1], fvc = fve - fvi; var n = normalArray[fi]; var l2 = n.LengthSquared; if (l2 < eps2) { polyList.Add(new int[fvc].SetByIndex(i => vertexIndices[fvi + i])); if (faceBackMap != null) { faceBackMap.Add(fi); } fvi = fve; continue; } M44d local2global, global2local; M44d.NormalFrame(V3d.Zero, n, out local2global, out global2local); var polygon = new Polygon2d(fvc, i => global2local.TransformPos(vertexArray[vertexIndices[fvi + i]]).XY); var subPolyList = polygon.ComputeNonConcaveSubPolygons(absoluteEpsilon); foreach (var poly in subPolyList) { polyList.Add(poly.Map(i => fvi + i)); } if (faceBackMap != null) { for (int i = 0; i < subPolyList.Count; i++) { faceBackMap.Add(fi); } } fvi = fve; } return(polyList); }