Revision 2305
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.util/org.gvsig.tools.util.impl/src/main/java/org/gvsig/euclidean/EuclideanLine2DImpl.java | ||
---|---|---|
144 | 144 |
public double getDistance(EuclideanLine2D line) { |
145 | 145 |
|
146 | 146 |
if (isParallel(line)) { //Parallel lines |
147 |
Double num = Math.abs(line.getC() - coefC); |
|
147 | 148 |
if (Double.isInfinite(m)) { //Vertical lines |
148 |
return line.getC() - coefC;
|
|
149 |
return num;
|
|
149 | 150 |
} |
150 | 151 |
Double den = Math.sqrt(Math.pow(coefA, 2) + Math.pow(coefB, 2)); |
151 |
return Math.abs(line.getC() - coefC) / den;
|
|
152 |
return num / den;
|
|
152 | 153 |
} |
153 | 154 |
return 0d; |
154 | 155 |
} |
... | ... | |
192 | 193 |
|
193 | 194 |
@Override |
194 | 195 |
public EuclideanLine2D getPerpendicular(double pointX, double pointY) { |
196 |
if(Math.abs(m)==0.0){ |
|
197 |
return new EuclideanLine2DImpl(1, 0, -pointX); |
|
198 |
} |
|
199 |
if(Double.isInfinite(m)){ |
|
200 |
return new EuclideanLine2DImpl(0, 1, -pointY); |
|
201 |
} |
|
195 | 202 |
// perpendicular slope (m) |
196 | 203 |
Double m1 = -1 / m; |
197 | 204 |
|
... | ... | |
214 | 221 |
if (Double.isInfinite(m)) { |
215 | 222 |
y = pointY; |
216 | 223 |
x = (-coefB * y - coefC) / coefA; |
217 |
} else if (m == 0) {
|
|
224 |
} else if (Math.abs(m) == 0) {
|
|
218 | 225 |
x = pointX; |
219 | 226 |
y = b; |
220 | 227 |
} else { |
Also available in: Unified diff