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
- πππ₯ (π) = |π| β πππ (β π, π) = (πβ π) / |π| this number, the length of the projection with a sign (+, -)
- ππ
π (π) = ((πβ π) / |π|) β (π/|π|) = ((π,π) β π) / |π|β|π| - 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