Revision 42356

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.api/src/main/java/org/gvsig/fmap/geom/primitive/Arc.java
24 24

  
25 25
package org.gvsig.fmap.geom.primitive;
26 26

  
27
import org.gvsig.fmap.geom.operation.GeometryOperationException;
28
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
29

  
27 30
/**
28 31
 * <p>
29
 * This interface is equivalent to the GM_Arc specified in
30
 * <a href="http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=26012">ISO 19107</a>.
31
 * A Arc is defined by 3 points, and consists of the arc of the circle determined by the 3 points,
32
 * starting at the first, passing through the second and terminating at the third.
33
 * If the 3 points are co-linear, then the arc shall be a 3-point line string, and will
34
 * not be able to return values for center, radius, start angle and end angle.
32
 * This interface is equivalent to the GM_Arc specified in <a href=
33
 * "http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=26012"
34
 * >ISO 19107</a>. A Arc is defined by 3 points, and consists of the arc of the
35
 * circle determined by the 3 points, starting at the first, passing through the
36
 * second and terminating at the third. If the 3 points are co-linear, then the
37
 * arc shall be a 3-point line string, and will not be able to return values for
38
 * center, radius, start angle and end angle.
35 39
 * </p>
36
 * @see <a href="http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=26012">ISO 19107</a>
40
 *
41
 * @see <a
42
 *      href="http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=26012">ISO
43
 *      19107</a>
37 44
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
38 45
 */
