Changeset 23190 in osm for applications/editors/josm/plugins/duplicateway
- Timestamp:
- 2010-09-15T18:54:18+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/duplicateway/src/org/openstreetmap/josm/plugins/duplicateway/JVector.java
r13497 r23190 15 15 * A class encapsulating a line Segment treating it as a Vector ( 16 16 * direction and length). Includes Utility routines to perform various 17 * transformations and Trigonometric operations 17 * transformations and Trigonometric operations 18 18 * 19 19 * @author Brent Easton … … 21 21 */ 22 22 public class JVector extends Line2D.Double { 23 23 24 24 public static final double EARTH_CIRCUMFERENCE = 40041455; 25 25 protected static final double PI_ON_2 = Math.PI / 2.0; 26 26 protected Point2D.Double slopeIntercept = null; 27 27 protected Point2D.Double rtheta = null; 28 28 29 29 /** 30 30 * Create new JVector joining two points 31 * 31 * 32 32 * @param x1 33 33 * @param y1 … … 38 38 super(x1, y1, x2, y2); 39 39 } 40 40 41 41 /** 42 42 * Create new JVector from another JVector 43 * 43 * 44 44 * @param v JVector to copy 45 45 */ … … 51 51 y2 = v.y2; 52 52 } 53 53 54 54 /** 55 55 * Create a new JVector based on a JOSM Segment object 56 * 56 * 57 57 * @param s 58 58 */ … … 60 60 super(s.from.eastNorth.east(), s.from.eastNorth.north(), s.to.eastNorth.east(), s.to.eastNorth.north()); 61 61 } 62 62 63 63 /** 64 64 * Calculate slope/intersect from cartesian co-ords … … 70 70 slopeIntercept = new Point2D.Double(slope, intersect); 71 71 } 72 72 73 73 /** 74 74 * Return the slope of the JVector … … 81 81 return slopeIntercept.x; 82 82 } 83 83 84 84 /** 85 85 * Return the Y intercept of the JVector … … 92 92 return slopeIntercept.y; 93 93 } 94 94 95 95 /** 96 96 * Calculate the polar coordinates for this line as a ray with … … 104 104 rtheta = new Point2D.Double(r, theta); 105 105 } 106 106 107 107 /** 108 108 * Return the length of the line segment … … 115 115 return rtheta.x; 116 116 } 117 117 118 118 /** 119 119 * Return the angle of the line segment … … 126 126 return rtheta.y; 127 127 } 128 128 129 129 /** 130 130 * Convert Polar co-ords to cartesian … … 137 137 slopeIntercept = null; 138 138 } 139 139 140 140 /** 141 141 * Set the line segment using Polar co-ordinates 142 * 142 * 143 143 * @param r line length 144 144 * @param theta angle … … 148 148 polarToCartesian(); 149 149 } 150 150 151 151 /** 152 152 * Set the length of the line segment … … 157 157 polarToCartesian(); 158 158 } 159 159 160 160 /** 161 161 * Reverse the direction of the segment … … 171 171 rtheta = null; 172 172 } 173 173 174 174 /** 175 175 * Rotate the line segment about the origin … … 183 183 polarToCartesian(); 184 184 } 185 185 186 186 /** 187 187 * Rotate 90 degrees clockwise … … 191 191 rotate(-PI_ON_2); 192 192 } 193 193 194 194 /** 195 195 * Rotate 90 degrees counterclockwise … … 199 199 rotate(PI_ON_2); 200 200 } 201 201 202 202 /** 203 203 * Normalize theta to be in the range -PI < theta < PI … … 216 216 return theta; 217 217 } 218 219 /** 220 * Rotate the line segment 90 degrees and set the length. 218 219 /** 220 * Rotate the line segment 90 degrees and set the length. 221 221 * @param offset length 222 222 */ … … 226 226 } 227 227 228 /* 229 * Return the distance of the given point from this line. Offset is 228 /* 229 * Return the distance of the given point from this line. Offset is 230 230 * -ve if the point is to the left of the line, or +ve if to the right 231 231 */ 232 233 234 /** 235 * Return the distance of the given point from this line. Offset is 232 233 234 /** 235 * Return the distance of the given point from this line. Offset is 236 236 * -ve if the point is to the left of the line, or +ve if to the right 237 * @param target 237 * @param target 238 238 */ 239 239 protected double calculateOffset(EastNorth target) { 240 240 241 241 // Calculate the perpendicular interceptor to this point 242 242 EastNorth intersectPoint = perpIntersect(target); 243 243 JVector intersectRay = new JVector(intersectPoint.east(), intersectPoint.north(), target.east(), target.north()); 244 244 245 245 // Offset is equal to the length of the interceptor 246 246 double offset = intersectRay.getLength(); 247 247 248 248 // Check the angle between this line and the interceptor to calculate left/right 249 249 double theta = normalize(getTheta() - intersectRay.getTheta()); … … 251 251 offset = -offset; 252 252 } 253 253 254 254 return offset; 255 255 } 256 256 257 257 258 258 /** … … 282 282 * @return 283 283 */ 284 public static double perpDistance(Segment s, EastNorth en) { 284 public static double perpDistance(Segment s, EastNorth en) { 285 285 return Line2D.ptSegDist(s.from.eastNorth.east(), s.from.eastNorth.north(), s.to.eastNorth.east(), s.to.eastNorth.north(), en.east(), en.north()); 286 286 } 287 287 288 288 /** 289 289 * Calculate the bisector between this and another Vector. A positive offset means … … 297 297 double newTheta = Math.PI + ls.getTheta() - getTheta(); 298 298 newSeg.setPolar(Math.abs(offset), newSeg.getTheta() - newTheta/2.0); 299 299 300 300 double angle = normalize(getTheta() - newSeg.getTheta()); 301 301 if ((angle < 0 && offset > 0) || (angle > 0 && offset < 0)) { … … 304 304 return newSeg; 305 305 } 306 306 307 307 /** 308 308 * Return the Perpendicular Intersector from a point to this line … … 313 313 return perpIntersect(n.eastNorth); 314 314 } 315 315 316 316 /** 317 317 * Calculate the point on our line closest to the supplied point … … 320 320 */ 321 321 public EastNorth perpIntersect(EastNorth en) { 322 322 323 323 /* 324 324 * Calculate the coefficients for the two lines … … 326 326 * 2. The perpendicular line through the new point: y = cx + d 327 327 */ 328 double perpSlope = -1 / getSlope(); 328 double perpSlope = -1 / getSlope(); 329 329 double perpIntercept = en.north() - (en.east() * perpSlope); 330 330 331 331 /* 332 332 * Solve the simultaneous equation to calculate the intersection … … 334 334 * ax - cx = d - b 335 335 * x (a-c) = d - b 336 * x = (d - b) / (a - c) 336 * x = (d - b) / (a - c) 337 337 */ 338 338 double intersectE = (perpIntercept - getIntercept()) / (getSlope() - perpSlope); 339 339 double intersectN = intersectE * getSlope() + getIntercept(); 340 340 341 341 return new EastNorth(intersectE, intersectN); 342 342 }
Note:
See TracChangeset
for help on using the changeset viewer.