// Plane public Plane PlaneToSpeckle(AC.Plane plane) { Vector xAxis = VectorToSpeckle(plane.GetCoordinateSystem().Xaxis); Vector yAxis = VectorToSpeckle(plane.GetCoordinateSystem().Yaxis); var _plane = new Plane(PointToSpeckle(plane.PointOnPlane), VectorToSpeckle(plane.Normal), xAxis, yAxis, ModelUnits); return(_plane); }
private Spiral AlignmentSpiralToSpeckle(CivilDB.AlignmentSubEntitySpiral spiral, CivilDB.Alignment alignment) { var _spiral = new Spiral(); _spiral.startPoint = PointToSpeckle(spiral.StartPoint); _spiral.endPoint = PointToSpeckle(spiral.EndPoint); _spiral.length = spiral.Length; _spiral.pitch = 0; _spiral.spiralType = SpiralTypeToSpeckle(spiral.SpiralDefinition); // get plane var vX = new Vector3d(System.Math.Cos(spiral.StartDirection) + spiral.StartPoint.X, System.Math.Sin(spiral.StartDirection) + spiral.StartPoint.Y, 0); var vY = vX.RotateBy(System.Math.PI / 2, Vector3d.ZAxis); var plane = new Acad.Plane(new Point3d(spiral.RadialPoint.X, spiral.RadialPoint.Y, 0), vX, vY); _spiral.plane = PlaneToSpeckle(plane); // get turns int turnDirection = (spiral.Direction == CivilDB.SpiralDirectionType.DirectionLeft) ? 1 : -1; _spiral.turns = turnDirection * spiral.Delta / (System.Math.PI * 2); // create polyline display, default tessellation length is 1 var tessellation = 1; int spiralSegmentCount = System.Convert.ToInt32(System.Math.Ceiling(spiral.Length / tessellation)); spiralSegmentCount = (spiralSegmentCount < 10) ? 10 : spiralSegmentCount; double spiralSegmentLength = spiral.Length / spiralSegmentCount; List <Point2d> points = new List <Point2d>(); points.Add(spiral.StartPoint); for (int i = 1; i < spiralSegmentCount; i++) { double x = 0; double y = 0; double z = 0; alignment.PointLocation(spiral.StartStation + (i * spiralSegmentLength), 0, tolerance, ref x, ref y, ref z); points.Add(new Point2d(x, y)); } points.Add(spiral.EndPoint); double length = 0; for (int j = 1; j < points.Count; j++) { length += points[j].GetDistanceTo(points[j - 1]); } var poly = new Polyline(); poly.value = PointsToFlatList(points); poly.units = ModelUnits; poly.closed = (spiral.StartPoint != spiral.EndPoint) ? false : true; poly.length = length; _spiral.displayValue = poly; return(_spiral); }
private Arc AlignmentArcToSpeckle(CivilDB.AlignmentSubEntityArc arc) { // calculate midpoint of chord as between start and end point Point2d chordMid = new Point2d((arc.StartPoint.X + arc.EndPoint.X) / 2, (arc.StartPoint.Y + arc.EndPoint.Y) / 2); // calculate sagitta as radius minus distance between arc center and chord midpoint var sagitta = arc.Radius - arc.CenterPoint.GetDistanceTo(chordMid); // get unit vector from arc center to chord mid var midVector = arc.CenterPoint.GetVectorTo(chordMid); var unitMidVector = midVector.DivideBy(midVector.Length); // get midpoint of arc by moving chord mid point the length of the sagitta along mid vector var midPoint = chordMid.Add(unitMidVector.MultiplyBy(sagitta)); // find arc plane (normal is in clockwise dir) var center3 = new Point3d(arc.CenterPoint.X, arc.CenterPoint.Y, 0); Acad.Plane plane = (arc.Clockwise) ? new Acad.Plane(center3, Vector3d.ZAxis.MultiplyBy(-1)) : new Acad.Plane(center3, Vector3d.ZAxis); // calculate start and end angles var startVector = new Vector3d(arc.StartPoint.X - center3.X, arc.StartPoint.Y - center3.Y, 0); var endVector = new Vector3d(arc.EndPoint.X - center3.X, arc.EndPoint.Y - center3.Y, 0); var startAngle = startVector.AngleOnPlane(plane); var endAngle = endVector.AngleOnPlane(plane); // calculate total angle. // TODO: This needs to be improved with more research into autocad .AngleOnPlane() return values (negative angles, etc). var totalAngle = (arc.Clockwise) ? System.Math.Abs(endAngle - startAngle) : System.Math.Abs(endAngle - startAngle); // create arc var _arc = new Arc(PlaneToSpeckle(plane), arc.Radius, startAngle, endAngle, totalAngle, ModelUnits); _arc.startPoint = PointToSpeckle(arc.StartPoint); _arc.endPoint = PointToSpeckle(arc.EndPoint); _arc.midPoint = PointToSpeckle(midPoint); _arc.domain = IntervalToSpeckle(new Acad.Interval(0, 1, tolerance)); _arc.length = arc.Length; return(_arc); }