Skip to content

get_sdf_pts() returns wrong SDF for single-point queries (PCU method) #51

Description

@gattia

Description

Mesh.get_sdf_pts() using the default PCU method returns incorrect signed distance values when called with a single query point (shape (1, 3)). With 2+ points, results are correct.

Reproduction

import numpy as np
import pyvista as pv
from pymskt.mesh import Mesh

cyl = pv.Cylinder(center=[0,0,0], direction=(0,0,1), radius=5.0, height=20.0, resolution=50)
mesh = Mesh(cyl.triangulate())

Single point on the surface — WRONG

pts_1 = np.array([[5.0, 0.0, 0.0]])
sdf_1 = mesh.get_sdf_pts(pts_1)
print(f"1 point (surface): {sdf_1}") # Returns -11.84 (should be ~0)

Same point with a second point — CORRECT

pts_2 = np.array([[5.0, 0.0, 0.0], [0.0, 0.0, 0.0]])
sdf_2 = mesh.get_sdf_pts(pts_2)
print(f"2 points: {sdf_2}") # Returns [0.01, -4.99] (correct)
Output

1 point (surface): -11.84160892722138
2 points: [ 0.00986164 -4.98872184]
Expected behavior
The SDF for a point on the cylinder surface should be ~0 regardless of whether it is queried alone or with other points.

Environment
Python 3.9.19
PCU (point_cloud_utils) as the SDF backend
Tested on Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions