svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / UtilFunctions.java @ 1430
History | View | Annotate | Download (4.15 KB)
1 |
/*
|
---|---|
2 |
* Created on 10-feb-2005
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
package com.iver.cit.gvsig.fmap.edition; |
45 |
|
46 |
import java.awt.Color; |
47 |
import java.awt.Graphics; |
48 |
import java.awt.Graphics2D; |
49 |
import java.awt.geom.Arc2D; |
50 |
import java.awt.geom.Line2D; |
51 |
import java.awt.geom.Point2D; |
52 |
import java.awt.geom.Rectangle2D; |
53 |
|
54 |
/**
|
55 |
* @author FJP
|
56 |
*
|
57 |
* TODO To change the template for this generated type comment go to
|
58 |
* Window - Preferences - Java - Code Generation - Code and Comments
|
59 |
*/
|
60 |
public class UtilFunctions { |
61 |
static public Arc2D createCircle(Point2D p1, Point2D p2, Point2D p3) //, Graphics g) |
62 |
{ |
63 |
double xC, yC, w, h;
|
64 |
|
65 |
// Calculamos 2 secantes, tiramos perpendiculares por sus puntos
|
66 |
// medios y obtenemos el centro. Luego calculamos el radio.
|
67 |
// Puntos medios de los segmentos.
|
68 |
double xm1, ym1, xm2, ym2;
|
69 |
xm1 = (p1.getX() + p2.getX())/ 2.0;
|
70 |
ym1 = (p1.getY() + p2.getY())/ 2.0;
|
71 |
xm2 = (p2.getX() + p3.getX())/ 2.0;
|
72 |
ym2 = (p2.getY() + p3.getY())/ 2.0;
|
73 |
|
74 |
/* g.setColor(Color.GRAY);
|
75 |
g.draw3DRect((int)xm1, (int) ym1, 1, 1, true);
|
76 |
g.draw3DRect((int)xm2, (int) ym2, 1, 1, true); */
|
77 |
// Pendientes de las perpendiculares y constantes
|
78 |
double mP1=0, mP2=0, A1, A2; |
79 |
boolean bPerp1 = false, bPerp2 = false; |
80 |
if (p2.getY() - p1.getY() == 0) |
81 |
{ |
82 |
A1 = ym1; |
83 |
bPerp1 = true;
|
84 |
} |
85 |
else
|
86 |
{ |
87 |
mP1 = (p2.getX() - p1.getX()) /(p1.getY() - p2.getY()); |
88 |
A1 = ym1 - xm1 * mP1; |
89 |
} |
90 |
if (p2.getY() - p3.getY() == 0) |
91 |
{ |
92 |
A2 = ym2; |
93 |
bPerp2 = true;
|
94 |
} |
95 |
else
|
96 |
{ |
97 |
mP2 = (p3.getX() - p2.getX()) /(p2.getY() - p3.getY()); |
98 |
A2 = ym2 - xm2 * mP2; |
99 |
} |
100 |
if (mP2 == mP1)
|
101 |
{ |
102 |
return null; // Error, 3 puntos alineados. No puede pasar un arco |
103 |
} |
104 |
else
|
105 |
{ |
106 |
xC = (A2 - A1)/(mP1-mP2); |
107 |
if (!bPerp1)
|
108 |
yC = xC * mP1 + A1; |
109 |
else
|
110 |
yC = xC * mP2 + A2; |
111 |
} |
112 |
double Radio = p1.distance(xC, yC);
|
113 |
double xR = xC - Radio ;
|
114 |
double yR = yC - Radio ;
|
115 |
w = 2.0* Radio;
|
116 |
h = w; |
117 |
Rectangle2D.Double rBounds = new Rectangle2D.Double(xR,yR, w,h); |
118 |
Arc2D.Double resul = new Arc2D.Double(rBounds, 0.0, 360.0, Arc2D.OPEN); |
119 |
/* g.setColor(Color.RED);
|
120 |
((Graphics2D) g).draw(resul);
|
121 |
g.setColor(Color.BLUE);
|
122 |
((Graphics2D) g).draw(rBounds);
|
123 |
g.draw3DRect((int)p1.getX(), (int) p1.getY(), 1, 1, true);
|
124 |
g.draw3DRect((int)p2.getX(), (int) p2.getY(), 2, 2, true);
|
125 |
g.draw3DRect((int)p3.getX(), (int) p3.getY(), 1, 1, true);
|
126 |
g.drawString("1", (int) p1.getX(), (int) p1.getY());
|
127 |
g.drawString("2", (int) p2.getX(), (int) p2.getY());
|
128 |
g.drawString("3", (int) p3.getX(), (int) p3.getY());
|
129 |
g.drawString("C", (int) xC, (int) yC);
|
130 |
g.draw3DRect((int)xC, (int) yC, 2, 2, true); */
|
131 |
|
132 |
return resul;
|
133 |
} |
134 |
|
135 |
} |