39 46
public interface Arc extends Curve {
40 47

  
41
	/**
42
	 * Sets the three points to define an arc.
43
	 * These are three ordered points that belong to the arc
44
	 * (none of them is the center of the ellipse/circle). Therefore
45
	 * they must not be aligned.
46
	 *
47
	 * @param startPoint
48
	 * The start point of an arc.
48
    /**
49
     * Sets the three points to define an arc.
50
     * These are three ordered points that belong to the arc
51
     * (none of them is the center of the ellipse/circle). Therefore
52
     * they must not be aligned.
53
     *
54
     * @param startPoint
55
     *            The start point of an arc.
49 56
     * @param midPoint
50
     * The middle point of an arc.
51
	 * @param endPoint
52
	 * The end point of an arc.
53
	 * @exception IllegalArgumentException if the three points are aligned or
54
	 * there is a repeated point.
55
	 *
56
	 */
57
	void setPoints(Point startPoint, Point midPoint, Point endPoint);
57
     *            The middle point of an arc.
58
     * @param endPoint
59
     *            The end point of an arc.
60
     * @exception IllegalArgumentException
61
     *                if the three points are aligned or
62
     *                there is a repeated point.
63
     *
64
     */
65
    void setPoints(Point startPoint, Point midPoint, Point endPoint);
58 66

  
59
	/**
60
	 * Sets the values to define an arc.
61
	 * @param center The center of the arc.
62
	 * @param radius The radius.
63
	 * @param startAngle The start angle of the arc (in radians)
64
	 * @param angleExt The angular extent of the arc (in radians).
65
	 *
66
	 * The sign convention is:
67
	 *
68
	 * startAngle = 0 is "3 o'clock";
69
	 * startAngle = (PI / 3) is "1 o'clock";
70
     * angleExt > 0 means "advancing clockwise";
71
     * angleExt < 0 means "advancing counterclockwise".
72
	 */
73
	void setPoints (Point center, double radius, double startAngle, double angleExt);
67
    /**
68
     * Sets the values to define an arc.
69
     *
70
     * @param center
71
     *            The center of the arc.
72
     * @param radius
73
     *            The radius.
74
     * @param startAngle
75
     *            The start angle of the arc (in radians)
76
     * @param angleExt
77
     *            The angular extent of the arc (in radians).
78
     *
79
     *            The sign convention is:
80
     *
81
     *            startAngle = 0 is "3 o'clock";
82
     *            startAngle = (PI / 3) is "1 o'clock";
83
     *            angleExt > 0 means "advancing clockwise";
84
     *            angleExt < 0 means "advancing counterclockwise".
85
     */
86
    void setPoints(Point center, double radius, double startAngle, double angleExt);
74 87

  
75 88
    /**
76 89
     * Sets the values to define an arc.
77
     * @param center The center of the arc.
78
     * @param radius The radius.
79
     * @param startAngle The start angle of the arc (in radians)
80
     * @param angleExt The angular extent of the arc (in radians).
81 90
     *
82
     * The sign convention is:
91
     * @param center
92
     *            The center of the arc.
93
     * @param radius
94
     *            The radius.
95
     * @param startAngle
96
     *            The start angle of the arc (in radians)
97
     * @param angleExt
98
     *            The angular extent of the arc (in radians).
83 99
     *
84
     * startAngle = 0 is "3 o'clock";
85
     * startAngle = (PI / 3) is "1 o'clock";
86
     * angleExt > 0 means "advancing clockwise";
87
     * angleExt < 0 means "advancing counterclockwise".
100
     *            The sign convention is:
101
     *
102
     *            startAngle = 0 is "3 o'clock";
103
     *            startAngle = (PI / 3) is "1 o'clock";
104
     *            angleExt > 0 means "advancing clockwise";
105
     *            angleExt < 0 means "advancing counterclockwise".
88 106
     */
89
    void setPointsStartExt (Point center, double radius, double startAngle, double angleExt);
107
    void setPointsStartExt(Point center, double radius, double startAngle, double angleExt);
90 108

  
91 109
    /**
92 110
     * Sets the values to define an arc. The arc will go from
......
94 112
     * normalized to ]-PI, PI] (-PI excluded) before creating
95 113
     * the arc.
96 114
     *
97
     * @param center The center of the arc.
98
     * @param radius The radius.
99
     * @param startAngle The start angle of the arc (in radians)
100
     * @param endAngle The end angle of the arc (in radians).
115
     * @param center
116
     *            The center of the arc.
117
     * @param radius
118
     *            The radius.
119
     * @param startAngle
120
     *            The start angle of the arc (in radians)
121
     * @param endAngle
122
     *            The end angle of the arc (in radians).
101 123
     *
102 124
     */
103
    void setPointsStartEnd (Point center, double radius, double startAngle, double endAngle );
125
    void setPointsStartEnd(Point center, double radius, double startAngle, double endAngle);
104 126

  
105
	/**
106
	 * Return the first point that has been used to create the arc.
107
	 * @return
108
	 * The first point of the arc.
109
	 */
110
	Point getInitPoint();
127
    /**
128
     * Return the first point that has been used to create the arc.
129
     *
130
     * @return
131
     *         The first point of the arc.
132
     */
133
    Point getInitPoint();
111 134

  
112
	/**
113
	 * Return the end point that has been used to create the arc.
114
	 * @return
115
	 * The end point of the arc.
116
	 */
117
	Point getEndPoint();
135
    /**
136
     * Return the end point that has been used to create the arc.
137
     *
138
     * @return
139
     *         The end point of the arc.
140
     */
141
    Point getEndPoint();
118 142

  
119
	/**
120
	 * Return the center of the arc, that is, the center of the ellipse/circle
121
	 * in which the arc is based.
122
	 *
123
	 * @return The center of the arc.
124
	 */
125
	Point getCenterPoint();
143
    /**
144
     * Return the center of the arc, that is, the center of the ellipse/circle
145
     * in which the arc is based.
146
     *
147
     * @return The center of the arc.
148
     */
149
    Point getCenterPoint();
126 150

  
127
	   /**
151
    /**
128 152
     * Return the middle point of the arc.
129 153
     *
130 154
     * @return The middle point of the arc.
131 155
     */
132 156
    Point getMiddlePoint();
133 157

  
158
    /**
159
     * Returns the counterclockwise angle formed by the horizontal line passing
160
     * through the center, the center itself and the starting point.
161
     *
162
     * @return
163
     * @throws GeometryOperationNotSupportedException
164
     * @throws GeometryOperationException
165
     */
166
    double getStartAngle() throws GeometryOperationNotSupportedException, GeometryOperationException;
134 167

  
168
    /**
169
     * Returns the counterclockwise angle formed by the horizontal line passing
170
     * through the center, the center itself and the ending point.
171
     *
172
     * @return
173
     * @throws GeometryOperationNotSupportedException
174
     * @throws GeometryOperationException
175
     */
176
    double getEndAngle() throws GeometryOperationNotSupportedException, GeometryOperationException;
177

  
135 178
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.jts/src/main/java/org/gvsig/fmap/geom/jts/primitive/curve/arc/AbstractArc.java
409 409
        init = end;
410 410
        end = aux;
411 411
    }
412

  
413

  
414
    /* (non-Javadoc)
415
     * @see org.gvsig.fmap.geom.primitive.Arc#getStartAngle()
416
     */
417
    public double getStartAngle() throws GeometryOperationNotSupportedException, GeometryOperationException {
418
        return getAngle(getCenterPoint(), getInitPoint());
419
    }
420

  
421
    /* (non-Javadoc)
422
     * @see org.gvsig.fmap.geom.primitive.Arc#getEndAngle()
423
     */
424
    public double getEndAngle() throws GeometryOperationNotSupportedException, GeometryOperationException {
425
        return getAngle(getCenterPoint(), getEndPoint());
426
    }
427

  
428
    private double getAngle(Point start, Point end) throws GeometryOperationNotSupportedException, GeometryOperationException {
429
        double angle = Math.acos((end.getX() - start.getX()) / start.distance(end));
430

  
431
        if (start.getY() > end.getY()) {
432
            angle = -angle;
433
        }
434

  
435
        if (angle < 0) {
436
            angle += (2 * Math.PI);
437
        }
438

  
439
        return angle;
440
    }
441

  
412 442
}

Also available in: Unified diff