Пример #1
0
        public ArcInterpolation(Point3D origin, float radius, Point3D end, bool clockwise)
        {
            _origin    = origin;
            _end       = end;
            _clockwise = clockwise;
            _radius    = radius;
            _plane     = GetPlane(origin, end);
            _centers   = CalculateCenters(origin, end, radius, _plane);
            _offset    = RoundOffsets(CalculateOffsets(origin, _centers));
            _angles    = RoundAngles(CalculateAngles(origin, end, _centers, _plane));

            if (!_clockwise && _angles.StartingAngle >= _angles.EndAngle)
            {
                _angles.EndAngle += 360;
            }
        }
Пример #2
0
        public ArcInterpolation(Point3D origin, ArcCenters centers, Point3D end, bool clockwise)
        {
            _origin    = origin;
            _centers   = centers ?? throw new ArgumentNullException(paramName: nameof(centers));
            _end       = end;
            _clockwise = clockwise;

            _plane  = GetPlane();
            _radius = CalculateRadius(_plane);
            _offset = CalculateOffsets(origin, centers);
            _angles = CalculateAngles(origin, end, centers, _plane);

            if (!_clockwise && _angles.StartingAngle >= _angles.EndAngle)
            {
                _angles.EndAngle += 360;
            }
        }
Пример #3
0
        private ArcAngles CalculateAngles(Point3D start, Point3D end, ArcCenters centers, Plane plane)
        {
            ArcAngles result;
            double    catetA, catetB, angleStart, angleEnd;

            switch (plane)
            {
            case Plane.XY:
                catetA     = start.X - (centers.I.Value + start.X);
                catetB     = start.Y - (centers.J.Value + start.Y);
                angleStart = Math.Atan2(catetB, catetA) * (180 / Math.PI);

                catetA   = end.X - (centers.I.Value + start.X);
                catetB   = end.Y - (centers.J.Value + start.Y);
                angleEnd = Math.Atan2(catetB, catetA) * (180 / Math.PI);
                break;

            case Plane.XZ:
                catetA     = start.X - (centers.I.Value + start.X);
                catetB     = start.Z - (centers.K.Value + start.Z);
                angleStart = Math.Atan2(catetB, catetA) * (180 / Math.PI);

                catetA   = end.X - (centers.I.Value + start.X);
                catetB   = end.Z - (centers.K.Value + start.Z);
                angleEnd = Math.Atan2(catetB, catetA) * (180 / Math.PI);
                break;

            case Plane.YZ:
                catetA     = start.Y - (centers.J.Value + start.Y);
                catetB     = start.Z - (centers.K.Value + start.Z);
                angleStart = Math.Atan2(catetB, catetA) * (180 / Math.PI);

                catetA   = end.Y - (centers.J.Value + start.Y);
                catetB   = end.Z - (centers.K.Value + start.Z);
                angleEnd = Math.Atan2(catetB, catetA) * (180 / Math.PI);
                break;

            case Plane.Unknown:
            default:
                throw new InvalidOperationException(ResourcesStrings.UnknownPlane);
            }


            result = new ArcAngles(angleStart, angleEnd);
            return(result);
        }
Пример #4
0
        private ArcCenters CalculateCenters(Point3D origin, Point3D end, float radius, Plane plane)
        {
            ArcCenters result;
            double     a1, a2, b1, b2;

            switch (plane)
            {
            case Plane.XY:
                a1 = origin.X;
                a2 = end.X;
                b1 = origin.Y;
                b2 = end.Y;
                var ij = CalculateCentersInternal(ref a1, ref a2, ref b1, ref b2, radius);
                result = new ArcCenters {
                    I = ij.Item1, J = ij.Item2
                };
                break;

            case Plane.XZ:
                a1 = origin.X;
                a2 = end.X;
                b1 = origin.Z;
                b2 = end.Z;
                var ik = CalculateCentersInternal(ref a1, ref a2, ref b1, ref b2, radius);
                result = new ArcCenters {
                    I = ik.Item1, K = ik.Item2
                };
                break;

            case Plane.YZ:
                a1 = origin.Y;
                a2 = end.Y;
                b1 = origin.Z;
                b2 = end.Z;
                var jk = CalculateCentersInternal(ref a1, ref a2, ref b1, ref b2, radius);
                result = new ArcCenters {
                    J = jk.Item1, K = jk.Item2
                };
                break;

            default:
            case Plane.Unknown:
                throw new InvalidOperationException(ResourcesStrings.UnknownPlane);
            }
            return(result);
        }
Пример #5
0
        private Point3D CalculateOffsets(Point3D start, ArcCenters centers)
        {
            Point3D result = default;

            if (centers.I.HasValue)
            {
                result.X = centers.I.Value + start.X;
            }
            if (centers.J.HasValue)
            {
                result.Y = centers.J.Value + start.Y;
            }
            if (centers.K.HasValue)
            {
                result.Z = centers.K.Value + start.Z;
            }
            return(result);
        }