Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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)".

share|improve this question

closed as not a real question by Yusubov, Mark Trapp, Walter, ChrisF Oct 6 '12 at 21:51

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

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

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
add comment

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