[SOLVED] nearestFacetOnRay no taking into account vector orientation

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
wmayer
Founder
Posts: 20307
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: [SOLVED] nearestFacetOnRay no taking into account vector orientation

Post by wmayer »

comlich wrote: Fri Jul 22, 2022 6:07 pm However, that let me realize a behavior of the foraminate function that can be undesirable to some (including me, especially in the problem I am dealing with at the moment). When calling foraminate with a point that is outside the mesh, the direction of the real ray is ignored (regardless of whether the maximum angle between the direction and the facets' normals is limited or not).
Yes, you are right about this behaviour. On the other hand the documentation only says that the angle between ray and facet normal is checked but not the start point of the ray relative to the facet. Since I don't know if this situation has been overlooked or if it's on purpose I cannot simply change the implementation.
In my case I am only interested in rays pointing downwards ie. with direction = (0,0,-1). I thought the foraminate function could handle this situation by returning no intersection points when the ray doesn't cross the mesh. But it doesn't, so I used a filtering work-around inspired by the one you sent, to filter out intersections points which are above the origin point of the ray. But in case the direction is neither along X, Y nor Z, such work-around could be more difficult to implement.
You can easily extend the filter function by computing the signed distance of the start point of the ray to the facet. If this value is positive you can filter the facet, if's negative or null accept it.

Assuming that the ray is defined by (Point, Direction) and that the intersection point of a facet with the ray is IntersectionPoint you can determine the signed distance with:

Code: Select all

(Point - Intersection) * Direction
Post Reply