Putting a point inside a triangle in 3D space

Click For Summary

Discussion Overview

The discussion revolves around the problem of determining the position of a point within a triangle defined by three points in 3D space. Participants explore methods for calculating the y-coordinate of a point given its x- and z-coordinates, as well as how to maintain the relative position of that point if the triangle is moved. The conversation includes mathematical reasoning and potential algorithms for solving these geometric problems.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant suggests using a determinant of a 4x4 matrix to find the coefficients for the plane equation, expressing concern about its efficiency.
  • Another participant proposes using displacement vectors between the triangle's vertices to define the edges and calculate the plane's normal vector through the cross product.
  • A later reply emphasizes that the equation of the plane can be used to check if a point lies within it by substituting its coordinates into the plane's equation.
  • Some participants discuss the implications of the triangle being aligned with the y-axis, noting that this could lead to a lack of unique solutions for the y-coordinate.
  • There is a suggestion to express the point in terms of barycentric coordinates to maintain its relative position within the triangle as it moves.
  • One participant expresses appreciation for the insights shared, indicating a realization of their own understanding of the problem.
  • Another participant questions the conclusion drawn from the vector addition, prompting further exploration of the geometric relationships involved.

Areas of Agreement / Disagreement

Participants generally agree on the methods to calculate the y-coordinate and check the point's position relative to the triangle, but there are differing opinions on the efficiency and elegance of various approaches. The discussion remains unresolved regarding the most optimal method and the implications of special cases like alignment with the y-axis.

Contextual Notes

Some limitations are noted, such as the potential for non-unique solutions when the triangle is aligned with the y-axis and the need for additional checks to confirm that the point lies within the triangle.

wukunlin
Gold Member
Messages
479
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   Reactions: 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   Reactions: 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   Reactions: 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   Reactions: 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   Reactions: WWGD

Similar threads

  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
17
Views
3K