jeffThompson / CollisionDetection

A book and examples on collision detection

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

line/circle

Lin-Rolover opened this issue Β· comments

Why do this?
float len = sqrt( (distXdistX) + (distYdistY) );
And after this
float dot = ( ((cx-x1)(x2-x1)) + ((cy-y1)(y2-y1)) ) / pow(len,2);

You have scalar aa
float len2 = (distXdistX) + (distYdistY);
And
float dot = ( ((cx-x1)(x2-x1)) + ((cy-y1)(y2-y1)) ) / len2;

But what is that ? I am understand projection vector in other vector ab/|b|. But what is : ab/|b|*|b|?

Thanks for noting this. It's been a looooong time since I researched this and my vector math isn't so good. I'm not sure I'm understanding you're question though?

I found out. This is really a projection of a vector onto a vector, but also finding a collinear vector

  1. π‘π‘Ÿπ‘₯ (π‘Œ) = |π‘Œ| βˆ™ π‘π‘œπ‘ (βˆ π‘‹, π‘Œ) = (π‘‹βˆ™ π‘Œ) / |𝑋| this number, the length of the projection with a sign (+, -)
  2. 𝑃𝑅𝑋 (π‘Œ) = ((π‘‹βˆ™ π‘Œ) / |𝑋|) βˆ™ (𝑋/|𝑋|) = ((𝑋,π‘Œ) βˆ™ 𝑋) / |𝑋|βˆ™|𝑋| - is a vector parallel (collinear) to the vector 𝑋.
    and |𝑋|βˆ™|𝑋| <=>(π‘‹βˆ™π‘‹) => ((π‘‹βˆ™ π‘Œ)/(π‘‹βˆ™π‘‹)) βˆ™ 𝑋

ab/|b|*|b| => ((π‘‹βˆ™ π‘Œ)/(π‘‹βˆ™π‘‹)) = dot => dot βˆ™ 𝑋 - But this is a vector

Then you find the point
x = x1 + (dot βˆ™ (x2 - x1) ) // x1 + dot βˆ™ Xx
y = y1 + (dot βˆ™ (y2 - y1) ) // y1 + dot βˆ™ Xy

Sorry, I think you lost me! Does this mean the code on the site isn't working correctly or could be simplified?

Honestly, I haven’t tested your code at all except on the page at the very top. I just read and took for an idea, a solution algorithm, for example, what steps, what to watch for. I really liked the point / polygon algorithm, I took the comparison logic, and did not analyze it.

In some solutions, I went from the opposite. For example, the intersection of a point and a line. I did not look for the intersection of a point with a line. I checked whether the point of the line belongs. Got this result

pointLine (px,py, l) {
l = l.arrVert;
// if the scalar product of vectors <= 0, the point belongs to the segment
return (
(l[0] - px) * ( l[2] - px) +
(l[1] - py) * (l[3] - py) <= 0
) ? {x:px, y:py} : false;
}
All

If think can put a buffer in, but now me no needed pointer
And my line / line algorithm is not very scary. Sorry.

But once again I want to thank you for great ideas
The code can be simplified, without doing unnecessary actions