Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

I Putting a point inside a triangle in 3D space

  1. Dec 7, 2017 #1


    User Avatar
    Gold Member

    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?
  2. jcsd
  3. Dec 7, 2017 #2


    Staff: Mentor

    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?
  4. Dec 7, 2017 #3


    Staff: Mentor

    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.
  5. Dec 7, 2017 #4


    User Avatar
    Science Advisor
    Gold Member

    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.
  6. Dec 7, 2017 #5


    User Avatar
    2017 Award

    Staff: Mentor

    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.
  7. Dec 8, 2017 #6


    User Avatar
    Gold Member

    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.

    That worked beautifully!! Thank you :biggrin:

    Thanks for the help. Looks like great minds think alike :woot:

    Oh wow, that does look a LOT more elegant.

    Drawing that final vector from P2 will end up somewhere inside the triangle right?
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted