-1

I saw these methods in the Line2D Java Docs but did not understand what they do?

Javadoc for ptLineDist says:

Returns the distance from a point to this line. The distance measured is the distance between the specified point and the closest point on the infinitely-extended line defined by this Line2D. If the specified point intersects the line, this method returns 0.0

Doc for relativeCCW says:

Returns an indicator of where the specified point (PX, PY) lies with respect to the line segment from (X1, Y1) to (X2, Y2). The return value can be either 1, -1, or 0 and indicates in which direction the specified line must pivot around its first endpoint, (X1, Y1), in order to point at the specified point (PX, PY).

A return value of 1 indicates that the line segment must turn in the direction that takes the positive X axis towards the negative Y axis. In the default coordinate system used by Java 2D, this direction is counterclockwise.

A return value of -1 indicates that the line segment must turn in the direction that takes the positive X axis towards the positive Y axis. In the default coordinate system, this direction is clockwise.

A return value of 0 indicates that the point lies exactly on the line segment. Note that an indicator value of 0 is rare and not useful for determining colinearity because of floating point rounding issues.

If the point is colinear with the line segment, but not between the endpoints, then the value will be -1 if the point lies "beyond (X1, Y1)" or 1 if the point lies "beyond (X2, Y2)".

5
  • put references where did you see that.
    – Yusubov
    Sep 22, 2012 at 2:50
  • if you are the one who -1'd me, I already wrote JAVA DOCS. If not, I apologize :p
    – A User
    Sep 22, 2012 at 2:54
  • if my reference is correct, it is a name of class not a method
    – Yusubov
    Sep 22, 2012 at 3:03
  • 3
    Did you click on the methods and read the (slightly more) detailed docs?
    – Adam Lear
    Sep 22, 2012 at 3:07
  • 1
    Yes, I did @AnnaLear
    – A User
    Sep 22, 2012 at 18:45

1 Answer 1

1

ptLineDist is the shortest distance between a point and a line.

One trick to note is that it's an infinitely extended line, which means that the line is extended out to infinity in either direction and then the distance between the line and point is determined.

I don't do 2D programming work, but this could be handy if I were trying to determine how far an object (defined by a reference point) was from the horizon line of another object.

relativeCCW tells you which direction a line would have to rotate in order to direct itself at a point. (I really wanted to say "point at a point" there).

I think their definitions of clockwise / counterclockwise are backwards, but whatever, at least they're defined. I would experiment and validate the results.

This could be useful if I had a vector or an arrow and wanted to see which direction it needed to rotate from its base in order to align with my point. So, if I were writing a compass application, I could keep track of which way to rotate to get to North.

Not the answer you're looking for? Browse other questions tagged or ask your own question.