Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibly a bug in sig of the distance #129

Open
ipcoder opened this issue Feb 4, 2025 · 0 comments
Open

Possibly a bug in sig of the distance #129

ipcoder opened this issue Feb 4, 2025 · 0 comments

Comments

@ipcoder
Copy link

ipcoder commented Feb 4, 2025

It seems to me that the minus sign is by mistake applied twice when passing the d into create().

Considering that create does not changes values, only packs into array [*normal, distance], than
distance there is equivalent to the d in the comment defining the plane equation -d = ax+bx+xz.
So that [nx, ny, nx, distance ] equivalent to [a, b, c, d] up to normalization.
It is calculated correctly on the next line with required minus d = -np.sum(n * position).
However the sign is changed again when passed to create(n, -d, dtype)

@parameters_as_numpy_arrays('position', 'normal')
def create_from_position(position, normal, dtype=None):
    dtype = dtype or position.dtype
    # -d = a * x  + b * y + c * z
    n = vector.normalize(normal)
    d = -np.sum(n * position)
    return create(n, -d, dtype)

def create(normal=None, distance=0.0, dtype=None):
    if normal is None:
        normal = [0.0, 0.0, 1.0]
    return np.array([normal[0], normal[1], normal[2], distance], dtype=dtype)

As a result, when creating a plane in this simple case:

pl = plane.create_from_position([1,1,1], [1,1,1], dtype=float)
print(f"plane: {pl}")

zero = plane.normal(pl).dot(plane.position(pl)) + plane.distance(pl)
print(f"p*n + d = {zero} != 0!"

the result does not satisfy the plane equation p*n + d = 0 for position:

plane: [0.57735027 0.57735027 0.57735027 1.73205081]
p*n + d = 3.4641016151377553 != 0!

Unless I am missing something, I suggest to remove the minus in the call to create:

return create(n, d, dtype)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant