Undergrad Putting a point inside a triangle in 3D space

Click For Summary
To compute the y-coordinate of a point p4 in a plane defined by three points in 3D space, one efficient method involves using the cross product of vectors formed by the triangle's edges to derive the plane's equation. Once the plane is established, substituting the known x and z coordinates allows for solving the linear equation to find y. To maintain the relative position of p4 as the triangle moves, it can be expressed in terms of the triangle's vertices and the parameters a and b, which represent the barycentric coordinates. This method also facilitates checking if p4 lies within the triangle by ensuring the conditions on a and b are met. Overall, this approach provides a more elegant solution than using a determinant of a matrix.
wukunlin
Gold Member
Messages
478
Reaction score
117
This may belong to the computing subforum, let me know if this is more true than having it here in the math forum :)

My questions are
1) Suppose there is a plane in 3D space and I have 3 points to define it:
p1 = {x1, y1, z1}
p2 = {x2, y2, z2}
p3 = {x3, y3, z3}

and I want to put a particular point p4 which I already know the x- and z- coordinates.
What will be the most efficient way to compute the y- coordinate of p4?
I can think of the nasty method which I compute the determinant of a 4x4 matrix to find the coefficients for:
ax + by + cz + z = 0
Then substitute my known x and z, I get the feeling this is very inefficient and there are more elegant solutions than this. Are there any known algorithms to deal with this problem?

2) Now that I have my p4, I want have the same relative position to the 3 points p1, p2, p3 if someone move this triangle around:
f(p1, p2, p3) = p4
for example, if p4 happens to be in the middle of the triangle, the function would be the average of each of the x, y, z coordinates of the 3 points. But for a point that is off-centered, how will I go about finding what this function should be?
 
Mathematics news on Phys.org
so you have three points represented by three position vectors. If you subtract p1-p2 and p3-p2 then you have two vectors that describe the edges of the triangle right? If you then add them and divide the resultant vector by some value > 2 then what can you conclude?
 
  • Like
Likes wukunlin
It's possible there are more efficient ways, but here is a straightforward way. If you have three points in a plane ##P_1, P_2, P_3##, find displacement vectors between any two pairs of them, say, ##\vec u = \vec{P_1P_2}## and ##\vec v = \vec{P_1P_3}##.
Calculate the cross product ##\vec n = \vec u \times \vec v## = <A, B, C>
The equation of the plane will be ##A(x - x_1) + B(y - y_1) + C(z - z_1) = 0##, where I arbitrarily chose the coordinates of point ##P_1##. You could use the coordinates of either of the other two given points -- it doesn't matter.
Now that you have the equation of the plane, it's a simple matter to check whether some point ##P_4 = (x_4, y_4, z_4)## lies in the plane by substituting these coordinates for x, y, and z respectively in the plane's equation.
 
  • Like
Likes wukunlin and jedishrfu
wukunlin said:
This may belong to the computing subforum, let me know if this is more true than having it here in the math forum :)

My questions are
1) Suppose there is a plane in 3D space and I have 3 points to define it:
p1 = {x1, y1, z1}
p2 = {x2, y2, z2}
p3 = {x3, y3, z3}

and I want to put a particular point p4 which I already know the x- and z- coordinates.
What will be the most efficient way to compute the y- coordinate of p4?
I can think of the nasty method which I compute the determinant of a 4x4 matrix to find the coefficients for:
ax + by + cz + z = 0
Then substitute my known x and z, I get the feeling this is very inefficient and there are more elegant solutions than this. Are there any known algorithms to deal with this problem?

2) Now that I have my p4, I want have the same relative position to the 3 points p1, p2, p3 if someone move this triangle around:
f(p1, p2, p3) = p4
for example, if p4 happens to be in the middle of the triangle, the function would be the average of each of the x, y, z coordinates of the 3 points. But for a point that is off-centered, how will I go about finding what this function should be?

I am not sure I understand, the equation of a plane in 3-space is : ## ax+by+cz=d ##. Once you do the cross-product and have any of these points, you will have all of a,b,c and d given. You only need to solve for y from a linear relation. EDIT: Essentially a rewording of what Mark44 said.
 
  • Like
