Skip to content

Clearer documentation for intersection_ray_mesh #34

@yiqiaowang-arch

Description

@yiqiaowang-arch

Feature Request

As a developer for CityEnergyAnalyst, I want clearer documentation for intersection_ray_mesh so that I could understand the relationship between u, v, w and the vertices of the mesh. For example, is p_hit = up1 + vp2 + wp3 or wp1 + vp2 + up3? What's the relationship between this barycentric coordinate and another function provided by compas, barycentric_coordinates?

Details

In the following example code, I want to reconstruct the coordinates of the intersection point between a ray vertically extruded from a point at XY plane and a triangular mesh.

Image

the code is listed as below:

import compas.geometry
import compas.datastructures


p0 = compas.geometry.Point(2, 0, 0)
p1 = compas.geometry.Point(3, 0, 13)
p2 = compas.geometry.Point(0, 0, 10)
p3 = compas.geometry.Point(0, 2, 10)

mesh = compas.datastructures.Mesh.from_points([[p1.x, p1.y, p1.z],
                                               [p2.x, p2.y, p2.z],
                                               [p3.x, p3.y, p3.z]])

ray = (p0, compas.geometry.Vector(0, 0, 1))
hits = compas.geometry.intersection_ray_mesh(ray, mesh.to_vertices_and_faces())
idx, u, v, t = hits[0]
print("intersection length:", t)

w = 1 - u - v # barycentric coordinates
print("barycentric coordinates:", u, v, w)

phit = compas.geometry.Point(
    w * p1.x + v * p2.x + u * p3.x,
    w * p1.y + v * p2.y + u * p3.y,
    w * p1.z + v * p2.z + u * p3.z
)

print("intersection point", phit.x, phit.y, phit.z)

bary_coords = compas.geometry.barycentric_coordinates([p0.x, p0.y, p0.z], [p1, p2, p3])
print("reconstructed barycentric coordinates:", *bary_coords)

And the output is as such:

intersection length: 12.0
barycentric coordinates: -0.0 0.3333333432674408 0.6666666567325592
intersection point 1.9999999701976776 0.0 11.999999970197678
reconstructed barycentric coordinates: -1.3333333333333335 2.3333333333333335 0.0

It seems that w is corresponding to p1, v to p2 and u to p3. However, in the documentation, this is not clearly listed.

Further, the documentation listed the second and the third output to both the u coordinate. I believe that the third output should be v, instead of u.

Finally, the u, v, w is not identical as the reconstructed barycentric coordinates provided by compas.geometry.barycentric_coordinates. Instead of [0, 0.33, 0.67], the compas function outputs [-1.33, 2.33, 0]. Could you help me understand the difference here?

Describe the solution you'd like
It would be nice if clear documentation for the role of u, v, w is listed; also, the typo in documentation should be fixed. Further, it would be beneficial to unify the two barycentric calculations in compas and in compas_libigl.

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions