public static List <InterpolatedPoint> interp(Point3d p, Point3d p1, Point3d p2, Point3d p3) { List <InterpolatedPoint> ps = new List <InterpolatedPoint>(); p1 = new Point3d(p.X + (p1.X - p.X) / 4, p.Y + (p1.Y - p.Y) / 4, p.Z + (p1.Z - p.Z) / 4); p2 = new Point3d(p.X + (p2.X - p.X) / 4, p.Y + (p2.Y - p.Y) / 4, p.Z + (p2.Z - p.Z) / 4); p3 = new Point3d(p.X + (p3.X - p.X) / 4, p.Y + (p3.Y - p.Y) / 4, p.Z + (p3.Z - p.Z) / 4); //pl.Sort(new My.Point3dComparer()); //Point3d p1 = pl[0], p2 = pl[1], p3 = pl[2]; Autodesk.AutoCAD.Geometry.Plane plane1 = new Autodesk.AutoCAD.Geometry.Plane(p1, p2, p3); Autodesk.AutoCAD.Geometry.Matrix3d prjMat1 = Autodesk.AutoCAD.Geometry.Matrix3d.Projection(plane1, plane1.Normal); Point3d prjP = p.TransformBy(prjMat1); Autodesk.AutoCAD.Geometry.Vector3d direction = new Autodesk.AutoCAD.Geometry.Vector3d(p.X - prjP.X, p.Y - prjP.Y, p.Z - prjP.Z); Point3d tp = p1.TransformBy(Autodesk.AutoCAD.Geometry.Matrix3d.Displacement(direction * 1 / 3)); ps.Add(new InterpolatedPoint(direction.Length, new Point(tp.X, tp.Y, tp.Z))); tp = p2.TransformBy(Autodesk.AutoCAD.Geometry.Matrix3d.Displacement(direction * 1 / 3)); ps.Add(new InterpolatedPoint(direction.Length, new Point(tp.X, tp.Y, tp.Z))); tp = p3.TransformBy(Autodesk.AutoCAD.Geometry.Matrix3d.Displacement(direction * 1 / 3)); ps.Add(new InterpolatedPoint(direction.Length, new Point(tp.X, tp.Y, tp.Z))); return(ps); }
public static void Transform(List <Edge> el, Autodesk.AutoCAD.Geometry.Matrix3d matrix) { for (int i = 0; i < el.Count; i++) { Transform(el[i], matrix); } }
public static void Transform(ngeometry.VectorGeometry.Point p, Autodesk.AutoCAD.Geometry.Matrix3d matrix) { Autodesk.AutoCAD.Geometry.Point3d p3d = new Point3d(p.X, p.Y, p.Z); Autodesk.AutoCAD.Geometry.Point3d r = p3d.TransformBy(matrix); p.X = r.X; p.Y = r.Y; p.Z = r.Z; }
public static void Transform(Edge e, Autodesk.AutoCAD.Geometry.Matrix3d matrix) { /*Point3d p1 = pl[0], p2 = pl[1], p3 = pl[2]; * Autodesk.AutoCAD.Geometry.Plane plane1 = new Autodesk.AutoCAD.Geometry.Plane(p1, p2, p3); * Autodesk.AutoCAD.Geometry.Matrix3d prjMat1 = Autodesk.AutoCAD.Geometry.Matrix3d.Projection(plane1, plane1.Normal);*/ Transform(e.StartPoint, matrix); Transform(e.EndPoint, matrix); //Point3d prjP = p.TransformBy(prjMat1); }
public static CoordinateSystem GetCeometricUcs() { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Autodesk.AutoCAD.Geometry.Matrix3d currentUserCoordinateSystem = editor.CurrentUserCoordinateSystem; Point3d origin = currentUserCoordinateSystem.CoordinateSystem3d.Origin; Autodesk.AutoCAD.Geometry.Vector3d xaxis = currentUserCoordinateSystem.CoordinateSystem3d.Xaxis; Autodesk.AutoCAD.Geometry.Vector3d yaxis = currentUserCoordinateSystem.CoordinateSystem3d.Yaxis; Autodesk.AutoCAD.Geometry.Vector3d zaxis = currentUserCoordinateSystem.CoordinateSystem3d.Zaxis; ngeometry.VectorGeometry.Point originPoint = new ngeometry.VectorGeometry.Point(origin.X, origin.Y, origin.Z); ngeometry.VectorGeometry.Vector3d e = new ngeometry.VectorGeometry.Vector3d(xaxis.X, xaxis.Y, xaxis.Z); ngeometry.VectorGeometry.Vector3d e2 = new ngeometry.VectorGeometry.Vector3d(yaxis.X, yaxis.Y, yaxis.Z); ngeometry.VectorGeometry.Vector3d e3 = new ngeometry.VectorGeometry.Vector3d(zaxis.X, zaxis.Y, zaxis.Z); return(new ngeometry.VectorGeometry.CoordinateSystem(originPoint, e, e2, e3)); }
private Region method_2(SubDMeshHandler subDMeshHandler_0, int int_0) { Region result; try { using (DBObjectCollection dBObjectCollection = new DBObjectCollection()) { using (Face face = new Face(new Point3d(subDMeshHandler_0.Vertices[subDMeshHandler_0.FaceVertexIndex1[int_0]].X, subDMeshHandler_0.Vertices[subDMeshHandler_0.FaceVertexIndex1[int_0]].Y, subDMeshHandler_0.Vertices[subDMeshHandler_0.FaceVertexIndex1[int_0]].Z), new Point3d(subDMeshHandler_0.Vertices[subDMeshHandler_0.FaceVertexIndex2[int_0]].X, subDMeshHandler_0.Vertices[subDMeshHandler_0.FaceVertexIndex2[int_0]].Y, subDMeshHandler_0.Vertices[subDMeshHandler_0.FaceVertexIndex2[int_0]].Z), new Point3d(subDMeshHandler_0.Vertices[subDMeshHandler_0.FaceVertexIndex3[int_0]].X, subDMeshHandler_0.Vertices[subDMeshHandler_0.FaceVertexIndex3[int_0]].Y, subDMeshHandler_0.Vertices[subDMeshHandler_0.FaceVertexIndex3[int_0]].Z), false, false, false, false)) { dBObjectCollection.Add(face); Region region = Region.CreateFromCurves(dBObjectCollection)[0] as Region; result = region; } } } catch (System.Exception ex) { for (double num = 0.001; num <= 1000.0; num *= 10.0) { try { using (DBObjectCollection dBObjectCollection2 = new DBObjectCollection()) { using (Face face2 = new Face(new Point3d(subDMeshHandler_0.Vertices[subDMeshHandler_0.FaceVertexIndex1[int_0]].X, subDMeshHandler_0.Vertices[subDMeshHandler_0.FaceVertexIndex1[int_0]].Y, subDMeshHandler_0.Vertices[subDMeshHandler_0.FaceVertexIndex1[int_0]].Z), new Point3d(subDMeshHandler_0.Vertices[subDMeshHandler_0.FaceVertexIndex2[int_0]].X, subDMeshHandler_0.Vertices[subDMeshHandler_0.FaceVertexIndex2[int_0]].Y, subDMeshHandler_0.Vertices[subDMeshHandler_0.FaceVertexIndex2[int_0]].Z), new Point3d(subDMeshHandler_0.Vertices[subDMeshHandler_0.FaceVertexIndex3[int_0]].X, subDMeshHandler_0.Vertices[subDMeshHandler_0.FaceVertexIndex3[int_0]].Y, subDMeshHandler_0.Vertices[subDMeshHandler_0.FaceVertexIndex3[int_0]].Z), false, false, false, false)) { Autodesk.AutoCAD.Geometry.Matrix3d matrix3d = Autodesk.AutoCAD.Geometry.Matrix3d.Scaling(num, new Point3d(0.0, 0.0, 0.0)); Autodesk.AutoCAD.Geometry.Matrix3d matrix3d2 = Autodesk.AutoCAD.Geometry.Matrix3d.Scaling(1.0 / num, new Point3d(0.0, 0.0, 0.0)); face2.TransformBy(matrix3d); dBObjectCollection2.Add(face2); Region region2 = Region.CreateFromCurves(dBObjectCollection2)[0] as Region; region2.TransformBy(matrix3d2); result = region2; return(result); } } } catch (System.Exception ex111) { } } result = null; } return(result); }
public static PointSet __interp(Point3d p, List <LineSegment3d> ll) { if (ll.Count < 3) { return(null); } PointSet ps = new PointSet(); List <Point3d> pl = new List <Point3d>(); Point3d ortherP; for (int i = 0; i < ll.Count; i++) { if (p == ll[0].EndPoint) { ortherP = ll[0].StartPoint; } else { ortherP = ll[i].EndPoint; } Point3d tp = new Point3d(p.X + (ortherP.X - p.X) / 3, p.Y + (ortherP.Y - p.Y) / 3, p.Z + (ortherP.Z - p.Z) / 3); pl.Add(tp); } Point3d p1 = pl[0], p2 = pl[1], p3 = pl[2]; Autodesk.AutoCAD.Geometry.Plane plane1 = new Autodesk.AutoCAD.Geometry.Plane(p1, p2, p3); Autodesk.AutoCAD.Geometry.Matrix3d prjMat1 = Autodesk.AutoCAD.Geometry.Matrix3d.Projection(plane1, plane1.Normal); Point3d prjP = p.TransformBy(prjMat1); Autodesk.AutoCAD.Geometry.Vector3d direction = new Autodesk.AutoCAD.Geometry.Vector3d(p.X - prjP.X, p.Y - prjP.Y, p.Z - prjP.Z); for (int i = 0; i < pl.Count; i++) { //double d = p.DistanceTo(prjP); ; Point3d tp = pl[i].TransformBy(Autodesk.AutoCAD.Geometry.Matrix3d.Displacement(direction * 2 / 3)); ps.Add(new Point(tp.X, tp.Y, tp.Z)); } return(ps); }
internal static ProjectClass getMovement(Point3d p, Point3d p1, Point3d p2, Point3d p3) { List <InterpolatedPoint> ps = new List <InterpolatedPoint>(); //p1 = new Point3d(p.X + (p1.X - p.X) / 4, p.Y + (p1.Y - p.Y) / 4, p.Z + (p1.Z - p.Z) / 4); //p2 = new Point3d(p.X + (p2.X - p.X) / 4, p.Y + (p2.Y - p.Y) / 4, p.Z + (p2.Z - p.Z) / 4); //p3= new Point3d(p.X + (p3.X - p.X) /4, p.Y + (p3.Y - p.Y) / 4, p.Z + (p3.Z - p.Z) / 4); //pl.Sort(new My.Point3dComparer()); //Point3d p1 = pl[0], p2 = pl[1], p3 = pl[2]; Autodesk.AutoCAD.Geometry.Plane plane1 = new Autodesk.AutoCAD.Geometry.Plane(p1, p2, p3); Autodesk.AutoCAD.Geometry.Matrix3d prjMat1 = Autodesk.AutoCAD.Geometry.Matrix3d.Projection(plane1, plane1.Normal); Point3d prjP = p.TransformBy(prjMat1); Autodesk.AutoCAD.Geometry.Vector3d direction = new Autodesk.AutoCAD.Geometry.Vector3d(p.X - prjP.X, p.Y - prjP.Y, p.Z - prjP.Z); List <Point3d> pl = new List <Point3d>(); pl.Add(p1); pl.Add(p2); pl.Add(p3); return(new ProjectClass(plane1, prjMat1, direction, pl)); }
internal ProjectClass(Autodesk.AutoCAD.Geometry.Plane p, Autodesk.AutoCAD.Geometry.Matrix3d m, Autodesk.AutoCAD.Geometry.Vector3d d, List <Point3d> pl) { plane = p; prjMat = m; direction = d; points = pl; }
private void method_0(ObjectId[] objectId_0, ProgressMeter progressMeter_0, CoordinateSystem coordinateSystem_0) { Database workingDatabase = HostApplicationServices.WorkingDatabase; Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; List <Solid3d> list = new List <Solid3d>(); double epsilon = Convert.ToDouble(CMD_FacesToSolid.string_2); bool flag = true; if (CMD_FacesToSolid.string_0 == "N") { flag = false; } DBManager.SetEpsilon(); List <Triangle> list2 = Conversions.ToCeometricAcDbTriangleList(objectId_0); if (!Conversions.IsWCS(coordinateSystem_0)) { Triangle.TransformCoordinates(list2, CoordinateSystem.Global(), coordinateSystem_0); } list2.Sort(new Triangle.CompareMinX()); int num = 0; double num2 = -1.7976931348623157E+308; double num3 = -1.7976931348623157E+308; double num4 = 1.7976931348623157E+308; double num5 = 1.7976931348623157E+308; for (int i = list2.Count - 1; i >= 0; i--) { if (list2[i].NormalVector.IsOrthogonalTo(new ngeometry.VectorGeometry.Vector3d(0.0, 0.0, 1.0))) { list2.RemoveAt(i); num++; } else { double minimumX = list2[i].MinimumX; if (minimumX < num4) { num4 = minimumX; } double maximumX = list2[i].MaximumX; if (maximumX > num2) { num2 = maximumX; } double minimumY = list2[i].MinimumY; if (minimumY < num5) { num5 = minimumY; } double maximumY = list2[i].MaximumY; if (maximumY > num3) { num3 = maximumY; } } } ngeometry.VectorGeometry.Vector3d vector3d = new ngeometry.VectorGeometry.Vector3d(0.5 * (num4 + num2), 0.5 * (num5 + num3), 0.0); double num6 = 0.5 * Math.Max(Math.Abs(num2 - num4), Math.Abs(num3 - num5)); double num7 = Math.Ceiling(100000.0 / num6); for (int j = 0; j < list2.Count; j++) { list2[j] = list2[j].Move(-1.0 * vector3d); } SubDMeshHandler subDMeshHandler = new SubDMeshHandler(list2); subDMeshHandler.BuildDataStructure(false); int k = 2147483647; while (k > 0) { this.messageFilter_0.CheckMessageFilter(); k = subDMeshHandler.HealXY(epsilon); num += k; } editor.WriteMessage("\nDegenerate projections healed: " + num); Autodesk.AutoCAD.Geometry.Matrix3d matrix3d = Autodesk.AutoCAD.Geometry.Matrix3d.Scaling(num7, new Point3d(0.0, 0.0, 0.0)); Autodesk.AutoCAD.Geometry.Matrix3d matrix3d2 = Autodesk.AutoCAD.Geometry.Matrix3d.Scaling(1.0 / num7, new Point3d(0.0, 0.0, 0.0)); Autodesk.AutoCAD.Geometry.Matrix3d matrix3d3 = Autodesk.AutoCAD.Geometry.Matrix3d.Displacement(new Autodesk.AutoCAD.Geometry.Vector3d(vector3d.X, vector3d.Y, 0.0)); progressMeter_0 = new ProgressMeter(); progressMeter_0.SetLimit(objectId_0.Length); progressMeter_0.Start("Extruding objects"); int num8 = 0; int num9 = 0; for (int l = 0; l < subDMeshHandler.FaceVertexIndex1.Count; l++) { try { progressMeter_0.MeterProgress(); this.messageFilter_0.CheckMessageFilter((long)l, 1000); } catch (System.Exception ex) { for (int m = 0; m < list.Count; m++) { list[m].Dispose(); } progressMeter_0.Stop(); throw; } try { Face face = new Face(new Point3d(subDMeshHandler.Vertices[subDMeshHandler.FaceVertexIndex1[l]].X, subDMeshHandler.Vertices[subDMeshHandler.FaceVertexIndex1[l]].Y, subDMeshHandler.Vertices[subDMeshHandler.FaceVertexIndex1[l]].Z), new Point3d(subDMeshHandler.Vertices[subDMeshHandler.FaceVertexIndex2[l]].X, subDMeshHandler.Vertices[subDMeshHandler.FaceVertexIndex2[l]].Y, subDMeshHandler.Vertices[subDMeshHandler.FaceVertexIndex2[l]].Z), new Point3d(subDMeshHandler.Vertices[subDMeshHandler.FaceVertexIndex3[l]].X, subDMeshHandler.Vertices[subDMeshHandler.FaceVertexIndex3[l]].Y, subDMeshHandler.Vertices[subDMeshHandler.FaceVertexIndex3[l]].Z), false, false, false, false); double z = face.GetVertexAt(0).Z; double z2 = face.GetVertexAt(1).Z; double z3 = face.GetVertexAt(2).Z; short num10; if (CMD_FacesToSolid.double_0 < 0.0) { if (z <= z2 && z <= z3) { num10 = 0; } else if (z2 <= z && z2 <= z3) { num10 = 1; } else { num10 = 2; } } else if (z >= z2 && z >= z3) { num10 = 0; } else if (z2 >= z && z2 >= z3) { num10 = 1; } else { num10 = 2; } Point3d vertexAt = face.GetVertexAt(num10); Point3d point3d = new Point3d(vertexAt.X, vertexAt.Y, vertexAt.Z + CMD_FacesToSolid.double_0); //point3d..ctor(vertexAt.X, vertexAt.Y, vertexAt.Z + CMD_FacesToSolid.double_0); Autodesk.AutoCAD.DatabaseServices.Line line = new Autodesk.AutoCAD.DatabaseServices.Line(vertexAt, point3d); Region region = this.method_2(subDMeshHandler, l); if (region == null) { num8++; } else { region.TransformBy(matrix3d); line.TransformBy(matrix3d); try { Solid3d solid3d = new Solid3d(); solid3d.ExtrudeAlongPath(region, line, 0.0); solid3d.SetPropertiesFrom(face); list.Add(solid3d); } catch (System.Exception ex) { num9++; } line.Dispose(); region.Dispose(); } } catch (System.Exception ex) { } } editor.WriteMessage("\nNumber of failed projections: " + num8.ToString()); editor.WriteMessage("\nNumber of failed extrusions : " + num8.ToString()); progressMeter_0.Stop(); if (flag && list.Count > 1) { progressMeter_0 = new ProgressMeter(); int limit = (int)Math.Ceiling(Math.Log((double)list.Count) / Math.Log(2.0)); progressMeter_0.SetLimit(limit); progressMeter_0.Start("Building solid"); this.method_1(ref list, ref progressMeter_0); } using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { BlockTable blockTable = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)1); BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], (OpenMode)1); for (int n = 0; n < list.Count; n++) { list[n].TransformBy(matrix3d2); list[n].TransformBy(matrix3d3); CoordinateTransformator coordinateTransformator = new CoordinateTransformator(coordinateSystem_0, CoordinateSystem.Global()); if (!coordinateTransformator.bool_0) { list[n].TransformBy(coordinateTransformator.ToAcadTransformation()); } blockTableRecord.AppendEntity(list[n]); transaction.AddNewlyCreatedDBObject(list[n], true); } transaction.Commit(); } progressMeter_0.Stop(); }
private void method_0(ObjectId[] objectId_0, ref ProgressMeter progressMeter_0, CoordinateSystem coordinateSystem_0) { Database workingDatabase = HostApplicationServices.WorkingDatabase; Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; List <Region> list = new List <Region>(); double epsilon = Convert.ToDouble(CMD_Silhouette.string_1); DBManager.SetEpsilon(); List <Triangle> list2 = Conversions.ToCeometricAcDbTriangleList(objectId_0); if (!Conversions.IsWCS(coordinateSystem_0)) { Triangle.TransformCoordinates(list2, CoordinateSystem.Global(), coordinateSystem_0); } list2.Sort(new Triangle.CompareMinX()); int num = 0; double num2 = -1.7976931348623157E+308; double num3 = -1.7976931348623157E+308; double num4 = 1.7976931348623157E+308; double num5 = 1.7976931348623157E+308; for (int i = list2.Count - 1; i >= 0; i--) { if (list2[i].NormalVector.IsOrthogonalTo(new ngeometry.VectorGeometry.Vector3d(0.0, 0.0, 1.0))) { list2.RemoveAt(i); num++; } else { Global.SuspendEpsilon(0.0, 0.0); list2[i].Vertex1.Z = 0.0; list2[i].Vertex2.Z = 0.0; list2[i].Vertex3.Z = 0.0; Global.ResumeEpsilon(); double minimumX = list2[i].MinimumX; if (minimumX < num4) { num4 = minimumX; } double maximumX = list2[i].MaximumX; if (maximumX > num2) { num2 = maximumX; } double minimumY = list2[i].MinimumY; if (minimumY < num5) { num5 = minimumY; } double maximumY = list2[i].MaximumY; if (maximumY > num3) { num3 = maximumY; } } } ngeometry.VectorGeometry.Vector3d vector3d = new ngeometry.VectorGeometry.Vector3d(0.5 * (num4 + num2), 0.5 * (num5 + num3), 0.0); double num6 = 0.5 * Math.Max(Math.Abs(num2 - num4), Math.Abs(num3 - num5)); double num7 = Math.Ceiling(100000.0 / num6); for (int j = 0; j < list2.Count; j++) { list2[j] = list2[j].Move(-1.0 * vector3d); } SubDMeshHandler subDMeshHandler = new SubDMeshHandler(list2); subDMeshHandler.BuildDataStructure(false); int k = 2147483647; while (k > 0) { this.messageFilter_0.CheckMessageFilter(); k = subDMeshHandler.Heal(epsilon); num += k; } editor.WriteMessage("\nDegenerate projections healed: " + num); Autodesk.AutoCAD.Geometry.Matrix3d matrix3d = Autodesk.AutoCAD.Geometry.Matrix3d.Scaling(num7, new Point3d(0.0, 0.0, 0.0)); Autodesk.AutoCAD.Geometry.Matrix3d matrix3d2 = Autodesk.AutoCAD.Geometry.Matrix3d.Scaling(1.0 / num7, new Point3d(0.0, 0.0, 0.0)); Autodesk.AutoCAD.Geometry.Matrix3d matrix3d3 = Autodesk.AutoCAD.Geometry.Matrix3d.Displacement(new Autodesk.AutoCAD.Geometry.Vector3d(vector3d.X, vector3d.Y, 0.0)); progressMeter_0 = new ProgressMeter(); progressMeter_0.SetLimit(subDMeshHandler.FaceVertexIndex1.Count); progressMeter_0.Start("Generating projections"); int num8 = 0; for (int l = 0; l < subDMeshHandler.FaceVertexIndex1.Count; l++) { try { progressMeter_0.MeterProgress(); this.messageFilter_0.CheckMessageFilter((long)l, 1000); } catch (System.Exception ex) { for (int m = 0; m < list.Count; m++) { list[m].Dispose(); } progressMeter_0.Stop(); throw; } Region region = this.method_2(subDMeshHandler, l); if (region == null) { num8++; } else { region.TransformBy(matrix3d); list.Add(region); } } editor.WriteMessage("\nNumber of failed projections: " + num8.ToString()); progressMeter_0.Stop(); progressMeter_0 = new ProgressMeter(); int limit = (int)Math.Ceiling(Math.Log((double)list.Count) / Math.Log(2.0)); progressMeter_0.SetLimit(limit); progressMeter_0.Start("Computing silhouette"); if (list.Count > 1) { this.method_1(ref list, ref progressMeter_0); } list[0].TransformBy(matrix3d2); list[0].TransformBy(matrix3d3); CoordinateTransformator coordinateTransformator = new CoordinateTransformator(coordinateSystem_0, CoordinateSystem.Global()); if (!coordinateTransformator.bool_0) { list[0].TransformBy(coordinateTransformator.ToAcadTransformation()); } using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { BlockTable blockTable = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)1); BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], (OpenMode)1); blockTableRecord.AppendEntity(list[0]); transaction.AddNewlyCreatedDBObject(list[0], true); transaction.Commit(); } progressMeter_0.Stop(); }