void TransformTail(Point3d p1, Point3d p11, double bulge, sbyte flip, ref Polyline tail, out double offset) { double angle = 2 * Math.Atan(bulge); /*угол касательной аналитически получен как 2 вписанных угла. Например, если bulge равно 1, то * имеем дугу с хордой равной двум выпуклостям. Это соответствует углу между хордой и касательной 90 градусов, а угол между хордой * и хордой к середине дуги 45 градусов */ angle *= flip; //чтобы было в нужную сторону на обоих концах Vector3d p1p2v = p1.Subtract(p11.GetAsVector()).GetAsVector(); p1p2v = p1p2v.RotateBy(angle, Vector3d.ZAxis * -1); //-1здесь служит для корректировки направления (по результатам отладки) Point2d first = tail.GetPoint2dAt(0); offset = first.Y * offsetMode * side; //смысл смещения заключается в том, что иногда требуется нарисовать шпильки со смещением от базовой линии //смещение управляется начальной координатой хвоста Matrix3d M = Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, p1, p1p2v.DivideBy(p1p2v.Length), p1p2v.GetPerpendicularVector().MultiplyBy(side * flip), Vector3d.ZAxis); M *= Matrix3d.Displacement(Vector3d.YAxis * first.Y * -1 * (offsetMode ^ 1)); tail.TransformBy(M); }
public void cmdTestUCS() { var doc = AcApp.DocumentManager.MdiActiveDocument; var ed = doc.Editor; var db = doc.Database; using (var tr = db.TransactionManager.StartTransaction()) { var bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; var ms = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; var ucs = new CoordinateSystem3d(new Point3d(11, 22, 0), Vector3d.XAxis, Vector3d.YAxis); //UCS到WCS的转换矩阵 var matrix = Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, ucs.Origin, ucs.Xaxis, ucs.Yaxis, ucs.Zaxis); ed.CurrentUserCoordinateSystem = matrix; //API中加进去的都是WCS的坐标,我们构造的时候是通过UCS里的坐标值来构造的,真正加进去之前需要转换到WCS var circle = new Autodesk.AutoCAD.DatabaseServices.Circle(); circle.Center = new Point3d(10, 10, 0); circle.Radius = 5; circle.TransformBy(matrix); ms.AppendEntity(circle); tr.AddNewlyCreatedDBObject(circle, true); tr.Commit(); } }
void InputTail() { asc = UT.GetAnnoScale("CANNOSCALE"); var sset_poly = Input.Objects("Выберите полилинию-хвост. Прикрепление будет к начальной точке"); if (Input.StatusOK) { using (var th = new TransactionHelper()) { try { var pl = th.EditObjects(sset_poly)[0] as Polyline; tail_default = pl.Clone() as Polyline; } catch (System.Exception) { InputTail(); return; } var p1 = Input.Point("Укажите базовую точку"); var p2 = Input.Point("Укажите направление Х"); var p1p2v = p1.Subtract(p2.GetAsVector()).GetAsVector(); tail_default.TransformBy(Matrix3d.AlignCoordinateSystem(p1, p1p2v.DivideBy(p1p2v.Length), p1p2v.GetPerpendicularVector(), Vector3d.ZAxis, Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis)); tail_default.TransformBy(Matrix3d.Scaling(asc.Scale, Point3d.Origin)); } } }
public static Matrix3d GetUcs(Point3d f, Point3d s, Point3d T, bool toWcSorToUCs) { Matrix3d UCS; var qF = new Quaternion(0, f.X, f.Y, f.Z); var qS = new Quaternion(0, s.X, s.Y, s.Z); var qT = new Quaternion(0, T.X, T.Y, T.Z); var ucs = new UCS(qF, qS, qT); var qX = ucs.ToACS(new Quaternion(0, 1, 0, 0)) - ucs.ToACS(new Quaternion(0, 0, 0, 0)); var qY = ucs.ToACS(new Quaternion(0, 0, 1, 0)) - ucs.ToACS(new Quaternion(0, 0, 0, 0)); var qZ = ucs.ToACS(new Quaternion(0, 0, 0, 1)) - ucs.ToACS(new Quaternion(0, 0, 0, 0)); var o = ucs.ToACS(new Quaternion(0, 0, 0, 0)); var x = new Vector3d(qX.GetX(), qX.GetY(), qX.GetZ()); var y = new Vector3d(qY.GetX(), qY.GetY(), qY.GetZ()); var z = new Vector3d(qZ.GetX(), qZ.GetY(), qZ.GetZ()); var O = new Point3d(o.GetX(), o.GetY(), o.GetZ()); if (toWcSorToUCs) { UCS = Matrix3d.AlignCoordinateSystem( Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, O, x, y, z); } else { UCS = Matrix3d.AlignCoordinateSystem( O, x, y, z, Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis); } return(UCS); }
public static void ShowWCSAndUCS(Point3d p) { Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { Point3d pPt3dWCS = p; Point3d pPt3dUCS = p; ViewportTableRecord acVportTblRec; acVportTblRec = acTrans.GetObject(acDoc.Editor.ActiveViewportId, OpenMode.ForWrite) as ViewportTableRecord; Matrix3d newMatrix = new Matrix3d(); newMatrix = Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, acVportTblRec.Ucs.Origin, acVportTblRec.Ucs.Xaxis, acVportTblRec.Ucs.Yaxis, acVportTblRec.Ucs.Zaxis); pPt3dWCS = pPt3dWCS.TransformBy(newMatrix); Application.ShowAlertDialog("The WCS coordinates are: \n" + pPt3dWCS.ToString() + "\n" + "The UCS coordinates are: \n" + pPt3dUCS.ToString()); acTrans.Commit(); } }
/// <summary> /// нанизываем на линию символы исходя из точек /// </summary> /// <param name="data">массив точек для вставки символов</param> /// <returns></returns> Polyline Prepare() { var result = new Polyline(); //сортируем точки исходя из расстояния от начала data.Sort((x, y) => x.GetDistanceTo(p1.to2d()).CompareTo(y.GetDistanceTo(p1.to2d()))); result.AddVertexAt(0, p11.to2d(), 0, 0, 0); foreach (Point2d pt in data) { Matrix3d M = Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, new Point3d(pt.X, pt.Y, 0), p1p2v, p1p2v.GetPerpendicularVector(), Vector3d.ZAxis); //переносим и масштабируем символ Polyline bl = DefaultPolyline(); bl.TransformBy(M); M = Matrix3d.Scaling(size, new Point3d(pt.X, pt.Y, 0)); bl.TransformBy(M); //добавляем символ по одной точке в результирующую полилинию в ее конец for (int i = 0; i < bl.NumberOfVertices; i++) { result.AddVertexAt(result.NumberOfVertices, bl.GetPoint2dAt(i), 0, 0, 0); } } result.AddVertexAt(result.NumberOfVertices, p21.to2d(), 0, 0, 0); result.SetDatabaseDefaults(); return(result); }
GetEcsToWcsMatrix(Point3d origin, Vector3d zAxis) { const double kArbBound = 0.015625; // 1/64th // short circuit if in WCS already if (zAxis == Utils.Ge.kZAxis) { return(Matrix3d.Identity); } Vector3d xAxis, yAxis; Debug.Assert(zAxis.IsUnitLength(Tolerance.Global)); if ((Math.Abs(zAxis.X) < kArbBound) && (Math.Abs(zAxis.Y) < kArbBound)) { xAxis = Utils.Ge.kYAxis.CrossProduct(zAxis); } else { xAxis = Utils.Ge.kZAxis.CrossProduct(zAxis); } xAxis = xAxis.GetNormal(); yAxis = zAxis.CrossProduct(xAxis).GetNormal(); return(Matrix3d.AlignCoordinateSystem(Utils.Ge.kOrigin, Utils.Ge.kXAxis, Utils.Ge.kYAxis, Utils.Ge.kZAxis, origin, xAxis, yAxis, zAxis)); }
public static void InCline() { var sset = Input.Objects("Выберите объекты для преобразования"); if (Input.StatusBad) { return; } Point3d basePnt = Input.Point("Укажите базовую точку преобразования."); if (Input.StatusBad) { return; } //elevation divided by horisontal longtitude или по-русски уклон, тангенс угла наклона double tangent = Input.Double("Введите величину уклона. Положительный уклон повышается вправо (Х+ У+)"); if (Input.StatusBad) { return; } var matrix = Matrix3d.AlignCoordinateSystem( basePnt, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, basePnt, Vector3d.XAxis + Vector3d.YAxis * tangent, Vector3d.YAxis, Vector3d.ZAxis); using (var th = new TransactionHelper()) { sth = th; var objects = th.EditObjects(sset); TransformObjects(objects, matrix); sth = null; } }
/// <summary> /// Transform point3D coordinate from WCS to named UCS /// </summary> /// <param name="pnts"></param> /// <param name="ucsName"></param> /// <returns></returns> public static Point3dCollection Wcs2Ucs(Point3dCollection pnts, string ucsName) { Document doc = acApp.DocumentManager.MdiActiveDocument; Database db = doc.Database; Point3dCollection ucsPnts = new Point3dCollection(); using (Transaction tr = db.TransactionManager.StartTransaction()) { UcsTable acUCSTbl; acUCSTbl = tr.GetObject(db.UcsTableId, OpenMode.ForRead) as UcsTable; UcsTableRecord ucs1 = tr.GetObject(acUCSTbl[ucsName], OpenMode.ForRead) as UcsTableRecord; Matrix3d mat = Matrix3d.AlignCoordinateSystem( ucs1.Origin, ucs1.XAxis, ucs1.YAxis, ucs1.XAxis.CrossProduct(ucs1.YAxis), Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.XAxis.CrossProduct(ucs1.YAxis) ); // Translate foreach (Point3d p in pnts) { ucsPnts.Add(p.TransformBy(mat)); } tr.Commit(); } return(ucsPnts); }
public static CoordinateSystem3d GetZAxisUcsToWorld(Editor ed, Point3d basePoint, Point3d positiveZaxisPoint) { var pPt3dWCS = positiveZaxisPoint; var pPt3dUCS = positiveZaxisPoint; Plane plane = new Plane(basePoint, basePoint.GetVectorTo(positiveZaxisPoint)); Matrix3d ucs = Matrix3d.PlaneToWorld(plane); var cs = ucs.CoordinateSystem3d; ed.WriteMessage(String.Format(" GetZAxisUcsToWorld: X={0},Y={1},Z={2}", cs.Xaxis, cs.Yaxis, cs.Zaxis)); // Translate the point from the current UCS to the WCS Matrix3d newMatrix = new Matrix3d(); newMatrix = Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, ucs.CoordinateSystem3d.Origin, ucs.CoordinateSystem3d.Xaxis, ucs.CoordinateSystem3d.Yaxis, ucs.CoordinateSystem3d.Zaxis); pPt3dWCS = pPt3dUCS.TransformBy(newMatrix); ed.WriteMessage("\nThe WCS coordinates are: \n" + pPt3dWCS.ToString() + "\n" + "\nThe UCS coordinates are: \n" + pPt3dUCS.ToString()); return(ucs.CoordinateSystem3d); }
/// <summary> /// 判断点是否嵌入了表面所在的板件 /// </summary> /// <param name="pt"></param> /// <param name="peakValue">嵌入板件的深度值,按照设计这个值应当是负值</param> /// <param name="associateDist">判定时的容差,为正值</param> /// <returns></returns> private bool IsDistEnough(PartFace anotherFace, Point3d pt, double peakValue, double associateDist) { //先把世界坐标系下的pt转换成mp坐标系下 pt = pt.TransformBy(Matrix3d.AlignCoordinateSystem(anotherFace.Part.MovedMPPoint, anotherFace.Part.MovedMPXAxis, anotherFace.Part.MovedMPYAxis, anotherFace.Part.MovedMPZAxis, Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis)); //取有效数字两个,是为了避免精确计算的情况下的误差导致判断错误 double z = System.Math.Round(pt.Z, 2); //面5和面6的判断不同,这是因为Z的正方向发生了变化 double zlimitDown = 0 - peakValue; double zlimitUp = associateDist - peakValue; if (anotherFace.FaceNumber == 6) { zlimitUp = associateDist + this.Part.Thickness + peakValue; zlimitDown = this.Part.Thickness + peakValue; } if (z >= zlimitDown && z <= zlimitUp) { return(true); } else { return(false); } }
public override void ToMachining(double AssociatedDist, ToolFile toolFile) { //得到当前面的关联面 AssociatedPartFaceList = base.FindAssociatedFacesOneTime(AssociatedDist, Penetration); //当前的face var currentFace = this.Part.GetPartFaceByNumber(this.FaceNumber); foreach (var f in AssociatedPartFaceList) { //得到一个转换矩阵,将 var matrix = Matrix3d.AlignCoordinateSystem(f.Part.MovedMPPoint, f.Part.MovedMPXAxis, f.Part.MovedMPYAxis, f.Part.MovedMPZAxis, Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis); //将关联面的两个点作为铣型的起始 var pt1 = currentFace.Point1.TransformBy(matrix); var pt2 = currentFace.Point4.TransformBy(matrix); //TODO:需要考虑的事情 //1、LeadIn和LeadOut //2、铣型的方向 //3、double/triple pass //4、刀补的方向如何偏移 //5、宽度的方向如何偏移 List <Point3d> points = new List <Point3d>() { pt1, pt2 }; List <double> bulges = new List <double>() { 0, 0 }; Machinings.Routing route = new Machinings.Routing(); route.Bulges = bulges; route.Points = points; route.ToolComp = ToolComp.None; route.Part = f.Part; route.OnFace5 = (f.FaceNumber == 5) ? true : false; route.ToolName = this.ToolName; f.Part.Routings.Add(route); } }
private Matrix3d PlineUCS(Polyline pline, int param) { Point3d origin = pline.GetPoint3dAt(param); Vector3d xDir = origin.GetVectorTo(pline.GetPoint3dAt(param + 1)).GetNormal(); Vector3d zDir = pline.Normal; Vector3d yDir = zDir.CrossProduct(xDir).GetNormal(); return(Matrix3d.AlignCoordinateSystem( Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, origin, xDir, yDir, zDir)); }
// 根据入口向量、法向量获得变换矩阵 Matrix3d GetTranslateMatrix(Point3d inPoint, Vector3d inVector, Vector3d normal) { Vector3d xAxis = inVector; xAxis = xAxis.GetNormal(); Vector3d zAxis = normal; zAxis = zAxis.GetNormal(); Vector3d yAxis = new Vector3d(xAxis.X, xAxis.Y, xAxis.Z); yAxis = yAxis.RotateBy(Math.PI * 0.5, zAxis); return(Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, inPoint, xAxis, yAxis, zAxis)); }
/// <summary> /// TODO /// </summary> /// <returns></returns> public Matrix3d LayMatrix() { Vector3d normal; Vector3d vector3D; Vector3d normal1; Matrix3d matrix3D; Vector3d vector; if (XEdge.Length < SettingsUser.TolPoint) { matrix3D = new Matrix3d(); return(matrix3D); } if (!_rightAngle) { vector = XEdge.Eaxis.ToVector(); normal = vector.GetNormal(); } else { normal = XEdge.Tangent.GetNormal(); } if (!Normal.IsLessThanTol()) { normal1 = Normal.GetNormal(); vector = normal1.CrossProduct(normal); vector3D = vector.GetNormal(); vector = normal.CrossProduct(vector3D); normal1 = vector.GetNormal(); } else { if (YEdge.Length < SettingsUser.TolPoint) { matrix3D = new Matrix3d(); return(matrix3D); } vector3D = YEdge.Tangent.GetNormal(); vector = normal.CrossProduct(YEdge.Tangent); normal1 = vector.GetNormal(); vector = normal1.CrossProduct(normal); vector3D = vector.GetNormal(); } return(Matrix3d.AlignCoordinateSystem(VertPoint, normal, vector3D, normal1, Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis)); }
public override void ToMachining(double associateDist, Entities.ToolFile toolFile) { FindAssociatedFaces(associateDist); PartFace pf = this.Part.GetPartFaceByNumber(FaceNumber); if (pf.AssociatedPartFaces.Count != 0)//数量不为0,说明有关联的板件 { List <HDrilling> TempHDrills = new List <HDrilling>(); foreach (double d in this.PointsPosition) { HDrilling hdrill = new HDrilling(this.FaceNumber, this.EdgeBoreDiameter, this.EdgeBoreDepth, d, this.ZValue, Part); TempHDrills.Add(hdrill); } foreach (StructXY xy in this.ListCamVBoreXY) { VDrilling vdrill = new VDrilling(this.CamFaceNumber, xy.X, xy.Y, this.CamFaceBoreDiameter, this.CamFaceBoreDepth, Part); Part.VDrillings.Add(vdrill); } foreach (PartFace f in pf.AssociatedPartFaces) { if (!f.IsHorizontalFace)//如果关联的面是面5或面6 { foreach (HDrilling hdrill in TempHDrills) { Point3d holeposition = hdrill.GetBorePosition(); holeposition = holeposition.TransformBy(Matrix3d.AlignCoordinateSystem(new Point3d(), Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, hdrill.Part.MPPoint, hdrill.Part.MPXAxis, hdrill.Part.MPYAxis, hdrill.Part.MPZAxis)); holeposition = Math.MathHelper.GetRotatedAndMovedPoint(holeposition, Part.TXRotation, Part.TYRotation, Part.TZRotation, Part.CenterVector); holeposition = holeposition.TransformBy(Matrix3d.AlignCoordinateSystem(f.Part.MovedMPPoint, f.Part.MovedMPXAxis, f.Part.MovedMPYAxis, f.Part.MovedMPZAxis, new Point3d(), Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis)); double dimx = holeposition.X; double dimy = holeposition.Y; VDrilling vdrill = new VDrilling(f.FaceNumber, dimx, dimy, this.FaceBoreDiameter, this.FaceBoreDepth, f.Part); f.Part.VDrillings.Add(vdrill); } } else//TODO:如果关联的面是水平面 { } } if (this.EdgeBoreDiameter > 0 && this.EdgeBoreDepth > 0) { Part.HDrillings.AddRange(TempHDrills); } } }
WCS2UCS(Point3d pnt3dOrigin, Point3d pnt3dXaxis, Point3d pnt3dYaxis) { Matrix3d newMatrix = new Matrix3d(); Vector3d vector3dXaxis = new Vector3d(pnt3dXaxis.X - pnt3dOrigin.X, pnt3dXaxis.Y - pnt3dOrigin.Y, pnt3dXaxis.Z - pnt3dOrigin.Z); Vector3d vector3dYaxis = new Vector3d(pnt3dYaxis.X - pnt3dOrigin.X, pnt3dYaxis.Y - pnt3dOrigin.Y, pnt3dYaxis.Z - pnt3dOrigin.Z); Vector3d vector3dZ = vector3dXaxis.CrossProduct(vector3dYaxis); Vector3d vector3dY = vector3dZ.CrossProduct(vector3dXaxis); Vector3d vector3dPerpY = new Vector3d(vector3dY.X + pnt3dOrigin.X, vector3dY.Y + pnt3dOrigin.Y, vector3dY.Z + pnt3dOrigin.Z); newMatrix = Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, pnt3dOrigin, vector3dXaxis, vector3dPerpY, Vector3d.ZAxis); return(newMatrix); }
GetUcsToWcsOriginMatrix(Point3d wcsBasePt, Database db) { Matrix3d m = GetUcsMatrix(db); Point3d origin = m.CoordinateSystem3d.Origin; origin += wcsBasePt.GetAsVector(); m = Matrix3d.AlignCoordinateSystem(origin, m.CoordinateSystem3d.Xaxis, m.CoordinateSystem3d.Yaxis, m.CoordinateSystem3d.Zaxis, Utils.Ge.kOrigin, Utils.Ge.kXAxis, Utils.Ge.kYAxis, Utils.Ge.kZAxis); return(m); }
private bool IsPointIn(Point3d pt, double tolerateValue, double associateDist) { //先把世界坐标系下的pt转换成mp坐标系下 pt = pt.TransformBy(Matrix3d.AlignCoordinateSystem(this.Part.MovedMPPoint, this.Part.MovedMPXAxis, this.Part.MovedMPYAxis, this.Part.MovedMPZAxis, Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis)); //取有效数字两个,是为了避免精确计算的情况下的误差导致判断错误 double x = System.Math.Round(pt.X, 2); double y = System.Math.Round(pt.Y, 2); double z = System.Math.Round(pt.Z, 2); double zlimitUp = associateDist; if (FaceNumber == 6) { zlimitUp = associateDist + this.Part.Thickness; } double zlimitDown = 0; if (FaceNumber == 6) { zlimitDown = this.Part.Thickness; } //板件是否旋转,判断的区间也不同 if (this.Part.MachinePoint.IsRotated) { if (x >= 0 && x <= this.Part.Width && y >= 0 && y <= this.Part.Length && z >= zlimitDown && z <= zlimitUp) { return(true); } } else { if (x >= 0 && x <= this.Part.Length && y >= 0 && y <= this.Part.Width && z >= zlimitDown && z <= zlimitUp) { return(true); } } return(false); }
public static void SetViewTo(Autodesk.AutoCAD.GraphicsSystem.View view, Database db) { if (_extMax.Equals(Point3d.Origin) && _extMin.Equals(Point3d.Origin)) { // just check we have valid extents if (db.Extmax.X < db.Extmin.X || db.Extmax.Y < db.Extmin.Y || db.Extmax.Z < db.Extmax.Z) { db.Extmin = new Point3d(0, 0, 0); db.Extmax = new Point3d(400, 400, 400); } // get the dwg extents _extMax = db.Extmax; _extMin = db.Extmin; } // now the active viewport info double height = 0.0, width = 0.0, viewTwist = 0.0; Point3d targetView = new Point3d(); Vector3d viewDir = new Vector3d(); GetActiveViewPortInfo(ref height, ref width, ref targetView, ref viewDir, ref viewTwist, true); // from the data returned let's work out the viewmatrix viewDir = viewDir.GetNormal(); Vector3d viewXDir = viewDir.GetPerpendicularVector().GetNormal(); viewXDir = viewXDir.RotateBy(viewTwist, -viewDir); Vector3d viewYDir = viewDir.CrossProduct(viewXDir); Point3d boxCenter = _extMin + 0.5 * (_extMax - _extMin); Matrix3d viewMat; viewMat = Matrix3d.AlignCoordinateSystem(boxCenter, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, boxCenter, viewXDir, viewYDir, viewDir).Inverse(); Extents3d wcsExtents = new Extents3d(_extMin, _extMax); Extents3d viewExtents = wcsExtents; viewExtents.TransformBy(viewMat); double xMax = System.Math.Abs(viewExtents.MaxPoint.X - viewExtents.MinPoint.X); double yMax = System.Math.Abs(viewExtents.MaxPoint.Y - viewExtents.MinPoint.Y); Point3d eye = boxCenter + viewDir; view.SetView(eye, boxCenter, viewYDir, xMax, yMax); view.Invalidate(); view.Update(); }
/// <summary> /// 取得世界坐标系下的点在这个板件的MP坐标系下的坐标 /// </summary> /// <param name="pt"></param> /// <returns></returns> private Point3d getProjectPoint(Point3d pt) { //先把世界坐标系下的pt转换成mp坐标系下 pt = pt.TransformBy(Matrix3d.AlignCoordinateSystem(this.Part.MovedMPPoint, this.Part.MovedMPXAxis, this.Part.MovedMPYAxis, this.Part.MovedMPZAxis, Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis)); //取有效数字两个,是为了避免精确计算的情况下的误差导致判断错误 double x = System.Math.Round(pt.X, 2); double y = System.Math.Round(pt.Y, 2); double z = System.Math.Round(pt.Z, 2); return(new Point3d(x, y, z)); }
public static void ChangeUcs(Point3d aOrigin, Point3d aPointForXAxis) { //Point3d pt1 = new Point3d(10, 10, 0); //Point3d pt2 = new Point3d(50, 50, 0); var pt1 = aOrigin; var pt2 = aPointForXAxis; var ed = Application.DocumentManager.MdiActiveDocument.Editor; var zAxis = ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis; var xAxis = pt1.GetVectorTo(pt2).GetNormal(); var yAxis = zAxis.CrossProduct(xAxis).GetNormal(); var mat = Matrix3d.AlignCoordinateSystem( Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, pt1, xAxis, yAxis, zAxis); ed.CurrentUserCoordinateSystem = mat; }
public static Matrix3d GetTransforMatrixToUcs() { var world = Matrix3d.AlignCoordinateSystem( Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem.CoordinateSystem3d .Origin, Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem.CoordinateSystem3d .Xaxis, Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem.CoordinateSystem3d .Yaxis, Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem.CoordinateSystem3d .Zaxis, Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis); return(world); }
public static CoordinateSystem3d SetUCSToCustom(CoordinateSystem3d FromUcs, CoordinateSystem3d toUcs) { Editor ed = Application.DocumentManager.CurrentDocument.Editor; Matrix3d newMatrix = new Matrix3d(); newMatrix = Matrix3d.AlignCoordinateSystem(FromUcs.Origin, FromUcs.Xaxis, FromUcs.Yaxis, FromUcs.Zaxis, toUcs.Origin, toUcs.Xaxis, toUcs.Yaxis, toUcs.Zaxis); ed.CurrentUserCoordinateSystem = newMatrix; ed.Regen(); return(newMatrix.CoordinateSystem3d); }
public static Point3d ToWCS(this Point3d pUCS) { if (IsUCSInited == false) { UCS = GetUCS(); matrixToUCS = Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, UCS.Origin, UCS.Xaxis, UCS.Yaxis, UCS.Zaxis); IsUCSInited = true; } Point3d pPt3dWCS = pUCS.TransformBy(matrixToUCS); return(pPt3dWCS); }
public override bool WorldDraw(Drawable drawable, WorldDraw wd) { if (wd.RegenAbort || wd.IsDragging) { return(base.WorldDraw(drawable, wd)); } RebarPos pos = drawable as RebarPos; if (pos == null || (pos.IncludeInBOQ && !pos.Detached)) { return(base.WorldDraw(drawable, wd)); } // Get geometry Point3d minpt; Point3d maxpt; pos.TextBox(out minpt, out maxpt); minpt = minpt.DivideBy(pos.Scale); maxpt = maxpt.DivideBy(pos.Scale); using (Solid solid = new Solid()) { solid.SetPointAt(0, new Point3d(minpt.X - 0.15, minpt.Y - 0.15, 0)); solid.SetPointAt(1, new Point3d(maxpt.X + 0.15, minpt.Y - 0.15, 0)); solid.SetPointAt(2, new Point3d(minpt.X - 0.15, maxpt.Y + 0.15, 0)); solid.SetPointAt(3, new Point3d(maxpt.X + 0.15, maxpt.Y + 0.15, 0)); solid.Color = mColor; solid.LayerId = PosUtility.DefpointsLayer; Matrix3d trans = Matrix3d.AlignCoordinateSystem( Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, pos.BasePoint, pos.DirectionVector, pos.UpVector, pos.NormalVector); solid.TransformBy(trans); wd.Geometry.Draw(solid); } // Draw the entity over shading return(base.WorldDraw(drawable, wd)); }
public void CreateUcsOrigin() { Database db = HostApplicationServices.WorkingDatabase; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; PromptPointOptions opt = new PromptPointOptions("指定新原点"); PromptPointResult res = ed.GetPoint(opt); Point3d pt = res.Value; using (Transaction trans = db.TransactionManager.StartTransaction()) { Vector3d xAxis = db.Ucsxdir; Vector3d yAxis = db.Ucsydir; Vector3d zAxis = xAxis.CrossProduct(yAxis); Matrix3d cmt = ed.CurrentUserCoordinateSystem; Point3d newOrg = pt.TransformBy(cmt); Matrix3d mT = Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, newOrg, xAxis, yAxis, zAxis); ed.CurrentUserCoordinateSystem = mT; trans.Commit(); } }
public void CreateUCS() { Database db = HostApplicationServices.WorkingDatabase; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; using (Transaction trans = db.TransactionManager.StartTransaction()) { UcsTable ut = (UcsTable)trans.GetObject(db.UcsTableId, OpenMode.ForWrite); String ucsName = "myUCS"; if (ut.Has(ucsName) == false) { UcsTableRecord utr = new UcsTableRecord(); utr.Name = ucsName; utr.Origin = new Point3d(0, 0, 0); utr.XAxis = new Vector3d(0, 1, 0); utr.YAxis = new Vector3d(-1, 0, 0); Matrix3d mt = Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, utr.Origin, utr.XAxis, utr.YAxis, utr.XAxis.CrossProduct(utr.YAxis)); ed.CurrentUserCoordinateSystem = mt; } trans.Commit(); } }
public void CreateUcsxAxis() { Database db = HostApplicationServices.WorkingDatabase; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; PromptAngleOptions opt = new PromptAngleOptions("指定绕 X 轴的旋转角度"); opt.UseDefaultValue = true; opt.DefaultValue = Math.PI / 2; PromptDoubleResult res = ed.GetAngle(opt); Double ang = res.Value; using (Transaction trans = db.TransactionManager.StartTransaction()) { Vector3d xAxis = db.Ucsxdir; Vector3d yAxis = db.Ucsydir.RotateBy(ang, xAxis); Vector3d zAxis = xAxis.CrossProduct(yAxis); Point3d org = db.Ucsorg; Matrix3d mT = Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, org, xAxis, yAxis, zAxis); ed.CurrentUserCoordinateSystem = mT; trans.Commit(); } }
Polyline MakeFromLine(Line l) { var result = new Polyline(); p1 = l.StartPoint; p2 = l.EndPoint; p1p2 = new Line(p1, p2); p1p2v = p1p2.Delta.MultiplyBy(1 / p1p2.Length); p11 = p1.Add(p1p2v.MultiplyBy(overlength * -1)); p21 = p2.Add(p1p2v.MultiplyBy(overlength)); result.AddVertexAt(0, p11.to2d(), 0, 0, 0); Point2d pt = new Point2d(p1.X * 0.5 + p2.X * 0.5, p1.Y * 0.5 + p2.Y * 0.5); Matrix3d M = Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, new Point3d(pt.X, pt.Y, 0), p1p2v, p1p2v.GetPerpendicularVector(), Vector3d.ZAxis); //переносим и масштабируем символ Polyline bl = DefaultPolyline(); bl.TransformBy(M); M = Matrix3d.Scaling(size, new Point3d(pt.X, pt.Y, 0)); bl.TransformBy(M); //добавляем символ по одной точке в результирующую полилинию в ее конец for (int i = 0; i < bl.NumberOfVertices; i++) { result.AddVertexAt(result.NumberOfVertices, bl.GetPoint2dAt(i), 0, 0, 0); } result.AddVertexAt(result.NumberOfVertices, p21.to2d(), 0, 0, 0); result.SetDatabaseDefaults(); return(result); }