{/// <summary> /// returns the contur of a list of triangles /// </summary> /// <param name="L">List of triangles</param> /// <returns></returns> public static Loxyz GetContour(List <Triangle> L) { Dictionary <xyz, xyz> D = new Dictionary <xyz, xyz>(); for (int i = 0; i < L.Count; i++) { INeighbors N = L[i] as INeighbors; ITriangle T = L[i]; if ((T.GetB() - T.GetA() & T.GetC() - T.GetA()).length() < 0.0000001) { continue; } if (N.GetNeighbor(0) == -1) { D.Add(T.GetA().Toxyz(), T.GetB().Toxyz()); } if (N.GetNeighbor(1) == -1) { D.Add(T.GetB().Toxyz(), T.GetC().Toxyz()); } if (N.GetNeighbor(2) == -1) { D.Add(T.GetC().Toxyz(), T.GetA().Toxyz()); } } Loxyz Result = new Loxyz(); while (true) { if (D.Count == 0) { break; } xyz First = new xyz(0, 0, 0); foreach (KeyValuePair <xyz, xyz> Pt in D) { First = Pt.Key; break; } xyz Current = First; xyzArray A = new xyzArray(); Result.Add(A); while (true) { if (D.ContainsKey(Current)) { xyz C = D[Current]; A.Add(C); D.Remove(Current); Current = C; } else { break; } } } return(Result); }
/// <summary> /// draws a list of <see cref="xyzArray"/>.The first array is the outer contur the other are holes. /// </summary> /// <param name="Loxyz">a list of <see cref="xyzArray"/></param> public void drawPolyPolyLine(Loxyz Loxyz) { Object Handle = null; if ((RenderKind == RenderKind.SnapBuffer)) { Handle = Selector.RegisterSnapItem(new PolyPolyLineSnappItem3D(Loxyz)); } if ((PolygonMode == PolygonMode.Fill) && (Loxyz.planar)) { Loxy L = Loxyz.ToLoxy(); PushMatrix(); MulMatrix(Loxyz.Base.ToMatrix()); drawFilledArray2d(this, L); PopMatrix(); if ((RenderKind == RenderKind.SnapBuffer)) { Selector.UnRegisterSnapItem(Handle); } return; } for (int i = 0; i < Loxyz.Count; i++) { Primitives3d.drawArrayLined(this, Loxyz[i]); } if ((RenderKind == RenderKind.SnapBuffer)) { Selector.UnRegisterSnapItem(Handle); } }
/// <summary> /// creates a <see cref="Face"/> in the <see cref="Model.Shell"/> with the points <b>Pts</b>. /// </summary> /// <param name="Pts"><see cref="Loxyz"/> which gives the points of the plane <see cref="Face"/>.</param> /// <param name="Surface"><see cref="Loxyz"/> which gives the points of the plane <see cref="Face"/>.</param> /// <returns>plane Face.</returns> static Face ShellFace(Loxyz Pts, Surface Surface) { if (Pts.Count == 0) { return(null); } Face Result = new Face(); for (int i = 0; i < Pts.Count; i++) { EdgeLoop Edgeloop = new EdgeLoop(); Result.Bounds.Add(Edgeloop); for (int j = 0; j < Pts[i].Count; j++) { xyz A = Pts[i][j]; xyz B = xyz.Null; if (j == Pts[i].Count - 1) { B = Pts[i][0]; } else { B = Pts[i][j + 1]; } Edge E = Edge.ShellLineEdge(A, B); E.SameSense = true; Edgeloop.Add(E); } } Result.Surface = Surface; return(Result); }
/// <summary> /// creates a <see cref="Face"/> in the <see cref="Model.Shell"/> with the points <b>Pts</b>. /// </summary> /// <param name="Pts"><see cref="Loxyz"/> which gives the points of the plane <see cref="Face"/>.</param> /// <returns>plane Face.</returns> public static Face ShellPlane(Loxyz Pts) { if (Pts.Count == 0) { return(null); } Plane _Plane = Pts[0].GetPlane(); Base Base = Base.UnitBase; Base.BaseO = _Plane.P; Base.BaseZ = _Plane.NormalUnit.normalized() * (-1); if ((Base.BaseZ & new xyz(1, 0, 0)).dist(xyz.Null) > 0.01) { Base.BaseY = (Base.BaseZ & (new xyz(1, 0, 0))).normalized(); Base.BaseX = Base.BaseY & Base.BaseZ; } else { Base.BaseY = (Base.BaseZ & (new xyz(0, 1, 0))).normalized(); Base.BaseX = Base.BaseY & Base.BaseZ; } PlaneSurface Surface = new PlaneSurface(); Surface.Base = Base; return(ShellFace(Pts, Surface)); }
/// <summary> /// creates a <see cref="Face"/> in the <see cref="Model.Shell"/> with the points <b>Pts</b>. /// </summary> /// <param name="Pts"><see cref="xyzArray"/> which gives the points of the plane <see cref="Face"/>.</param> /// <returns>plane Face.</returns> public static Face ShellPlane(xyzArray Pts) { Loxyz L = new Loxyz(); L.Count = 1; L[0] = Pts; return(ShellPlane(L)); }
/// <summary> /// multiplies the <see cref="Loxyz"/> with a <see cref="Matrix"/>. /// </summary> /// <param name="a">the matrix</param> /// <param name="b">the Loxyz</param> /// <returns></returns> public static Loxyz operator *(Matrix a, Loxyz b) { Loxyz Result = new Loxyz(); for (int i = 0; i < b.Count; i++) { Result.Add(a * b[i]); } return(Result); }
/// <summary> /// shifted a <see cref="Loxy"/> to a <see cref="Loxyz"/> by settimg the z-value to zero. /// </summary> /// <returns></returns> public Loxyz ToLoxyz() { Loxyz Result = new Loxyz(); for (int i = 0; i < Count; i++) { Result.Add(this[i].ToxyzArray()); } return(Result); }
/// <summary> /// refreshes the <see cref="Edge.ParamCurve"/> of the <see cref="EdgeList"/>. /// <see cref="ParamCurves"/>-liste. Diese doppelte Verwaltung der ParamCurves wird lediglich aus Performancegründen gemacht. /// </summary> public virtual void RefreshParamCurves() { Solid P = Parent; DrawPoints = new Loxyz(); DrawPoints.Count = Bounds.Count; if (ParamCurves == null) { Surface.BoundedCurves = new Loca(); } ParamCurves.Clear(); for (int i = 0; i < Bounds.Count; i++) { EdgeLoop EL = Bounds[i]; CurveArray CA = new CurveArray(); ParamCurves.Add(CA); for (int j = 0; j < EL.Count; j++) { Edge E = EL[j]; if (!DrawRelativToSurfaceBase) { DrawPoints[i].Add(E.EdgeStart.Value); } Curve c = Surface.To2dCurve(EL[j].EdgeCurve); if (!EL[j].SameSense) { c.Invert(); } EL[j].ParamCurve = c; CA.Add(c); } xyArray A = CA.getxyArrayClosed(false); DrawPoints[i] = A.ToxyzArray(); } }
void RefreshNormals() { Normals = new Loxyz(); Normals.Count = Bounds.Count; DrawPoints = new Loxyz(); DrawPoints.Count = ParamCurves.Count; if (!DrawRelativToSurfaceBase) { for (int i = 0; i < Bounds.Count; i++) { EdgeLoop EL = Bounds[i]; for (int k = 0; k < EL.Count; k++) { Edge E = EL[k]; DrawPoints[i].Add(E.EdgeStart.Value); } } } for (int i = 0; i < ParamCurves.Count; i++) { xyArray A = ParamCurves[i].getxyArrayClosed(false); if (DrawRelativToSurfaceBase) { DrawPoints[i] = A.ToxyzArray(); } int ct = 0; for (int t = 0; t < ParamCurves[i].Count; t++) { ct = ct + ParamCurves[i][t].Resolution; } xyzArray NormalsLoop = new xyzArray(ct); Normals[i] = NormalsLoop; int id = 0; for (int j = 0; j < ParamCurves[i].Count; j++) { List <Face> L = GetFaces(this, i, j); Edge E = Bounds[i][j]; if (L == null) { Normals = null; DrawPoints = null; return; } double SmoothAngle = Parent.SmoothAngle; xyz N = Surface.Normal(0, 0).normalized(); xyz N1 = Surface.Normal(0, 0).normalized(); for (int k = 0; k < L.Count; k++) { if (System.Math.Abs((N1 * L[k].Surface.Normal(0, 0).normalized())) > System.Math.Cos(SmoothAngle)) { N = N + L[k].Surface.Normal(0, 0).normalized(); } } N = N.normalized(); if (DrawRelativToSurfaceBase) { Matrix M = Surface.Base.ToMatrix().invert(); N = M * N - M * new xyz(0, 0, 0); } NormalsLoop[id] = N; id++; } } }