Putting a point inside a triangle in 3D space

In summary: To find the missing y-coordinate, you can use the x and z coordinates of this equation to create two linear equations with two unknowns (a and b). Solving these equations will give you the value of y. To check if the point is within the triangle, you can use the inequalities mentioned before. Shifting the triangle will only change the values of ##p_1, \vec u, \vec v##, so you can use the same values of a and b to find the new point 4.In
  • #1
wukunlin
Gold Member
480
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
  • #2
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
  • #3
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
  • #4
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
  • #5
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
  • #6
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

1. How do you determine if a point is inside a triangle in 3D space?

To determine if a point is inside a triangle in 3D space, you can use the following method:

  • Calculate the normal vector of the triangle using the cross product of two of its sides.
  • Calculate the dot product of the normal vector and the vector from one of the triangle's vertices to the point in question.
  • If the dot product is positive, the point is on the same side of the triangle as the normal vector and is outside the triangle. If it is negative, the point is on the opposite side and is inside the triangle.

2. Can a point be inside a triangle but not in the same plane?

No, a point cannot be inside a triangle but not in the same plane. A triangle and a point in 3D space must lie on the same plane in order for the point to be considered inside the triangle.

3. What happens if the point lies on one of the triangle's edges?

If the point lies on one of the triangle's edges, it is considered to be inside the triangle. This is because the point is still within the boundaries of the triangle's plane, and the method for determining if a point is inside the triangle considers points on the edges to be inside.

4. Can a point be inside a triangle if it is outside of the triangle's boundaries?

No, a point cannot be inside a triangle if it is outside of the triangle's boundaries. The method for determining if a point is inside a triangle takes into account the boundaries of the triangle and considers points outside of those boundaries to be outside of the triangle.

5. How does this method differ from determining if a point is inside a triangle in 2D space?

The method for determining if a point is inside a triangle in 3D space is similar to the method for 2D space, but it takes into account the third dimension. In 2D space, the triangle and point must lie on the same plane, while in 3D space, they must also be in the same plane and the same side of the plane. Additionally, in 3D space, the normal vector is used to determine the orientation of the triangle, while in 2D space, the winding order of the vertices is used.

Similar threads

  • General Math
Replies
3
Views
803
Replies
1
Views
994
Replies
1
Views
4K
  • General Math
Replies
3
Views
2K
Replies
8
Views
3K
Replies
7
Views
777
Replies
6
Views
2K
  • Precalculus Mathematics Homework Help
Replies
17
Views
877
Replies
2
Views
2K
Back
Top