Skip to content

Instantly share code, notes, and snippets.

@HViktorTsoi
Created June 25, 2020 13:30
Show Gist options
  • Save HViktorTsoi/e593912d9d2448ba41bc718f7a83dea6 to your computer and use it in GitHub Desktop.
Save HViktorTsoi/e593912d9d2448ba41bc718f7a83dea6 to your computer and use it in GitHub Desktop.
project 3D point to certain plane with parameter A, B, C (w.r.t. Ax+By+Cz=1)
def project_points(x, y, z, a, b, c):
"""
Projects the points with coordinates x, y, z onto the plane
defined by a*x + b*y + c*z = 1
"""
vector_norm = a * a + b * b + c * c
normal_vector = np.array([a, b, c]) / np.sqrt(vector_norm)
point_in_plane = np.array([a, b, c]) / vector_norm
points = np.column_stack((x, y, z))
points_from_point_in_plane = points - point_in_plane
proj_onto_normal_vector = np.dot(points_from_point_in_plane,
normal_vector)
proj_onto_plane = (points_from_point_in_plane -
proj_onto_normal_vector[:, None] * normal_vector)
return point_in_plane + proj_onto_plane
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment