def project_point_line(point, line): """Project a point onto a line. Parameters ---------- point : list of float XYZ coordinates of the point. line : tuple Two points defining the projection line. Returns ------- list XYZ coordinates of the projected point. Notes ----- For more info, see [1]_. References ---------- .. [1] Wiki Books. *Linear Algebra/Orthogonal Projection Onto a Line*. Available at: https://en.wikibooks.org/wiki/Linear_Algebra/Orthogonal_Projection_Onto_a_Line. """ a, b = line ab = subtract_vectors(b, a) ap = subtract_vectors(point, a) c = vector_component(ap, ab) return add_vectors(a, c)
def closest_point_on_line(point, line): """Computes closest point on line to a given point. Parameters ---------- point : sequence of float XYZ coordinates. line : tuple Two points defining the line. Returns ------- list XYZ coordinates of closest point. Examples -------- >>> See Also -------- :func:`compas.geometry.transformations.project_point_line` """ a, b = line ab = subtract_vectors(b, a) ap = subtract_vectors(point, a) c = vector_component(ap, ab) return add_vectors(a, c)
def project_point_line(point, line): """Project a point onto a line. Parameters: point (sequence of float): XYZ coordinates. line (tuple): Two points defining a line. Returns: list: XYZ coordinates of the projected point. References: https://en.wikibooks.org/wiki/Linear_Algebra/Orthogonal_Projection_Onto_a_Line """ a, b = line ab = subtract_vectors(b, a) ap = subtract_vectors(point, a) c = vector_component(ap, ab) return add_vectors(a, c)