Closed itfanr closed 10 months ago
Hi, @itfanr
According to my sketch the ray directed not as you expected:
See https://observablehq.com/@alexbol99/ray-and-segment-intersect-151
This is definitely wrong, ray supposed to be directed to the right of the normal vector.
I will check this.
You may help me to check if you want
I am a new js user. I will try to fix it. Thank you for your attention to this issue.
@itfanr ,
Actually there is no mistake.
Simply this library makes an assumption that "y"-axis goes upwards, like in math.
In the image "y"-axis usually goes downwards, which makes it look like in mirror.
In order to get result that you expected, you have to invert vector to be vector(-71.147335, -70.2713))
:
@alexbol99 Thank you. I think I need to check the coordinate system and add some transform.
let s = segment(point(336, -281.5), point(636, -281.5));
let r = ray(point(486, -271), vector(71.147335, -70.2713));
let ip = s.intersect(r);
if (ip.length > 0) {
console.log(ip[0].x, ip[0].y);
}
I calculated in third quadrant and got the interesct intersection (475.6292861847882, -281.5)
The expectation of this code is to output the intersection point. But I cannot get it.
Can someone help me?