Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

3D Perpendicular Point on Line From 3D point

Tags:

c#

math

geometry

3d

This question has been asked before in reference to 2D. This question extends it to 3D. How do I find the perpendicular intersected point on a line from a point in 3D space?. If my line is defined by points (x1,y1,z1) & (x2,y2,z2) and I have a point (x3,y3,z3) in space.

How do I find the perpendicular intersection of point (x4,y4,z4) on the line from (x3,y3,z3)?

like image 753
user1222017 Avatar asked Feb 20 '12 21:02

user1222017


People also ask

How do you find the perpendicular distance from a point to a 3d line?

The perpendicular distance between a point and a line is the shortest distance between these two objects. In three dimensions, the perpendicular distance, ๐ท , between a point ๐‘ƒ ( ๐‘ฅ , ๐‘ฆ , ๐‘ง ) ๏Šง ๏Šง ๏Šง and a line with direction vector โƒ‘ ๐‘‘ is given by ๐ท = โ€– โ€– ๏ƒŸ ๐ด ๐‘ƒ ร— โƒ‘ ๐‘‘ โ€– โ€– โ€– โ€– โƒ‘ ๐‘‘ โ€– โ€– , where ๐ด is any point on the line.

How do you find the perpendicular distance from a point to a line?

Perpendicular Distance of a Point From a LineStep 1: Consider a line L : Ax + By + C = 0 whose distance from the point P (x1, y1) is d. Step 2: Draw a perpendicular PM from the point P to the line L as shown in the figure below. Step 3: Let Q and R be the points where the line meets the x-and y-axes, respectively.

How do you find the image of a point with respect to a line in 3d?

find the coords of the point of intersection of the two lines. The image of a point from a line is the same distance from the line as the point itself. So, we can use the mid-point formula of a line segment, solving for xโ€ฒ,yโ€ฒ, and zโ€ฒ where xโ€ฒ,yโ€ฒ, and zโ€ฒ are coords of the image.

Where is the closest point on a line to the origin 3d?

The nearest point to the origin will lie on some line through the origin that's perpendicular to the given line, i.e., that r(t)โ‹…(9,4,5)=0. This is a simple linear equation in t to be solved. Equivalently, find the point at which the given line intersects its perpendicular plane through the origin.


2 Answers

For starters, you pretty much need some implementation of a Vector3 class, whether you write your own, find a standalone implementation on the internet somewhere, or use a library that contains one like XNA or Sharp3D.Math.

Typically lines in 3d space are not represented by two points, but by parametric equations and operated on by vectors and not scalars. Your parametric equation would be of the form:

x = x1 + t(x2-x1), y = y1 + t(y2-y1), z = z1 + t(z2-z1)

The vector u is defined by the coefficients of t. <x2-x1, y2-y1, z2-z1>.

The vector PQ is defined by your chosen point Q minus a point P on the line. Any point on the line can be chosen, so it would be simplest to just use the line t = 0, which simplifies to x1, y1, and z1. <x3-x1, y3-y1, z3-z1>

The definition of the shortest distance between a point and a line in 3-space is as follows:

D = ||PQ x u|| / ||u||

Where x is the cross product operator, and || ... || gets the magnitude of the contained vector. Depending on which library you choose, your code may vary, but it should be very similar:

Vector3 u = new Vector3(x2 - x1, y2 - y1, z2 - z1);
Vector3 pq = new Vector3(x3 - x1, y3 - y1, z3 - z1);

float distance = Vector3.Cross(pq, u).Length / u.Length;

Edit: I just realized you wanted the actual point of intersection, and not the distance. The formula to find the actual point is a bit different. You need to use inner product space to get the component of u perpendicular to PQ. To do that, you need to find the component of u in the direction of PQ:

((PQ ยท u) / ||u||^2) * u

This gets us the w1 component, but we want w2, which is the component between Q and the line:

PQ = w1 + w2

w2 = PQ - w1

From there, we take w2 and add it to the point Q to get the point on the line nearest Q. In code this would be:

Vector3 p1 = new Vector3(x1, y1, z1);
Vector3 p2 = new Vector3(x2, y2, z2);
Vector3 q = new Vector3(x3, y3, z3);

Vector3 u = p2 - p1;
Vector3 pq = q - p1;
Vector3 w2 = pq - Vector3.Multiply(u, Vector3.Dot(pq, u) / u.LengthSquared);

Vector3 point = q - w2;

Where point.X is x4, point.Y is y4, and point.Z is z4.

like image 91
Robert Rouhani Avatar answered Sep 22 '22 17:09

Robert Rouhani


You're asking, in practice, the calculation of a distance between the point and line, so the Length of the vector from the (x3,y3,z3) point to the line which is orthogonal to the vector. If we immagine the line like a vector, that means that dot-product of both vectors is equal to 0. (this is just to give you a hint) .

like image 41
Tigran Avatar answered Sep 22 '22 17:09

Tigran