public static double CalculateBulge(Point3d ptStart, Point3d corner, Point3d ptEnd) { Line line = new Line(ptStart, ptEnd); Point3d center = new Point3d(); Circle cir = new Circle(); double p = (line.Length + ptStart.DistanceTo(corner) + ptEnd.DistanceTo(corner)) / 2; double S = Math.Sqrt((p - line.Length) * (p - ptStart.DistanceTo(corner)) * (p - ptEnd.DistanceTo(corner)) * p); cir.Radius = (line.Length * ptStart.DistanceTo(corner) * ptEnd.DistanceTo(corner)) / (4 * S); //Find Center // midle line Point3d mid = new Point3d((ptEnd.X + ptStart.X) / 2, (ptEnd.Y + ptStart.Y) / 2, (ptEnd.Z + ptStart.Z) / 2); Xline xline1 = new Xline(); xline1.BasePoint = mid; xline1.UnitDir = (ptStart - ptEnd).GetPerpendicularVector(); Point3d mid2 = new Point3d((ptEnd.X + corner.X) / 2, (ptEnd.Y + corner.Y) / 2, (ptEnd.Z + corner.Z) / 2); Xline xline2 = new Xline(); xline2.BasePoint = mid2; xline2.UnitDir = (corner - ptEnd).GetPerpendicularVector(); Point3dCollection pts = new Point3dCollection(); xline2.IntersectWith(xline1, Intersect.ExtendArgument, pts, IntPtr.Zero, IntPtr.Zero); if (pts.Count == 0) { return(0); } cir.Center = pts[0]; center = cir.Center; Vector3d v1 = ptStart - cir.Center; Vector3d v2 = corner - cir.Center; double angle = v1.GetAngleTo(v2); double bul = Math.Tan(angle / 4); if (Clockwise(ptStart, corner, ptEnd)) { bul = -1 * bul; } else { } return(bul); }
public static void CreateStairFrom3Point(Point3d pt1, Point3d pt2, Point3d pt3, double stairWidth, string Layer) { Line l12 = new Line(pt1, pt2); Point3d ptonL12 = l12.GetClosestPointTo(pt3, false); Xline xl1 = new Xline(); xl1.BasePoint = pt1; xl1.UnitDir = pt3 - ptonL12; Xline xl3 = new Xline(); xl3.BasePoint = pt3; xl3.UnitDir = pt1 - pt2; Point3dCollection pts3 = new Point3dCollection(); Point3dCollection pts4 = new Point3dCollection(); xl1.IntersectWith(xl3, Intersect.OnBothOperands, pts3, IntPtr.Zero, IntPtr.Zero); Point3d p3 = new Point3d(); Point3d p4 = new Point3d(); if (pts3.Count > 0) { p3 = pts3[0]; } else { return; } Xline xl2 = new Xline(); xl2.BasePoint = pt2; xl2.UnitDir = pt3 - ptonL12; xl2.IntersectWith(xl3, Intersect.OnBothOperands, pts4, IntPtr.Zero, IntPtr.Zero); if (pts4.Count > 0) { p4 = pts4[0]; } else { return; } Point3dCollection verx = new Point3dCollection(); verx.Add(pt1); verx.Add(pt2); verx.Add(p4); verx.Add(p3); Polyline3d pl = new Polyline3d(Poly3dType.SimplePoly, verx, true); pl.Layer = Layer; ArxHelper.AppendEntity(pl); for (int i = 1; i < p4.DistanceTo(pt2) / stairWidth; i++) { Point3d p1 = pt1 + (p4 - pt2).GetNormal() * i * stairWidth; Point3d p2 = pt2 + (p4 - pt2).GetNormal() * i * stairWidth; Line line = new Line(p1, p2); line.Layer = Layer; ArxHelper.AppendEntity(line); } Point3d mid1 = new Point3d((pt1.X + pt2.X) / 2, (pt1.Y + pt2.Y) / 2, (pt1.Z + pt2.Z) / 2); Point3d mid2 = new Point3d((p3.X + p4.X) / 2, (p3.Y + p4.Y) / 2, (p3.Z + p4.Z) / 2); if (mid1.Z < mid2.Z) { drawArrow(mid1, mid2, pt1 - pt2, pt1.DistanceTo(pt2), stairWidth); } else { drawArrow(mid2, mid1, pt1 - pt2, pt1.DistanceTo(pt2), stairWidth); } }
public static bool BuilPolyline(Point3d pt1, Point3d pt2, Point3d closerPoint, Point3d CloserPointOnLine, Point3d FurtherPoint, Point3d FurthurPointOnLine) { //Build Longer line Point3d pt7 = pt1 + (CloserPointOnLine - closerPoint).GetNormal() * 3; Point3d pt8 = pt2 + (CloserPointOnLine - closerPoint).GetNormal() * 3; Point3dCollection verx = new Point3dCollection(); verx.Add(pt7); verx.Add(pt1); verx.Add(pt2); verx.Add(pt8); Polyline3d longer = new Polyline3d(Poly3dType.SimplePoly, verx, false); //Build Shorter Line Xline xline = new Xline(); xline.BasePoint = closerPoint; xline.UnitDir = pt1 - pt2; Line l48 = new Line(FurthurPointOnLine, FurtherPoint); Point3dCollection intersec = new Point3dCollection(); xline.IntersectWith(l48, Intersect.OnBothOperands, intersec, IntPtr.Zero, IntPtr.Zero); if (intersec.Count < 1) { return(false); } Xline xl1 = new Xline(); if (pt1.DistanceTo(FurtherPoint) < pt2.DistanceTo(FurtherPoint)) { xl1.BasePoint = pt1; } else { xl1.BasePoint = pt2; } xl1.UnitDir = pt7 - pt1; Xline xl2 = new Xline(); xl2.BasePoint = FurtherPoint; xl2.UnitDir = pt2 - pt1; Point3dCollection intersec2 = new Point3dCollection(); xl1.IntersectWith(xl2, Intersect.OnBothOperands, intersec2, IntPtr.Zero, IntPtr.Zero); Point3dCollection verx2 = new Point3dCollection(); if (intersec2.Count < 1) { return(false); } ArxHelper.AppendEntity(longer); if (pt1.DistanceTo(FurtherPoint) < pt2.DistanceTo(FurtherPoint)) { verx2.Add(pt1); verx2.Add(intersec2[0]); verx2.Add(FurtherPoint); verx2.Add(intersec[0]); verx2.Add(closerPoint); verx2.Add(CloserPointOnLine); Polyline3d pl = new Polyline3d(Poly3dType.SimplePoly, verx2, false); ArxHelper.AppendEntity(pl); return(true); } else { verx2.Add(pt2); verx2.Add(intersec2[0]); verx2.Add(FurtherPoint); verx2.Add(intersec[0]); verx2.Add(closerPoint); verx2.Add(CloserPointOnLine); Polyline3d pl = new Polyline3d(Poly3dType.SimplePoly, verx2, false); ArxHelper.AppendEntity(pl); return(true); } }