/// <summary> /// copies the <b>Face</b> to the <b>TargetSolid</b>. /// </summary> /// <param name="TargetSolid">is the target solid, in which the <see cref="Face"/> will be copied. /// If <b>TargetSolid</b> is null a simply copy of the face will be returned.</param> /// <returns>a copy of <b>Face</b>.</returns> public virtual Face Copy(Solid TargetSolid) { Face Result = Activator.CreateInstance(this.GetType()) as Face; Tag = Result; Result.Bounds = this.Bounds.Copy(TargetSolid); Result._ParamCurves = this.ParamCurves.Copy(); Result.Surface = this.Surface.Copy(); for (int i = 0; i < Result.Bounds.Count; i++) { EdgeLoop EL = Result.Bounds[i]; for (int j = 0; j < EL.Count; j++) { Edge E = EL[j]; Curve3D C = E.EdgeCurve; // if (Result is Face) { if (C.Neighbors == null) { C.Neighbors = new Face[2]; C.Neighbors[0] = Result as Face; } else { C.Neighbors[1] = Result as Face; } } } } if (TargetSolid != null) { TargetSolid.FaceList.Add(Result); } Result.RefreshParamCurves(); return(Result); }
/// <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); }