gkjohnson / three-mesh-bvh

A BVH implementation to speed up raycasting and enable spatial queries against three.js meshes.
https://gkjohnson.github.io/three-mesh-bvh/example/bundle/raycast.html
MIT License
2.5k stars 261 forks source link

why here copy edge1.start #444

Closed oneKonw closed 2 years ago

oneKonw commented 2 years ago

https://github.com/gkjohnson/three-mesh-bvh/blob/5b2b27f30dfd3a55ce5b05a7fcb63fac806eac3e/src/math/ExtendedTriangle.js#L274-L281 hello, i am sorry about that my english is poor. i dont understand why is here copy the edge1.start instead of edge1.end. could you please tell me why . thank you very mush.

gkjohnson commented 2 years ago

It probably deserves a comment but this is handling the case where exactly one corner of a triangle intersects the edge of the other meaning that there's only one point of overlap which is assigned to edge1.start.

oneKonw commented 2 years ago

It probably deserves a comment but this is handling the case where exactly one corner of a triangle intersects the edge of the other meaning that there's only one point of overlap which is assigned to edge1.start.

Thanks for your answer. I konw it means that only one point of overlap , but the default value of found2 is false, so the targetPoint = edge2.end , when the count == 1 ,is that not assigned to edge1.end ?

gkjohnson commented 2 years ago

You're right! Looks like this is a bug. Do you want to make a PR with a fix and replace it with edge1.end?

oneKonw commented 2 years ago

Yes, it is my pleasure . And i have another question. In https://github.com/gkjohnson/three-mesh-bvh/blob/master/src/math/MathUtilities.js , the 17 line,

const v0 = l1.start;
const v10 = dir1;
const v2 = l2.start;
const v32 = dir2;

v02.subVectors( v0, v2 );
dir1.subVectors( l1.end, l2.start );
dir2.subVectors( l2.end, l2.start );

according to http://paulbourke.net/geometry/pointlineplane/lineline.c,

p21.x = p2.x - p1.x;
p21.y = p2.y - p1.y;

I think that p21 equals v10 in here. so that need to change

dir1.subVectors( l1.end, l2.start )
===>
dir1.subVectors( l1.end, l1.start )

Is that right ?

gkjohnson commented 2 years ago
dir1.subVectors( l1.end, l2.start )
===>
dir1.subVectors( l1.end, l1.start )

Is that right ?

Yup! That looks right - looks like a flub when I ported the function.

oneKonw commented 2 years ago

OK , I create a pr to fix the two question.