コード例 #1
0
 private Arc(Circle circle, Coordinate p1, Coordinate p2, bool isClockwise)
 {
     this.p1 = p1;
     this.p2 = p2;
     clockwise = isClockwise;
     p1Angle = circle.GetAngle(p1);
     if (p1.Equals2D(p2))
     {
         p2Angle = TWO_PI + p1Angle;
     }
     else
     {
         p2Angle = circle.GetAngle(p2);
     }
     DetermineArcAngle();
 }
コード例 #2
0
            private double arcAngle; // angle in radians

            internal Arc(Circle circle, Coordinate p1, Coordinate midPt, Coordinate p2)
            {
                this.circle = circle;
                this.p1 = p1;
                this.p2 = p2;
                p1Angle = circle.GetAngle(p1);
                // See if this arc covers the whole circle
                if (p1.Equals2D(p2))
                {
                    p2Angle = TWO_PI + p1Angle;
                    arcAngle = TWO_PI;
                }
                else
                {
                    p2Angle = circle.GetAngle(p2);
                    double midPtAngle = circle.GetAngle(midPt);

                    // determine the direction
                    double ccDegrees = SubtractAngles(p1Angle,
                                                      midPtAngle)
                                       + SubtractAngles(midPtAngle, p2Angle);

                    if (ccDegrees < TWO_PI)
                    {
                        clockwise = false;
                        arcAngle = ccDegrees;
                    }
                    else
                    {
                        clockwise = true;
                        arcAngle = TWO_PI - ccDegrees;
                    }
                }
            }
コード例 #3
0
        /**
         * Given a circle defined by the 3 points, creates a linearized
         * interpolation of the circle starting and ending on the first coordinate.
         * This method uses a tolerence value of 1/100 of the length of the radius.
         *
         * @param x1
         *            x coordinate of point 1
         * @param y1
         *            y coordinate of point 1
         * @param x2
         *            x coordinate of point 2
         * @param y2
         *            y coordinate of point 2
         * @param x3
         *            x coordinate of point 3
         * @param y3
         *            y coordinate of point 3
         * @return an ordered list of Coordinates representing a series of chords
         *         approximating the arc.
         */

        public static Coordinate[] LinearizeCircle(
            double x1, double y1,
            double x2, double y2,
            double x3, double y3)
        {
            Coordinate p1 = new Coordinate(x1, y1);
            Coordinate p2 = new Coordinate(x2, y2);
            Coordinate p3 = new Coordinate(x3, y3);
            Circle c = new Circle(p1, p2, p3);
            double tolerence = 0.01 * c.Radius;
            return c.LinearizeArc(p1, p2, p1, tolerence);
        }
コード例 #4
0
 public bool Equals(Circle obj)
 {
     if (ReferenceEquals(null, obj))
     {
         return false;
     }
     if (ReferenceEquals(this, obj))
     {
         return true;
     }
     if (obj.radius != radius)
     {
         return false;
     }
     if (center != null
             ? !center.Equals2D(obj.center)
             : obj.center != null)
     {
         return false;
     }
     return true;
 }
コード例 #5
0
        /**
         * Linearizes arcs and circles.
         *
         * @param arcOrdinates
         *            arc or circle coordinates
         * @param dim
         *            coordinate dimension
         * @param lrs
         *            whether this is an lrs geometry
         * @param entireCirlce
         *            whether the whole arc should be linearized
         * @return linearized interpolation of arcs or circle
         */
        private Coordinate[] Linearize(double[] arcOrdinates, int dim, bool lrs, bool entireCirlce)
        {
            Coordinate[] linearizedCoords = new Coordinate[0];
            // CoordDim is the dimension that includes only non-measure (X,Y,Z)
            // ordinates in its value
            int coordDim = lrs ? dim - 1 : dim;

            // this only works with 2-Dimensional geometries, since we use
            // JGeometry linearization;
            if (coordDim != 2)
            {
                throw new ArgumentException("Can only linearize 2D arc segments, but geometry is " + dim + "D.");
            }
            int numOrd = dim;

            while (numOrd < arcOrdinates.Length)
            {
                numOrd = numOrd - dim;
                double x1 = arcOrdinates[numOrd++];
                double y1 = arcOrdinates[numOrd++];
                double m1 = lrs ? arcOrdinates[numOrd++] : Double.NaN;
                double x2 = arcOrdinates[numOrd++];
                double y2 = arcOrdinates[numOrd++];
                double m2 = lrs ? arcOrdinates[numOrd++] : Double.NaN;
                double x3 = arcOrdinates[numOrd++];
                double y3 = arcOrdinates[numOrd++];
                double m3 = lrs ? arcOrdinates[numOrd++] : Double.NaN;

                Coordinate[] coords;
                if (entireCirlce)
                {
                    coords = Circle.LinearizeCircle(x1, y1, x2, y2, x3, y3);
                }
                else
                {
                    coords = Circle.LinearizeArc(x1, y1, x2, y2, x3, y3);
                }

                // if this is an LRS geometry, fill the measure values into
                // the linearized array
                if (lrs)
                {
                    Coordinate[] mcoord    = new Coordinate[coords.Length];
                    int          lastIndex = coords.Length - 1;
                    mcoord[0]         = MCoordinate.Create2dWithMeasure(x1, y1, m1);
                    mcoord[lastIndex] = MCoordinate.Create2dWithMeasure(x3, y3, m3);
                    // convert the middle coordinates to MCoordinate
                    for (int i = 1; i < lastIndex; i++)
                    {
                        mcoord[i] = MCoordinate.ConvertCoordinate(coords[i]);
                        // if we happen to split on the middle measure, then
                        // assign it
                        if (mcoord[i].X == x2 && mcoord[i].Y == y2)
                        {
                            ((MCoordinate)mcoord[i]).M = m2;
                        }
                    }
                    coords = mcoord;
                }

                // if this is not the first arcsegment, the first linearized
                // point is already in linearizedArc, so disregard this.
                int resultBegin = 1;
                if (linearizedCoords.Length == 0)
                {
                    resultBegin = 0;
                }

                int          destPos   = linearizedCoords.Length;
                Coordinate[] tmpCoords = new Coordinate[linearizedCoords.Length + coords.Length - resultBegin];
                Array.Copy(linearizedCoords, 0, tmpCoords, 0, linearizedCoords.Length);
                Array.Copy(coords, resultBegin, tmpCoords, destPos, coords.Length - resultBegin);

                linearizedCoords = tmpCoords;
            }
            return(linearizedCoords);
        }