#How to go about projecting a point onto a line using a direction!

3 messages · Page 1 of 1 (latest)

surreal jetty
#

Essentially I got this function

func project_point_on_line(P : Vector3, A : Vector3, B : Vector3) -> Vector3:

var line_direction = B - A
var line_length = line_direction.length()
line_direction = line_direction.normalized()

var change = P-A

var project_length : float = clampf(
    change.dot(line_direction), 0, line_length)

return A + line_direction*project_length

But it returns the closest point on a line, I need a function that looks something more like this

func project_point_on_line(P : Vector3, A : Vector3, B : Vector3, Project_Dir : Vector3) -> Vector3:
# returns the point on the line

So it'd return a point on the line thats in that general direction.
Help on this issue would be very appriciated!

void plover
#

I don't remember the formula stuff offhand, but I can at least get you started on the right track. What you're looking for isn't projecting a point onto a line, what you're trying to do is find the intersection of two lines.

meager plinth
#

https://en.m.wikipedia.org/wiki/Line–line_intersection#Given_two_points_on_each_line_segment

Here are some semi-ready-to-use formulas to find the intersection, if there is any.

In Euclidean geometry, the intersection of a line and a line can be the empty set, a point, or another line. Distinguishing these cases and finding the intersection have uses, for example, in computer graphics, motion planning, and collision detection.
In three-dimensional Euclidean geometry, if two lines are not in the same plane, they have no ...