/// <summary> /// overrides the <see cref="Solid.Refresh()"/> method. /// </summary> public override void Refresh() { VertexList.Clear(); EdgeList.Clear(); FaceList.Clear(); EdgeCurveList.Clear(); Vertex3d A = new Vertex3d(xyz.Null); Vertex3d B = new Vertex3d(new xyz(Size.x, 0, 0)); Vertex3d C = new Vertex3d(new xyz(Size.x, Size.y, 0)); Vertex3d D = new Vertex3d(new xyz(0, Size.y, 0)); Vertex3d E = new Vertex3d(A.Value + new xyz(0, 0, Size.z)); Vertex3d F = new Vertex3d(B.Value + new xyz(0, 0, Size.z)); Vertex3d G = new Vertex3d(C.Value + new xyz(0, 0, Size.z)); Vertex3d H = new Vertex3d(D.Value + new xyz(0, 0, Size.z)); VertexList.Add(A); VertexList.Add(B); VertexList.Add(C); VertexList.Add(D); VertexList.Add(E); VertexList.Add(F); VertexList.Add(G); VertexList.Add(H); Vertex3dArray_2 Border = new Vertex3dArray_2(); Vertex3dArray VA = new Vertex3dArray(); Border.Add(VA); Face Face = null; VA.Clear(); VA.Add(A); VA.Add(B); VA.Add(C); VA.Add(D); Face = Face.SolidPlane(this, Border); // FaceList.Add(Face); VA.Clear(); VA.Add(A); VA.Add(E); VA.Add(F); VA.Add(B); Face = Face.SolidPlane(this, Border); // FaceList.Add(Face); VA.Clear(); VA.Add(B); VA.Add(F); VA.Add(G); VA.Add(C); Face = Face.SolidPlane(this, Border); // FaceList.Add(Face); VA.Clear(); VA.Add(C); VA.Add(G); VA.Add(H); VA.Add(D); Face = Face.SolidPlane(this, Border); // FaceList.Add(Face); VA.Clear(); VA.Add(D); VA.Add(H); VA.Add(E); VA.Add(A); Face = Face.SolidPlane(this, Border); // FaceList.Add(Face); VA.Clear(); VA.Add(H); VA.Add(G); VA.Add(F); VA.Add(E); Face = Face.SolidPlane(this, Border); //for (int i = 0; i < FaceList.Count; i++) //{ // FaceList[i].DrawRelativToSurfaceBase = false; // FaceList[i].Refresh(); //} }
/// <summary> /// creates a <see cref="Face"/> for a <see cref="Solid"/> in the <see cref="Model.Solid"/>. /// The Curves are all <see cref="Line3D"/>. The <see cref="Face"/> is plane and has as <see cref="Face.Surface"/> a <see cref="PlaneSurface"/>. /// </summary> /// <param name="Solid">is the target in which the <see cref="Face"/> will be posed.</param> /// <param name="Bounds">contains the <see cref="Vertex3d"/> for the <see cref="Line3D"/>.</param> /// <returns>a <see cref="Face"/></returns> public static Face SolidPlane(Solid Solid, Vertex3dArray_2 Bounds) { if (Bounds.Count == 0) { return(null); } xyz N = new xyz(0, 0, 0); xyz P = Bounds[0][0].Value; for (int i = 1; i < Bounds[0].Count - 1; i++) { xyz A = Bounds[0][i].Value; xyz B = Bounds[0][i + 1].Value; xyz M = N; N = N + ((A - P) & (B - P)); } N = N.normalized() * (-1); Base Base = Base.UnitBase; Base.BaseO = P; Base.BaseZ = N; 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; //------------------------------------- //-------- Create the Face Face Result = new Face(); // ---- With Plane Surface Result.Surface = Surface; if (Solid != null) { Solid.FaceList.Add(Result); } //----- Set the Edges for (int i = 0; i < Bounds.Count; i++) { EdgeLoop Edgeloop = new EdgeLoop(); Result.Bounds.Add(Edgeloop); for (int j = 0; j < Bounds[i].Count; j++) { Vertex3d A = Bounds[i][j]; Vertex3d B = null; if (j == Bounds[i].Count - 1) { B = Bounds[i][0]; } else { B = Bounds[i][j + 1]; } Edge E = Edge.SolidEdge(Solid, Result, A, B, new Line3D(A.Value, B.Value)); Edgeloop.Add(E); } } Result.RefreshParamCurves(); return(Result); }
/// <summary> /// overrides <see cref="Solid.Refresh()"/>. /// </summary> public override void Refresh() { Clear(); Cone ConeSurface = new Cone(); ConeSurface.VResolution = VResolution; ConeSurface.UResolution = UResolution; ConeSurface.Radius = Radius; ConeSurface.HalfAngle = HalfAngle; ConeSurface.Height = Height; Vertex3d[,] Points = new Vertex3d[ConeSurface.UResolution, ConeSurface.VResolution + 1]; Line3D[,] HorzCurves = new Line3D[ConeSurface.UResolution, ConeSurface.VResolution + 1]; Line3D[,] VertCurves = new Line3D[ConeSurface.UResolution, ConeSurface.VResolution]; Vertex3d[,] Normals = new Vertex3d[ConeSurface.UResolution + 1, ConeSurface.VResolution + 1]; for (int i = 0; i < ConeSurface.UResolution; i++) { for (int j = 0; j <= ConeSurface.VResolution; j++) { Points[i, j] = new Vertex3d(ConeSurface.Value((float)i / (float)ConeSurface.UResolution, (float)j / (float)ConeSurface.VResolution)); VertexList.Add(Points[i, j]); Normals[i, j] = new Vertex3d(ConeSurface.Normal((float)i / (float)ConeSurface.UResolution, (float)j / (float)ConeSurface.VResolution)); } } for (int i = 0; i < ConeSurface.UResolution; i++) { for (int j = 0; j <= ConeSurface.VResolution; j++) { if (i < ConeSurface.UResolution) { if (i + 1 < ConeSurface.UResolution) { HorzCurves[i, j] = new Line3D(Points[i, j].Value, Points[i + 1, j].Value); } else { HorzCurves[i, j] = new Line3D(Points[i, j].Value, Points[0, j].Value); } HorzCurves[i, j].Neighbors = new Face[2]; EdgeCurveList.Add(HorzCurves[i, j]); } if (j < ConeSurface.VResolution) { VertCurves[i, j] = new Line3D(Points[i, j].Value, Points[i, j + 1].Value); VertCurves[i, j].Neighbors = new Face[2]; EdgeCurveList.Add(VertCurves[i, j]); } } } for (int i = 0; i < ConeSurface.UResolution; i++) { for (int j = 0; j < ConeSurface.VResolution; j++) { int IInd = -1; Vertex3d A = Points[i, j]; Vertex3d B = Points[i, j + 1]; Vertex3d C = null; if (i + 1 < ConeSurface.UResolution) { IInd = i + 1; C = Points[i + 1, j + 1]; } else { IInd = 0; C = Points[0, j + 1]; } Vertex3d D = null; if (i + 1 < ConeSurface.UResolution) { D = Points[i + 1, j]; } else { D = Points[0, j]; } Face F = new Face(); FaceList.Add(F); F.Surface = new SmoothPlane(Points[i, j].Value, Points[IInd, j].Value, Points[i, j + 1].Value, Points[IInd, j + 1].Value, Normals[i, j].Value, Normals[IInd, j + 1].Value, Normals[i, j + 1].Value, Normals[IInd, j].Value); EdgeLoop EL = new EdgeLoop(); F.Bounds.Add(EL); Edge E = new Edge(); EdgeList.Add(E); EL.Add(E); E.EdgeStart = A; E.EdgeEnd = B; E.EdgeCurve = VertCurves[i, j]; E.EdgeCurve.Neighbors[0] = F; E.SameSense = true; E.ParamCurve = F.Surface.To2dCurve(E.EdgeCurve); E = new Edge(); EL.Add(E); EdgeList.Add(E); E.EdgeStart = B; E.EdgeEnd = C; E.EdgeCurve = HorzCurves[i, j + 1]; E.EdgeCurve.Neighbors[0] = F; E.SameSense = true; E.ParamCurve = F.Surface.To2dCurve(E.EdgeCurve); E = new Edge(); EL.Add(E); EdgeList.Add(E); E.EdgeStart = C; E.EdgeEnd = D; if (i + 1 < ConeSurface.UResolution) { E.EdgeCurve = VertCurves[i + 1, j]; } else { E.EdgeCurve = VertCurves[0, j]; } E.EdgeCurve.Neighbors[1] = F; E.SameSense = false; E.ParamCurve = F.Surface.To2dCurve(E.EdgeCurve); E.ParamCurve.Invert(); E = new Edge(); EL.Add(E); EdgeList.Add(E); E.EdgeStart = D; E.EdgeEnd = A; E.EdgeCurve = HorzCurves[i, j]; E.EdgeCurve.Neighbors[1] = F; E.SameSense = false; E.ParamCurve = F.Surface.To2dCurve(E.EdgeCurve); E.ParamCurve.Invert(); } } // Boden Base BodenBase = Base.From4Points(Points[0, 0].Value, Points[2, 0].Value, Points[1, 0].Value, Points[3, 0].Value); // Base BodenBase = Base.UnitBase; BodenBase.BaseO = Points[0, 0].Value; { Face F = new Face(); FaceList.Add(F); PlaneSurface S = null; S = new PlaneSurface(); S.Base = BodenBase; F.Surface = S; EdgeLoop EL = new EdgeLoop(); F.Bounds.Add(EL); for (int i = 0; i < ConeSurface.UResolution; i++) { Edge E = new Edge(); EL.Add(E); EdgeList.Add(E); E.EdgeStart = Points[i, 0]; if (i + 1 < ConeSurface.UResolution) { E.EdgeEnd = Points[i + 1, 0]; } else { E.EdgeEnd = Points[0, 0]; } E.EdgeCurve = HorzCurves[i, 0]; E.EdgeCurve.Neighbors[0] = F; E.SameSense = true; E.ParamCurve = S.To2dCurve(E.EdgeCurve); } } // Deckel { PlaneSurface S = null; S = new PlaneSurface(); BodenBase.BaseO = Points[0, ConeSurface.VResolution].Value; //S.Base = BodenBase; try { S.Base = Base.From4Points(Points[0, ConeSurface.VResolution].Value, Points[2, ConeSurface.VResolution].Value, Points[3, ConeSurface.VResolution].Value, Points[1, ConeSurface.VResolution].Value); } catch (Exception) { Base B = Base.UnitBase; B.BaseO = Points[0, ConeSurface.VResolution].Value; S.Base = B; } Face F = new Face(); FaceList.Add(F); F.Surface = S; EdgeLoop EL = new EdgeLoop(); F.Bounds.Add(EL); for (int i = ConeSurface.UResolution - 1; i >= 0; i--) // for (int i = 0; i < ConeSurface.UResolution; i++) { Edge E = new Edge(); EL.Add(E); EdgeList.Add(E); E.EdgeStart = Points[i, ConeSurface.VResolution]; //if (i + 1 < ConeSurface.UResolution) // E.EdgeEnd = Points[i + 1, ConeSurface.VResolution]; //else // E.EdgeEnd = Points[0, ConeSurface.VResolution]; E.EdgeEnd = Points[i, ConeSurface.VResolution]; if (i + 1 < ConeSurface.UResolution) { E.EdgeStart = Points[i + 1, ConeSurface.VResolution]; } else { E.EdgeStart = Points[0, ConeSurface.VResolution]; } E.EdgeCurve = HorzCurves[i, ConeSurface.VResolution]; if (E.EdgeStart.Value.dist(E.EdgeCurve.B) > 0.001) { } E.EdgeCurve.Neighbors[1] = F; E.SameSense = false; E.ParamCurve = S.To2dCurve(E.EdgeCurve); E.ParamCurve.Invert(); } } RefreshParamCurves(); base.Refresh(); }
/// <summary> /// gets the dual <see cref="Edge"/> in a <see cref="Face"/> which is given by <see cref="Face.Bounds"/>[Bound][(int)Param] In <b>OutBound</b> is the index of the dual <see cref="Edge"/> relativ to <b>Neighbor.Bounds</b> /// and the result value gives the parameter for the <see cref="Edge.ParamCurve"/> of this <see cref="Edge"/>. <b>Neighbor</b> is the neighbor <see cref="Face"/>. /// If no dual edge is found -1 will be returned. /// </summary> /// <param name="Face"><see cref="Face"/> in which <b>Bound</b> and <b>Param</b> are taken.</param> /// <param name="Bound">gives together with <b>Param</b> the <see cref="Edge"/> by <see cref="Face.Bounds"/>[Bound][(int)Param].</param> /// <param name="Param">gives together with <b>Bound</b> the <see cref="Edge"/> by <see cref="Face.Bounds"/>[Bound][(int)Param].</param> /// <param name="OutBound">is the bound index of the dual edge.</param> /// <param name="Neighbor">is the neighbor of <b>Face</b>.</param> /// <returns>a parameter, which gives togethe with <b>Outbound</b> the same point in the <b>dualedge</b> with dualedge.Paramcurve.value(parameter-(int)parameter.</returns> public static double GetDualEdge(Face Face, int Bound, double Param, ref int OutBound, ref Face Neighbor) { Edge E = Face.Bounds[Bound][(int)Param]; Vertex3d A = E.EdgeStart; Vertex3d B = E.EdgeEnd; Neighbor = Face.Neighbor(Bound, (int)Param) as Face; if (Neighbor == null) { return(-1); } OutBound = -1; for (int i1 = 0; i1 < Neighbor.Bounds.Count; i1++) { OutBound = i1; for (int i = 0; i < Neighbor.Bounds[i1].Count; i++) { if ((Neighbor.Bounds[i1][i].EdgeStart == B) && (Neighbor.Bounds[i1][i].EdgeEnd == A)) { if (Param != (int)Param) { return(i + (1 - (Param - (int)Param))); } return(i); } if ((Neighbor.Bounds[i1][i].EdgeStart == A) && (Neighbor.Bounds[i1][i].EdgeEnd == B)) { if (Param != (int)Param) { return(i + (1 - (Param - (int)Param))); } return(i); } } } return(-1); }