/// <summary> /// interpolation Qbezier /// </summary> public static LObject QBezierByStep(Point StartPoint, Point ControlPoint, Point EndPoint, double CRS) { LPoint3D LastPoint = new LPoint3D(StartPoint); double Lenth = 0; for (int t = 1; t < 100; t++) { LPoint3D tempPoint = GetPoint((double)t / 99); Lenth += LPoint3D.Lenth2D(LastPoint, tempPoint); LastPoint = tempPoint; } int CountStep = (int)(Lenth / (CRS)) >= 2 ? (int)(Lenth / CRS) : 2; LObject tempObj = new LObject(); for (int t = 0; t < CountStep; t++) { tempObj.Add(GetPoint((double)t / (CountStep - 1))); } return(tempObj); LPoint3D GetPoint(double t) { return(new LPoint3D( (1 - t) * (1 - t) * StartPoint.X + 2 * (1 - t) * t * ControlPoint.X + t * t * EndPoint.X, (1 - t) * (1 - t) * StartPoint.Y + 2 * (1 - t) * t * ControlPoint.Y + t * t * EndPoint.Y)); } }
/// <summary> /// Convert inner object in LPoint3D's /// </summary> public async static Task <LObjectList> CalcContour(CadObject cadObject) { LObjectList PathList = new LObjectList(); switch ((object)cadObject) { case NurbsShape nurbsShape: LObject NurbsObject = new LObject() { MeshType = cadObject.MeshType }; foreach (Point nurbsPoint in nurbsShape.BSplinePoints(cadObject.ProjectionSetting.PointStep.MX)) { NurbsObject.Add(new LPoint3D(nurbsPoint)); } NurbsObject.ProjectionSetting = cadObject.ProjectionSetting; PathList.Add(NurbsObject); break; case CadGeometry cadContour: foreach (PointsElement pntobj in cadContour.GCObject.GetPointCollection(cadContour.TransformGroup, cadObject.ProjectionSetting.PointStep.MX, cadObject.ProjectionSetting.RadiusEdge)) { PathList.Add(new LObject(pntobj.GetPoints3D)); } break; default: break; } return(PathList); }
/// <summary> /// interpolation bezier /// </summary> public static LObject BezieByStep(Point point0, Point point1, Point point2, Point point3, double CRS) { double Lenth = 0; LPoint3D LastPoint = new LPoint3D(point1); for (int t = 0; t < 100; t++) { LPoint3D tempPoint = GetPoint((double)t / 99); Lenth += LPoint3D.Lenth2D(LastPoint, tempPoint); LastPoint = tempPoint; } LObject tempObj = new LObject(); int CountStep = (int)(Lenth / CRS) >= 2 ? (int)(Lenth / CRS) : 2; for (int t = 0; t < CountStep; t++) { tempObj.Add(GetPoint((double)t / (CountStep - 1))); } return(tempObj); LPoint3D GetPoint(double t) { return(new LPoint3D( ((1 - t) * (1 - t) * (1 - t)) * point0.X + 3 * ((1 - t) * (1 - t)) * t * point1.X + 3 * (1 - t) * (t * t) * point2.X + (t * t * t) * point3.X, ((1 - t) * (1 - t) * (1 - t)) * point0.Y + 3 * ((1 - t) * (1 - t)) * t * point1.Y + 3 * (1 - t) * (t * t) * point2.Y + (t * t * t) * point3.Y, (byte)1)); } }
/// <summary> /// Get point from inner object /// </summary> /// <param name="cadObject">inner object</param> /// <returns>Object collection</returns> public static LObjectList GetPoint(CadObject cadObject, bool InGroup) { LObjectList lObjectList = new LObjectList(); switch (cadObject) { case CadAnchor cadDot: if (cadObject.DataContext is MonchaDeviceMesh deviceMesh) { if (MonchaDeviceMesh.ClbrForm == CalibrationForm.cl_Dot) { lObjectList.Add(new LObject() { Points = new List <LPoint3D>() { cadDot.GetPoint.GetMLpoint3D }, MeshType = cadDot.MeshType }); } if (MonchaDeviceMesh.ClbrForm == CalibrationForm.cl_Rect) { lObjectList.AddRange(CalibrationRect(deviceMesh, cadDot.GetPoint, cadDot.MeshType)); } if (MonchaDeviceMesh.ClbrForm == CalibrationForm.cl_miniRect) { lObjectList.AddRange(CalibrationMiniRect(deviceMesh, cadDot.GetPoint, cadDot.MeshType)); } if (MonchaDeviceMesh.ClbrForm == CalibrationForm.cl_Cross) { lObjectList.AddRange(CalibrationCross(deviceMesh, cadDot.GetPoint, cadDot.MeshType)); } if (MonchaDeviceMesh.ClbrForm == CalibrationForm.cl_HLine) { lObjectList.AddRange(CalibrationLineH(deviceMesh, cadDot.GetPoint, cadDot.MeshType)); } if (MonchaDeviceMesh.ClbrForm == CalibrationForm.cl_WLine) { lObjectList.AddRange(CalibrationLineW(deviceMesh, cadDot.GetPoint, cadDot.MeshType)); } } else { lObjectList.Add(new LObject() { Points = new List <LPoint3D>() { cadDot.GetPoint.GetMLpoint3D }, MeshType = cadDot.MeshType }); } break; case CadGeometry cadGeometry: lObjectList.AddRange(cadGeometry.GetTransformPoint()); break; case CadLine cadLine: lObjectList.Add(new LObject() { Points = new List <LPoint3D>() { cadLine.P1, cadLine.P2 }, ProjectionSetting = cadLine.ProjectionSetting, MeshType = cadLine.MeshType }); break; case CadRectangle cadRectangle: lObjectList.Add(new LObject() { Points = new List <LPoint3D>() { cadRectangle.LRect.P1, new LPoint3D(cadRectangle.LRect.P2.MX, cadRectangle.LRect.P1.MY), cadRectangle.LRect.P2, new LPoint3D(cadRectangle.LRect.P1.MX, cadRectangle.LRect.P2.MY), }, ProjectionSetting = cadRectangle.ProjectionSetting, Closed = true, MeshType = cadRectangle.MeshType }); break; case CadObjectsGroup cadObjectsGroup: foreach (CadObject obj in cadObjectsGroup) { obj.ProjectionSetting = cadObjectsGroup.ProjectionSetting != MonchaHub.ProjectionSetting ? cadObjectsGroup.ProjectionSetting : null; lObjectList.AddRange(GetPoint(obj, true)); } break; } return(lObjectList); LObjectList CalibrationCross(MonchaDeviceMesh monchaDeviceMesh, LPoint3D lPoint3D, MeshType meshType) { Tuple <int, int> tuple = monchaDeviceMesh.CoordinatesOf(lPoint3D); int height = monchaDeviceMesh.GetLength(0) - 1; int width = monchaDeviceMesh.GetLength(1) - 1; //Vertical LObject Line1 = new LObject() { MeshType = meshType }; for (int i = 0; i <= width; i += 1) { Line1.Add(monchaDeviceMesh[tuple.Item2, i].GetMLpoint3D); } //Vertical //Horizontal LObject Line2 = new LObject() { MeshType = meshType }; for (int i = 0; i <= height; i += 1) { Line2.Add(monchaDeviceMesh[i, tuple.Item1].GetMLpoint3D); } return(new LObjectList() { Line2, Line1 }); } LObjectList CalibrationRect(MonchaDeviceMesh monchaDeviceMesh, LPoint3D lPoint3D, MeshType meshType) { Tuple <int, int> tuple = monchaDeviceMesh.CoordinatesOf(lPoint3D); int height = monchaDeviceMesh.GetLength(0) - 1; int width = monchaDeviceMesh.GetLength(1) - 1; //Vertical LObject Line1H = GetLine(tuple.Item1, tuple.Item2, true); //Horizontal LObject Line1W = GetLine(tuple.Item1, height - tuple.Item2, false); //Vertical LObject Line2H = GetLine(width - tuple.Item1, height - tuple.Item2, true); //Horizontal LObject Line2W = GetLine(width - tuple.Item1, tuple.Item2, false); return(new LObjectList() { Line1H, Line1W, Line2H, Line2W }); LObject GetLine(int xpos, int ypos, bool Vertical) { LObject Line = new LObject() { MeshType = meshType }; if (Vertical == true) { int ypos2 = height - ypos; int delta = ypos > ypos2 ? -1 : 1; for (int i = 0; i <= Math.Abs(ypos2 - ypos); i += 1) { Line.Add(monchaDeviceMesh[ypos + (i * delta), xpos].GetMLpoint3D); } } else { int xpos2 = width - xpos; int delta = xpos > xpos2 ? -1 : 1; for (int i = 0; i <= Math.Abs(xpos2 - xpos); i += 1) { Line.Add(monchaDeviceMesh[ypos, xpos + (i * delta)].GetMLpoint3D); } } return(Line); } } LObjectList CalibrationMiniRect(MonchaDeviceMesh monchaDeviceMesh, LPoint3D lPoint3D, MeshType meshType) { Tuple <int, int> tuple = monchaDeviceMesh.CoordinatesOf(lPoint3D); int height = monchaDeviceMesh.GetLength(0) - 1; int width = monchaDeviceMesh.GetLength(1) - 1; return(new LObjectList() { new LObject() { Points = new List <LPoint3D>() { monchaDeviceMesh[tuple.Item2, tuple.Item1].GetMLpoint3D, monchaDeviceMesh[tuple.Item2, tuple.Item1 + (tuple.Item1 < width ? 1 : -1)].GetMLpoint3D, monchaDeviceMesh[tuple.Item2 + (tuple.Item2 < height ? 1 : -1), tuple.Item1 + (tuple.Item1 < width ? 1 : -1)].GetMLpoint3D, monchaDeviceMesh[tuple.Item2 + (tuple.Item2 < height ? 1 : -1), tuple.Item1].GetMLpoint3D }, Closed = true, MeshType = meshType } }); } LObjectList CalibrationLineH(MonchaDeviceMesh monchaDeviceMesh, LPoint3D lPoint3D, MeshType meshType) { Tuple <int, int> tuple = monchaDeviceMesh.CoordinatesOf(lPoint3D); int height = monchaDeviceMesh.GetLength(0) - 1; int width = monchaDeviceMesh.GetLength(1) - 1; //Height LObject Line = new LObject() { MeshType = meshType }; for (int i = 0; i <= height; i += 1) { Line.Add(monchaDeviceMesh[i, tuple.Item1].GetMLpoint3D); } return(new LObjectList() { Line, }); } LObjectList CalibrationLineW(MonchaDeviceMesh monchaDeviceMesh, LPoint3D lPoint3D, MeshType meshType) { Tuple <int, int> tuple = monchaDeviceMesh.CoordinatesOf(lPoint3D); int height = monchaDeviceMesh.GetLength(0) - 1; int width = monchaDeviceMesh.GetLength(1) - 1; //width LObject Line = new LObject() { MeshType = meshType }; for (int i = 0; i <= width; i += 1) { Line.Add(monchaDeviceMesh[tuple.Item2, i].GetMLpoint3D); } return(new LObjectList() { Line }); } }