Ignore:
Timestamp:
2010-09-15T18:54:18+02:00 (14 years ago)
Author:
stoecker
Message:

remove tabs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/duplicateway/src/org/openstreetmap/josm/plugins/duplicateway/JVector.java

    r13497 r23190  
    1515 * A class encapsulating a line Segment treating it as a Vector (
    1616 * direction and length). Includes Utility routines to perform various
    17  * transformations and Trigonometric operations 
     17 * transformations and Trigonometric operations
    1818 *
    1919 * @author Brent Easton
     
    2121 */
    2222public class JVector extends Line2D.Double {
    23  
     23
    2424  public static final double EARTH_CIRCUMFERENCE = 40041455;
    2525  protected static final double PI_ON_2 = Math.PI / 2.0;
    2626  protected Point2D.Double slopeIntercept = null;
    2727  protected Point2D.Double rtheta = null;
    28  
     28
    2929  /**
    3030   * Create new JVector joining two points
    31    * 
     31   *
    3232   * @param x1
    3333   * @param y1
     
    3838    super(x1, y1, x2, y2);
    3939  }
    40  
     40
    4141  /**
    4242   * Create new JVector from another JVector
    43    * 
     43   *
    4444   * @param v JVector to copy
    4545   */
     
    5151    y2 = v.y2;
    5252  }
    53  
     53
    5454  /**
    5555   * Create a new JVector based on a JOSM Segment object
    56    * 
     56   *
    5757   * @param s
    5858   */
     
    6060    super(s.from.eastNorth.east(), s.from.eastNorth.north(), s.to.eastNorth.east(), s.to.eastNorth.north());
    6161  }
    62  
     62
    6363  /**
    6464   * Calculate slope/intersect from cartesian co-ords
     
    7070    slopeIntercept = new Point2D.Double(slope, intersect);
    7171  }
    72  
     72
    7373  /**
    7474   * Return the slope of the JVector
     
    8181    return slopeIntercept.x;
    8282  }
    83  
     83
    8484  /**
    8585   * Return the Y intercept of the JVector
     
    9292    return slopeIntercept.y;
    9393  }
    94  
     94
    9595  /**
    9696   * Calculate the polar coordinates for this line as a ray with
     
    104104    rtheta = new Point2D.Double(r, theta);
    105105  }
    106  
     106
    107107  /**
    108108   * Return the length of the line segment
     
    115115    return rtheta.x;
    116116  }
    117  
     117
    118118  /**
    119119   * Return the angle of the line segment
     
    126126    return rtheta.y;
    127127  }
    128  
     128
    129129  /**
    130130   * Convert Polar co-ords to cartesian
     
    137137    slopeIntercept = null;
    138138  }
    139  
     139
    140140  /**
    141141   * Set the line segment using Polar co-ordinates
    142    * 
     142   *
    143143   * @param r line length
    144144   * @param theta angle
     
    148148    polarToCartesian();
    149149  }
    150  
     150
    151151  /**
    152152   * Set the length of the line segment
     
    157157    polarToCartesian();
    158158  }
    159  
     159
    160160  /**
    161161   * Reverse the direction of the segment
     
    171171    rtheta = null;
    172172  }
    173  
     173
    174174  /**
    175175   * Rotate the line segment about the origin
     
    183183    polarToCartesian();
    184184  }
    185  
     185
    186186  /**
    187187   * Rotate 90 degrees clockwise
     
    191191    rotate(-PI_ON_2);
    192192  }
    193  
     193
    194194  /**
    195195   * Rotate 90 degrees counterclockwise
     
    199199    rotate(PI_ON_2);
    200200  }
    201  
     201
    202202  /**
    203203   * Normalize theta to be in the range -PI < theta < PI
     
    216216    return theta;
    217217  }
    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.
    221221   * @param offset length
    222222   */
     
    226226  }
    227227
    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
    230230   * -ve if the point is to the left of the line, or +ve if to the right
    231231   */
    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
    236236   * -ve if the point is to the left of the line, or +ve if to the right
    237    * @param target 
     237   * @param target
    238238   */
    239239  protected double calculateOffset(EastNorth target) {
    240    
     240
    241241    // Calculate the perpendicular interceptor to this point
    242242    EastNorth intersectPoint = perpIntersect(target);
    243243    JVector intersectRay = new JVector(intersectPoint.east(), intersectPoint.north(), target.east(), target.north());
    244    
     244
    245245    // Offset is equal to the length of the interceptor
    246246    double offset = intersectRay.getLength();
    247    
     247
    248248    // Check the angle between this line and the interceptor to calculate left/right
    249249    double theta = normalize(getTheta() - intersectRay.getTheta());
     
    251251      offset = -offset;
    252252    }
    253    
     253
    254254    return offset;
    255255  }
    256  
     256
    257257
    258258  /**
     
    282282   * @return
    283283   */
    284   public static double perpDistance(Segment s, EastNorth en) { 
     284  public static double perpDistance(Segment s, EastNorth en) {
    285285   return Line2D.ptSegDist(s.from.eastNorth.east(), s.from.eastNorth.north(), s.to.eastNorth.east(), s.to.eastNorth.north(), en.east(), en.north());
    286286  }
    287  
     287
    288288  /**
    289289   * Calculate the bisector between this and another Vector. A positive offset means
     
    297297    double newTheta = Math.PI + ls.getTheta() - getTheta();
    298298    newSeg.setPolar(Math.abs(offset), newSeg.getTheta() - newTheta/2.0);
    299    
     299
    300300    double angle = normalize(getTheta() - newSeg.getTheta());
    301301    if ((angle < 0 && offset > 0) || (angle > 0 && offset < 0)) {
     
    304304    return newSeg;
    305305  }
    306  
     306
    307307  /**
    308308   * Return the Perpendicular Intersector from a point to this line
     
    313313    return perpIntersect(n.eastNorth);
    314314  }
    315  
     315
    316316  /**
    317317   * Calculate the point on our line closest to the supplied point
     
    320320   */
    321321  public EastNorth perpIntersect(EastNorth en) {
    322    
     322
    323323    /*
    324324     * Calculate the coefficients for the two lines
     
    326326     *  2. The perpendicular line through the new point: y = cx + d
    327327     */
    328     double perpSlope = -1 / getSlope();   
     328    double perpSlope = -1 / getSlope();
    329329    double perpIntercept = en.north() - (en.east() * perpSlope);
    330    
     330
    331331    /*
    332332     * Solve the simultaneous equation to calculate the intersection
     
    334334     *  ax - cx = d - b
    335335     *  x (a-c) = d - b
    336      *  x = (d - b) / (a - c) 
     336     *  x = (d - b) / (a - c)
    337337     */
    338338    double intersectE = (perpIntercept - getIntercept()) / (getSlope() - perpSlope);
    339339    double intersectN = intersectE * getSlope() + getIntercept();
    340    
     340
    341341    return new EastNorth(intersectE, intersectN);
    342342  }
Note: See TracChangeset for help on using the changeset viewer.