Example #1
0
        public static IgesCircularArc ToIgesCircle(this Entity entity)
        {
            var(center, startAngle, endAngle, color) = entity.MapEntity <(Point, double, double, CadColor?)>(
                aggregate => throw new ArgumentException(nameof(entity)),
                arc => (arc.Center, arc.StartAngle, arc.EndAngle, arc.Color),
                circle => (circle.Center, 0.0, 360.0, circle.Color),
                ellipse => throw new ArgumentException(nameof(entity)),
                image => throw new ArgumentException(nameof(entity)),
                line => throw new ArgumentException(nameof(entity)),
                location => throw new ArgumentException(nameof(entity)),
                polyline => throw new ArgumentException(nameof(entity)),
                spline => throw new ArgumentException(nameof(entity)),
                text => throw new ArgumentException(nameof(entity))
                );

            startAngle *= MathHelper.DegreesToRadians;
            endAngle   *= MathHelper.DegreesToRadians;

            // TODO: if normal isn't z-axis, create a transformation matrix
            var fromUnit   = entity.GetUnitCircleProjection();
            var startPoint = fromUnit.Transform(new Point(Math.Cos(startAngle), Math.Sin(startAngle), 0.0));
            var endPoint   = fromUnit.Transform(new Point(Math.Cos(endAngle), Math.Sin(endAngle), 0.0));
            var result     = new IgesCircularArc()
            {
                PlaneDisplacement = center.Z,
                Center            = new IgesPoint(center.X, center.Y, 0),
                StartPoint        = new IgesPoint(startPoint.X, startPoint.Y, 0),
                EndPoint          = new IgesPoint(endPoint.X, endPoint.Y, 0)
            };

            AssignColor(result, color);
            return(result);
        }
Example #2
0
        public static IgesCircularArc ToIgesCircle(this Entity entity)
        {
            Point    center;
            double   startAngle, endAngle;
            CadColor?color;

            switch (entity.Kind)
            {
            case EntityKind.Arc:
                var arc = (Arc)entity;
                center     = arc.Center;
                startAngle = arc.StartAngle;
                endAngle   = arc.EndAngle;
                color      = arc.Color;
                break;

            case EntityKind.Circle:
                var circle = (Circle)entity;
                center     = circle.Center;
                startAngle = 0.0;
                endAngle   = 360.0;
                color      = circle.Color;
                break;

            default:
                throw new ArgumentException();
            }

            startAngle *= MathHelper.DegreesToRadians;
            endAngle   *= MathHelper.DegreesToRadians;

            // TODO: if normal isn't z-axis, create a transformation matrix
            var fromUnit   = entity.GetUnitCircleProjection();
            var startPoint = fromUnit.Transform(new Point(Math.Cos(startAngle), Math.Sin(startAngle), 0.0));
            var endPoint   = fromUnit.Transform(new Point(Math.Cos(endAngle), Math.Sin(endAngle), 0.0));
            var result     = new IgesCircularArc()
            {
                PlaneDisplacement = center.Z,
                Center            = new IgesPoint(center.X, center.Y, 0),
                StartPoint        = new IgesPoint(startPoint.X, startPoint.Y, 0),
                EndPoint          = new IgesPoint(endPoint.X, endPoint.Y, 0)
            };

            AssignColor(result, color);
            return(result);
        }
Example #3
0
        public void WriteLineWithStructureTest()
        {
            var file   = new IgesFile();
            var circle = new IgesCircularArc()
            {
                StructureEntity = new IgesLine()
            };

            file.Entities.Add(circle);
            VerifyFileContains(file, @"
     110       1       0       0       0                        00000000D      1
     110       0       0       1       0                                D      2
     100       2      -1       0       0                        00000000D      3
     100       0       0       1       0                                D      4
110,0.,0.,0.,0.,0.,0.;                                                 1P      1
100,0.,0.,0.,0.,0.,0.,0.;                                              3P      2
");
        }
Example #4
0
        public static Entity ToArc(this IgesCircularArc arc)
        {
            var center     = TransformPoint(arc, arc.ProperCenter);
            var startPoint = TransformPoint(arc, arc.ProperStartPoint);
            var endPoint   = TransformPoint(arc, arc.ProperEndPoint);

            // all points have the same Z-value, so the normal will be the transformed Z-axis vector
            var igesNormal = TransformPoint(arc, IgesVector.ZAxis);
            var normal     = new Vector(igesNormal.X, igesNormal.Y, igesNormal.Z).Normalize();

            // find radius from start/end points
            var startVector = startPoint - center;
            var endVector   = endPoint - center;
            var startRadius = startVector.Length;
            var endRadius   = endVector.Length;
            // these should be very close, if not identical, but not necessarily
            var radius = (startRadius + endRadius) / 2;

            // if start/end points are the same, it's a circle.  otherwise it's an arc
            if (startPoint.CloseTo(endPoint))
            {
                return(new Circle(center, radius, normal, GetColor(arc), arc));
            }
            else
            {
                // project back to unit circle to find start/end angles
                var primitiveCircle = new PrimitiveEllipse(center, radius, normal);
                var fromUnit        = primitiveCircle.FromUnitCircle;
                Debug.Assert(AreAllValuesValid(fromUnit));
                var toUnit = fromUnit.Inverse();
                Debug.Assert(AreAllValuesValid(toUnit));
                var startUnit  = toUnit.Transform(startPoint);
                var endUnit    = toUnit.Transform(endPoint);
                var startAngle = ((Vector)startUnit).ToAngle();
                var endAngle   = ((Vector)endUnit).ToAngle();
                return(new Arc(center, radius, startAngle, endAngle, normal, GetColor(arc), arc));
            }
        }