Likes wukunlin
If your triangle is aligned with the y-axis there is no unique solution, but if we know we don't have this special case:

To just find the third coordinate, set up the plane as described in the previous posts, this gives a linear equation to solve. Note: It doesn't guarantee you that the point is actually within the triangle.

To (a) check that the point is indeed inside and (b) make the triangle movable, I would take a slightly different approach.
With ##\vec u## and ##\vec v## defined as in post 3, the point 4 can be expressed as ##p_4 = p_1 + a \vec u + b \vec v## where ##a,b \geq 0## and ##a+b \leq 1##. If you consider the x and z coordinate of this equation you get two equations with two unknowns (a and b). Solve, and you can calculate the missing y coordinate. You can also check if the point is really within the triangle by checking the inequalities mentioned before. Shifting the triangle just changes ##p_1, \vec u, \vec v## so you can use the same a and b to find the new point 4.
 
  • Like
Likes wukunlin
I really appreciate all the help everyone. It made me realize how rusty the gears of my brain has gotten after years of not doing problems like these.

mfb said:
If your triangle is aligned with the y-axis there is no unique solution, but if we know we don't have this special case:

To just find the third coordinate, set up the plane as described in the previous posts, this gives a linear equation to solve. Note: It doesn't guarantee you that the point is actually within the triangle.

To (a) check that the point is indeed inside and (b) make the triangle movable, I would take a slightly different approach.
With ##\vec u## and ##\vec v## defined as in post 3, the point 4 can be expressed as ##p_4 = p_1 + a \vec u + b \vec v## where ##a,b \geq 0## and ##a+b \leq 1##. If you consider the x and z coordinate of this equation you get two equations with two unknowns (a and b). Solve, and you can calculate the missing y coordinate. You can also check if the point is really within the triangle by checking the inequalities mentioned before. Shifting the triangle just changes ##p_1, \vec u, \vec v## so you can use the same a and b to find the new point 4.
That worked beautifully! Thank you :biggrin:

WWGD said:
I am not sure I understand, the equation of a plane in 3-space is : ## ax+by+cz=d ##. Once you do the cross-product and have any of these points, you will have all of a,b,c and d given. You only need to solve for y from a linear relation. EDIT: Essentially a rewording of what Mark44 said.
Thanks for the help. Looks like great minds think alike :woot:

Mark44 said:
It's possible there are more efficient ways, but here is a straightforward way. If you have three points in a plane ##P_1, P_2, P_3##, find displacement vectors between any two pairs of them, say, ##\vec u = \vec{P_1P_2}## and ##\vec v = \vec{P_1P_3}##.
Calculate the cross product ##\vec n = \vec u \times \vec v## = <A, B, C>
The equation of the plane will be ##A(x - x_1) + B(y - y_1) + C(z - z_1) = 0##, where I arbitrarily chose the coordinates of point ##P_1##. You could use the coordinates of either of the other two given points -- it doesn't matter.
Now that you have the equation of the plane, it's a simple matter to check whether some point ##P_4 = (x_4, y_4, z_4)## lies in the plane by substituting these coordinates for x, y, and z respectively in the plane's equation.
Oh wow, that does look a LOT more elegant.

jedishrfu said:
so you have three points represented by three position vectors. If you subtract p1-p2 and p3-p2 then you have two vectors that describe the edges of the triangle right? If you then add them and divide the resultant vector by some value > 2 then what can you conclude?
Drawing that final vector from P2 will end up somewhere inside the triangle right?
 
  • Like
Likes WWGD
Good morning I have been refreshing my memory about Leibniz differentiation of integrals and found some useful videos from digital-university.org on YouTube. Although the audio quality is poor and the speaker proceeds a bit slowly, the explanations and processes are clear. However, it seems that one video in the Leibniz rule series is missing. While the videos are still present on YouTube, the referring website no longer exists but is preserved on the internet archive...

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
1K
  • · Replies 6 ·
Replies
6
Views
3K