JOIN
Get Time
forums   
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat (oldest first)  | Threaded  | Tree
Previous Thread  |  Next Thread
Re: Basic Concept: I don't get the logic behind the distance between a line segment and a point. (response to post by Illuminad) | Reply
I'm unfamiliar with vector arithmetic but I know high school trigonometry. Does anyone know what the right answer here is :c?

Both answers are correct. The reason vector arithmetic is usually preferred in computer science is because of internals of trigonometry function (sin, cos, tan, etc.) implementations. First, these functions are slow. Then, using them to calculate things like line-point distance leads to less precise results. This is very important when it comes to determining things like "less than 0 degrees", "greater than 90 degrees" and so on. Especially when we deal with integer-valued coordinates.
Last but not least is that when using vector arithmetic, the corner case amount is usually reduced compared to trigonometry formulas.
To sum it up, when you have relatively high amount of time for calculations, and the coordinates are floating-point values, and allowed error tolerance is big enough (like 10E-5), you are free to use trigonometry. In other cases, do think twice before you do so. For example, I personally try to use vector arithmetic in Marathon Match contests whenever possible.
Basic Concept: I don't get the logic behind the distance between a line segment and a point. | Reply
From what I understand from the tutorial, to find the distance between a line segment and a point, you need to consider the case where C (the point) lies outside of the line segment AB. In order to determine whether this special case occurs, you use the sign of the dot product of the vectors formed by the three points, A, B and C.

The tutorial says...
"First, check to see if the nearest point on the line AB is beyond B (as in the example above) by taking AB ⋅ BC. If this value is greater than 0, it means that the angle between AB and BC is between -90 and 90, exclusive, and therefore the nearest point on the segment AB will be B"

But how come it isn't...
"If this value is greater than 0, it means that the angle between AB and BC is between -90 and 90, exclusive, and therefore the nearest point to C is within segment AB (it may or may not be A or B, the endpoints)"

So what I'm thinking is, if the angle between AB and BC, theta, is between 0 and 90, then cos(theta) is positive, then the nearest point to C should lie within the segment AB. In this case, we can drop a perpendicular from C to AB and calculate its length with dot_product(AC, AB) / abs(AB). Otherwise, if theta is greater than 90 degrees (but less than 270) then cos(theta) is negative and so C lies beyond line segment AB, therefore, the closest point must be one of the endpoints A or B and the distance we're looking for the length of line segment AC or BC.

I'm unfamiliar with vector arithmetic but I know high school trigonometry. Does anyone know what the right answer here is :c?
RSS