I looked back through this thread and back through the stuff you have uploaded and I'm going to say it again.

While I'm sure your formulas are correct and it makes sense to you, I don't know if it is comprehensible to people like me ( in fact it is not comprehensible to me ).

One thing I have found interesting about those whom understand higher mathematics very well is the inability to explain it to those with less knowledge or understanding. What I mean by this is sometimes offering up way more knowledge in one go without understanding the previous material is overwhelming and is probably why people feel like idiots, at least that's how I feel right now.

Please, finish your material and upload as you planned, I'm sure others won't have such a difficult time with it as I have.

My original point on this thread was, I wasn't and still unable to visualize in my head or on paper the point/line intersection formulas chili used. For instance, if I draw a line and a ball separated from the line on a piece of paper, I can see visually that the closest point is going to be a straight line from the ball perpendicular to the line.

Now, how do I find this vector that goes from the ball to the line? I know that the dot product is used to cast a shadow ( project ) onto another line so the dot product is what I would use. Using the vector from p0 to ball center I can project that vector onto the line segment which gives me the closest point on the line the segment is on. If the distance of that point to p0 is less than the distance to p1, then the point is on the segment. Then I can check if the distance from the closest point that we just calculated to the center of the ball is less than the radius of the ball, then we have a collision otherwise we do not.

I am unsure if that makes things any clearer as to what I meant by being able to visualize or reason about the steps needed to find closest point and determining if there is a collision. The formula chili uses:

Code: Select all

```
const auto a = p0.y - p1.y;
const auto b = p1.x - p0.x;
const auto c = ( p0.x * p1.y ) - ( p0.y * p1.x );
return std::abs( a * r.x + b * r.y + c ) / std::sqrt( sq( a ) + sq( b ) );
```

First off, I am not sure if 'a' = p0.y - p1.y is like that because the screen coordinates in the Y is flipped compared to the Cartesian Y coordinate or if it even matters.

Second, from what I can tell, 'a' is the height ( negated? ) and 'b' is the width if an imaginary triangle where p1-p0 is the hypotenuse.

Third, 'c' is the area of a quadrangle with p0 and p1 being opposite corners.

Fourth, std::sqrt( sq( a ) + sq( b ) ) gives the length of the hypotenuse ( ||p1-p0|| ).

So the only part I don't understand is the ( a * r.x + b * r.y + c ) or as I described:

( length of side A * r.x + length of side B * r.y + area of quadrangle )

This is the only part of the distance from point to line I can't visualize I suppose. It's apparently some factor of the length of the hypotenuse or ||p1-p0||, but how?

Let's see if giving concrete numbers to abstract variables helps:

p0 = ( 10, 100 )

p1 = ( 200, 10 )

r = ( 400, 400 )

First, side A

a = p1.y - p0.y = 10 - 100 = -90

b = p0.x - p1.x = 10 - 200 = -190

c = ( p0.x * p1.y ) - ( p0.y * p1.x ) = ( 10 * 10 ) - ( 100 * 200 ) = 100 - 20000 = -19900

X = ( a * r.x + b * r.y + c ) = ( -90 * 400 ) + ( -190 * 400 ) + 19900 = ( -36000 ) + ( -76000 ) + ( -19900 ) = -131900

L = sqrt( ( a * a ) + ( b * b ) ) = 210.238

d = |X| / L = 131900 / 210.238... = 627.384...

Am I right in assuming that the portion I'm not understanding is a simplification of a larger formula just like ( ax * by ) - ( ay * bx ) is a simplified version of the 3D cross product

cx = ( ay * bz ) - ( az * by ),

cy = ( az * bx ) - ( ax * bz ),

cz = ( ax * by ) - ( ay * bx )

Since a 2D vector would be extended to ( x, y, 0 ), the first two equations are always going to be 0 and not needed in 2D and the Z would just be the area of a parallelogram with A and B as opposite points, or if divided by 2 would be the area of a triangle where AB would be the hypotenuse.

I must have something wrong here, because if I use the ( ax + by + c ) = 0 formula and plug in p0.x and p0.y as the x and y, I get:

ax = -90 * 10 = -900

by = -190 * 100 = -19000

c = -19900

(-900 + ( -19000 ) + ( -19900 ) = -39800

If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com