bool intersectPlaneWithLine(SnapItem Plane, SnapItem Line, xyzArray LineArray, ref double Lam, ref xyz Result) { TriangleF T = Plane.GetTriangle(); if (T == null) { return(false); } xyz N1 = ((T.B - T.A) & (T.C - T.A)).Toxyz(); if (LineArray == null) { } xyz N2 = LineArray.cross(); if ((N1 & N2).length() < 0.00001) // Parallel { xyzArray A = Plane.getxyzArray(); if (A != null) { xyzArray B = LineArray; List <CrossTag1> L = CrossTag1.GetCrossList(A, B); for (int i = 0; i < L.Count; i++) { if (A.Value(L[i].Lam1).dist(Plane.Point) <= SnapItem.Snapdist) { Lam = L[i].Lam1; Result = A.Value(L[i].Lam1); return(true); } } } } int Object = StoredSnapItems.IndexOf(Plane); int siz = SnapDistance * 2 + 1; // int siz = SnapDistance; Drawing3d.PrimIdObj[,] P = SubArray(Device.MousePos.X - siz / 2, (int)Device.ViewPort.Height - Device.MousePos.Y - siz / 2, siz, siz); List <TriangleF> LT = GetTriangles(P, Object); Lam = -1; bool R = Cross(LT, LineArray, ref Lam, ref Result); return(R); }
bool IntersectLines(xyzArray A, xyzArray B, xyz NearPoint, ref xyz CrossPoint) { List <CrossTag1> L = CrossTag1.GetCrossList(A, B); for (int i = 0; i < L.Count; i++) { if (A.Value(L[i].Lam1).dist(NearPoint) <= SnapItem.Snapdist) { CrossPoint = A.Value(L[i].Lam1); return(true); } } return(false); }
void IntersectLines(List <xyzArray> Arrays, List <SnapItem> Snap) { xyzArray A = Arrays[0]; xyzArray B = Arrays[1]; List <CrossTag1> L = CrossTag1.GetCrossList(A, B); for (int i = 0; i < L.Count; i++) { if (A.Value(L[i].Lam1).dist(Snap[0].Point) <= SnapItem.Snapdist) { Snap[0].Point = A.Value(L[i].Lam1); Snap[1].Point = Snap[0].Point; Snap[0].Crossed = true; Snap[1].Crossed = true; break; } } }
xyz Nearest(LineType L, xyzf A, xyzf B, xyzf C) { xyzArray M = new xyzArray(4); M[0] = A.Toxyz(); M[1] = B.Toxyz(); M[2] = C.Toxyz(); M[3] = A.Toxyz(); double Param = -1; double LineLam = -1; double n = M.Distance(L, 1e10, out Param, out LineLam); return(M.Value(Param)); }
protected internal override xyz Cross(LineType ViewLine) { double Dummy = -1; double di = Poly.Distance(ViewLine, 2 * Snapdist, out Lam, out Dummy); if (di <= 2 * Snapdist) { return(Poly.Value(Lam)); } else { Lam = -1; } xyz Result = new xyz(0, 0, 0); double LineLam = -1; new Plane(new xyz(0, 0, 0), new xyz(0, 0, 1)).Cross(ViewLine, out LineLam, out Result); return(Result); }
public static bool Cross(TriangleF t1, TriangleF t2, out double Lam, out double Mue, out xyz P, out xyz Q) { xyzArray A = new xyzArray(); xyzArray B = new xyzArray(); A.data = new xyz[] { t1.A.Toxyz(), t1.B.Toxyz(), t1.C.Toxyz() }; B.data = new xyz[] { t2.A.Toxyz(), t2.B.Toxyz(), t2.C.Toxyz() }; Lam = -1; Mue = -1; P = new Drawing3d.xyz(0, 0, 0); Q = new Drawing3d.xyz(0, 0, 0); double d = (A.Distance(B, 1e10, out Lam, out Mue)); if (d < 2) { P = A.Value(Lam); Q = B.Value(Mue); return(true); } return(false); }
protected internal override xyz Cross(LineType ViewLine) { if (this.PolygonMode == PolygonMode.Line) { Polygon = Primitives3d.GetBoxPoints(Position, Size); double Param = -1; double LineLam1 = -1; if (Polygon.Distance(ViewLine, 1e10, out Param, out LineLam1) < 1) { return(Polygon.Value(Param)); } return(new xyz(0, 0, 0)); } xyz[] Result = new xyz[5]; Plane Triangle = new Plane(TriangleInfo.Points[TriangleInfo.Indices[PrimId * 3]], TriangleInfo.Points[TriangleInfo.Indices[PrimId * 3 + 1]], TriangleInfo.Points[TriangleInfo.Indices[PrimId * 3 + 2]]); //Test switch (PrimId) {// Oben case 0: //Polygon.data = new xyz[] {TriangleInfo.Points[0].Toxyz(), // TriangleInfo.Points[2].Toxyz(), // TriangleInfo.Points[1].Toxyz(), // TriangleInfo.Points[3].Toxyz(), // TriangleInfo.Points[0].Toxyz()}; //Point = Position; //Result[0] = new xyz(Point.x, Point.y, Point.z + Size.z); //Result[1] = new xyz(Point.x, Point.y + Size.y, Point.z + Size.z); //Result[2] = new xyz(Point.x, Point.y + Size.y, Point.z); //Result[3] = new xyz(Point.x, Point.y, Point.z); //Result[4] = Result[0]; Result[0] = new xyz(Position.x, Position.y, Position.z + Size.Z); Result[1] = new xyz(Position.x + Size.x, Position.y, Position.z + Size.Z); Result[2] = new xyz(Position.x + Size.x, Position.y + Size.y, Position.z + Size.Z); Result[3] = new xyz(Position.x, Position.y + Size.y, Position.z + Size.Z); Result[4] = Result[0]; break; case 1: //Polygon.data = new xyz[] {TriangleInfo.Points[0].Toxyz(), // TriangleInfo.Points[2].Toxyz(), // TriangleInfo.Points[1].Toxyz(), // TriangleInfo.Points[3].Toxyz(), // TriangleInfo.Points[0].Toxyz() //}; Result[0] = new xyz(Position.x, Position.y, Position.z + Size.Z); Result[1] = new xyz(Position.x + Size.x, Position.y, Position.z + Size.Z); Result[2] = new xyz(Position.x + Size.x, Position.y + Size.y, Position.z + Size.Z); Result[3] = new xyz(Position.x, Position.y + Size.y, Position.z + Size.Z); Result[4] = Result[0]; break; case 2: // unten //Polygon.data = new xyz[] {TriangleInfo.Points[4].Toxyz(), // TriangleInfo.Points[6].Toxyz(), // TriangleInfo.Points[5].Toxyz(), // TriangleInfo.Points[7].Toxyz(), // TriangleInfo.Points[4].Toxyz() //}; Result[0] = new xyz(Position.x, Position.y, Position.z); Result[2] = new xyz(Position.x + Size.x, Position.y, Position.z); Result[1] = new xyz(Position.x + Size.x, Position.y + Size.y, Position.z); Result[3] = new xyz(Position.x, Position.y + Size.y, Position.z); Result[4] = Result[0]; break; case 3: //Polygon.data = new xyz[] {TriangleInfo.Points[4].Toxyz(), // TriangleInfo.Points[6].Toxyz(), // TriangleInfo.Points[5].Toxyz(), // TriangleInfo.Points[7].Toxyz(), // TriangleInfo.Points[4].Toxyz() //}; Result[0] = new xyz(Position.x, Position.y, Position.z); Result[2] = new xyz(Position.x + Size.x, Position.y, Position.z); Result[1] = new xyz(Position.x + Size.x, Position.y + Size.y, Position.z); Result[3] = new xyz(Position.x, Position.y + Size.y, Position.z); Result[4] = Result[0]; break; case 4: //Polygon.data = new xyz[] {TriangleInfo.Points[8].Toxyz(), // TriangleInfo.Points[10].Toxyz(), // TriangleInfo.Points[9].Toxyz(), // TriangleInfo.Points[11].Toxyz(), // TriangleInfo.Points[8].Toxyz() //}; Result[0] = new xyz(Position.x, Position.y, Position.z); Result[1] = new xyz(Position.x + Size.x, Position.y, Position.z); Result[2] = new xyz(Position.x + Size.x, Position.y, Position.z + Size.Z); Result[3] = new xyz(Position.x, Position.y, Position.z + Size.Z); Result[4] = Result[0]; break; case 5: //Polygon.data = new xyz[] {TriangleInfo.Points[8].Toxyz(), // TriangleInfo.Points[10].Toxyz(), // TriangleInfo.Points[9].Toxyz(), // TriangleInfo.Points[11].Toxyz(), // TriangleInfo.Points[8].Toxyz() //}; Result[0] = new xyz(Position.x, Position.y, Position.z); Result[1] = new xyz(Position.x + Size.x, Position.y, Position.z); Result[2] = new xyz(Position.x + Size.x, Position.y, Position.z + Size.Z); Result[3] = new xyz(Position.x, Position.y, Position.z + Size.Z); Result[4] = Result[0]; break; case 6: // Hinten //Polygon.data = new xyz[] {TriangleInfo.Points[12].Toxyz(), // TriangleInfo.Points[14].Toxyz(), // TriangleInfo.Points[13].Toxyz(), // TriangleInfo.Points[15].Toxyz(), // TriangleInfo.Points[12].Toxyz() //}; Result[0] = new xyz(Position.x + Size.x, Position.y + Size.Y, Position.z); Result[1] = new xyz(Position.x, Position.y + Size.Y, Position.z); Result[2] = new xyz(Position.x, Position.y + Size.y, Position.z + Size.Z); Result[3] = new xyz(Position.x + Size.x, Position.y + Size.y, Position.z + Size.Z); Result[4] = Result[0]; break; case 7: // Hinten //Polygon.data = new xyz[] {TriangleInfo.Points[12].Toxyz(), // TriangleInfo.Points[14].Toxyz(), // TriangleInfo.Points[13].Toxyz(), // TriangleInfo.Points[15].Toxyz(), // TriangleInfo.Points[12].Toxyz() //}; Result[0] = new xyz(Position.x + Size.x, Position.y + Size.Y, Position.z); Result[1] = new xyz(Position.x, Position.y + Size.Y, Position.z); Result[2] = new xyz(Position.x, Position.y + Size.y, Position.z + Size.Z); Result[3] = new xyz(Position.x + Size.x, Position.y + Size.y, Position.z + Size.Z); Result[4] = Result[0]; break; case 8: // Links)) //Polygon.data = new xyz[] {TriangleInfo.Points[16].Toxyz(), // TriangleInfo.Points[18].Toxyz(), // TriangleInfo.Points[17].Toxyz(), // TriangleInfo.Points[19].Toxyz(), // TriangleInfo.Points[16].Toxyz() //}; Result[0] = new xyz(Position.x, Position.y + Size.Y, Position.z); Result[1] = new xyz(Position.x, Position.y, Position.z); Result[2] = new xyz(Position.x, Position.y, Position.z + Size.Z); Result[3] = new xyz(Position.x, Position.y + Size.Y, Position.z + Size.Z); Result[4] = Result[0]; break; case 9: //Polygon.data = new xyz[] {TriangleInfo.Points[16].Toxyz(), // TriangleInfo.Points[18].Toxyz(), // TriangleInfo.Points[17].Toxyz(), // TriangleInfo.Points[19].Toxyz(), // TriangleInfo.Points[16].Toxyz() // }; Result[0] = new xyz(Position.x, Position.y + Size.Y, Position.z); Result[1] = new xyz(Position.x, Position.y, Position.z); Result[2] = new xyz(Position.x, Position.y, Position.z + Size.Z); Result[3] = new xyz(Position.x, Position.y + Size.Y, Position.z + Size.Z); Result[4] = Result[0]; break; case 10: //Rechts //Polygon.data = new xyz[] {TriangleInfo.Points[20].Toxyz(), // TriangleInfo.Points[22].Toxyz(), // TriangleInfo.Points[21].Toxyz(), // TriangleInfo.Points[23].Toxyz(), // TriangleInfo.Points[20].Toxyz() // }; Result[0] = new xyz(Position.x + Size.X, Position.y, Position.z); Result[1] = new xyz(Position.x + Size.x, Position.y + Size.Y, Position.z); Result[2] = new xyz(Position.x + Size.x, Position.y + Size.y, Position.z + Size.Z); Result[3] = new xyz(Position.x + Size.x, Position.y, Position.z + Size.z); Result[4] = Result[0]; break; case 11: //Rechts //Polygon.data = new xyz[] {TriangleInfo.Points[20].Toxyz(), // TriangleInfo.Points[22].Toxyz(), // TriangleInfo.Points[21].Toxyz(), // TriangleInfo.Points[23].Toxyz(), // TriangleInfo.Points[20].Toxyz() // }; Result[0] = new xyz(Position.x + Size.X, Position.y, Position.z); Result[1] = new xyz(Position.x + Size.x, Position.y + Size.Y, Position.z); Result[2] = new xyz(Position.x + Size.x, Position.y + Size.y, Position.z + Size.Z); Result[3] = new xyz(Position.x + Size.x, Position.y, Position.z + Size.z); Result[4] = Result[0]; break; default: break; } Polygon.data = Result; double Lam = -1; double LineLam = -1; double di = Polygon.Distance(ViewLine, Snapdist, out Lam, out LineLam); if (di <= Snapdist) { xyz P = Polygon.Value(Lam); doExchange = true; //xyz W = ViewLine.Value(LineLam); //double mm = P.dist(W); return(P); } return(base.Cross(ViewLine)); }