private static Segment3f[] GetSegments(ISectionFace face) { var segments = new Segment3f[12]; var C = new Vector3f(face.CenterX, face.CenterY, face.CenterZ); var X = (Vector3f)(face.GetU() * face.SizeX / 2.0); var Y = (Vector3f)(face.GetV() * face.SizeY / 2.0); segments[0] = new Segment3f(C - X - Y, C + X - Y); segments[1] = new Segment3f(C + X - Y, C + X + Y); segments[2] = new Segment3f(C + X + Y, C - X + Y); segments[3] = new Segment3f(C - X + Y, C - X - Y); return(segments); }
internal static double GetDistance(this ISectionFace face, Vector3d pt) { var center = new Vector3d(face.CenterX, face.CenterY, face.CenterZ); var D = pt - center; var N = face.GetNormal(); var U = face.GetU(); var V = face.GetV(); var halfW = (face.SizeX + 5.0) / 2.0; var halfH = (face.SizeY + 5.0) / 2.0; var du = U.Dot(ref D); var dv = V.Dot(ref D); var uuul = du <= halfW; var uull = du >= -halfW; var uvul = dv <= halfH; var uvll = dv >= -halfH; var nc = N.Dot(ref D); double result = 0.0f; if (uuul && uull && uvll && uvul) { result = nc; } else if (uuul && uull) { var pc = Math.Abs(dv) - halfH; result = Math.Sqrt(pc * pc + nc * nc); } else if (uvll && uvul) { var pc = Math.Abs(du) - halfW; result = Math.Sqrt(pc * pc + nc * nc); } else { var cu = Math.Abs(du) - halfW; var cv = Math.Abs(dv) - halfH; result = Math.Sqrt(nc * nc + cu * cu + cv * cv); } return(result); }