Can you compute line segment that crosses a triangle?












0












$begingroup$


I have a triangle with corner vertices (x1, y1, z1), (x2, y2, z2), (x3, y3, z3). I also have a height H which is between min(z1, z2, z3) and max(z1, z2, z3) and I'm looking to find the coordinates of the line segment that crosses the triangle horizontally and has height H. Here's a little diagram:



https://www.dropbox.com/s/y3527zf1916yfss/Screenshot%202018-12-06%2015.41.09.png?dl=0



Context: I have mesh of triangles and am trying to draw the contour at a certain height H. I've found the triangles that the contour lines passes through, but not sure how to find the specific lines through each triangle.










share|cite|improve this question









$endgroup$












  • $begingroup$
    Linear interpolation using the endpoints of the three sides will give you the endpoints of the segment.
    $endgroup$
    – amd
    Dec 7 '18 at 0:59
















0












$begingroup$


I have a triangle with corner vertices (x1, y1, z1), (x2, y2, z2), (x3, y3, z3). I also have a height H which is between min(z1, z2, z3) and max(z1, z2, z3) and I'm looking to find the coordinates of the line segment that crosses the triangle horizontally and has height H. Here's a little diagram:



https://www.dropbox.com/s/y3527zf1916yfss/Screenshot%202018-12-06%2015.41.09.png?dl=0



Context: I have mesh of triangles and am trying to draw the contour at a certain height H. I've found the triangles that the contour lines passes through, but not sure how to find the specific lines through each triangle.










share|cite|improve this question









$endgroup$












  • $begingroup$
    Linear interpolation using the endpoints of the three sides will give you the endpoints of the segment.
    $endgroup$
    – amd
    Dec 7 '18 at 0:59














0












0








0





$begingroup$


I have a triangle with corner vertices (x1, y1, z1), (x2, y2, z2), (x3, y3, z3). I also have a height H which is between min(z1, z2, z3) and max(z1, z2, z3) and I'm looking to find the coordinates of the line segment that crosses the triangle horizontally and has height H. Here's a little diagram:



https://www.dropbox.com/s/y3527zf1916yfss/Screenshot%202018-12-06%2015.41.09.png?dl=0



Context: I have mesh of triangles and am trying to draw the contour at a certain height H. I've found the triangles that the contour lines passes through, but not sure how to find the specific lines through each triangle.










share|cite|improve this question









$endgroup$




I have a triangle with corner vertices (x1, y1, z1), (x2, y2, z2), (x3, y3, z3). I also have a height H which is between min(z1, z2, z3) and max(z1, z2, z3) and I'm looking to find the coordinates of the line segment that crosses the triangle horizontally and has height H. Here's a little diagram:



https://www.dropbox.com/s/y3527zf1916yfss/Screenshot%202018-12-06%2015.41.09.png?dl=0



Context: I have mesh of triangles and am trying to draw the contour at a certain height H. I've found the triangles that the contour lines passes through, but not sure how to find the specific lines through each triangle.







geometry triangle






share|cite|improve this question













share|cite|improve this question











share|cite|improve this question




share|cite|improve this question










asked Dec 6 '18 at 23:41









nickponlinenickponline

240110




240110












  • $begingroup$
    Linear interpolation using the endpoints of the three sides will give you the endpoints of the segment.
    $endgroup$
    – amd
    Dec 7 '18 at 0:59


















  • $begingroup$
    Linear interpolation using the endpoints of the three sides will give you the endpoints of the segment.
    $endgroup$
    – amd
    Dec 7 '18 at 0:59
















$begingroup$
Linear interpolation using the endpoints of the three sides will give you the endpoints of the segment.
$endgroup$
– amd
Dec 7 '18 at 0:59




$begingroup$
Linear interpolation using the endpoints of the three sides will give you the endpoints of the segment.
$endgroup$
– amd
Dec 7 '18 at 0:59










1 Answer
1






active

oldest

votes


















1












$begingroup$

Let
$$bbox{
vec{v}_1 = left [ begin{matrix} x_1 \ y_1 \ z_1 end{matrix} right ]
} quad text{and} quad bbox{
vec{v}_2 = left [ begin{matrix} x_2 \ y_2 \ z_2 end{matrix} right ]
} , quad bbox{
z_1 lt z lt z_2
}$$

then the contour at $z$ intersects the line segment between $vec{v}_1$ and $vec{v}_2$ at $vec{p}$,
$$bbox{
vec{p} = frac{z_2 - z}{z_2 - z_1}vec{v}_1 + frac{z - z_1}{z_2 - z_1}vec{v}_2
}$$



In a triangle with vertices $vec{v}_1$, $vec{v}_2$, and $vec{v}_3$, with $min(z_1 , z_2 , z_3) lt z lt max(z_1 , z_2 , z_3)$ there are exactly two such intersections; draw the line between those.



If we use $vec{e}_{12}$ for the intersection point between vertices $vec{v}_1$ and $vec{v}_2$, $vec{e}_{13}$ for the intersection point between vertices $vec{v}_1$ and $vec{v}_3$, and $vec{e}_{23}$ for the intersection point between vertices $vec{v}_2$ and $vec{v}_2$, calculated using the above formula for $vec{p}$ for each respective pair of vertices, the complete table of possible cases is
$$begin{array}{c|c|c|c}
z_1 & z_2 & z_3 & z text{ contour line or (point) } \
hline
z_1 lt z & z_2 lt z & z_3 lt z & text{None} \
z_1 = z & z_2 lt z & z_3 lt z & (vec{v}_1) \
z_1 gt z & z_2 lt z & z_3 lt z & vec{e}_{12} - vec{e}_{13} \
z_1 lt z & z_2 = z & z_3 lt z & (vec{v}_2) \
z_1 = z & z_2 = z & z_3 lt z & vec{v}_1 - vec{v}_2 \
z_1 gt z & z_2 = z & z_3 lt z & vec{v}_2 - vec{e}_{13} \
z_1 lt z & z_2 gt z & z_3 lt z & vec{e}_{12} - vec{e}_{23} \
z_1 = z & z_2 gt z & z_3 lt z & vec{v}_1 - vec{e}_{23} \
z_1 gt z & z_2 gt z & z_3 lt z & vec{e}_{13} - vec{e}_{23} \
z_1 lt z & z_2 lt z & z_3 = z & (vec{v}_3) \
z_1 = z & z_2 lt z & z_3 = z & vec{v}_1 - vec{v}_3 \
z_1 gt z & z_2 lt z & z_3 = z & vec{v}_3 - vec{e}_{12} \
z_1 lt z & z_2 = z & z_3 = z & vec{v}_2 - vec{v}_3 \
z_1 = z & z_2 = z & z_3 = z & text{ Entire triangle } \
z_1 gt z & z_2 = z & z_3 = z & vec{v}_2 - vec{v}_3 \
z_1 lt z & z_2 gt z & z_3 = z & vec{v}_3 - vec{e}_{12} \
z_1 = z & z_2 gt z & z_3 = z & vec{v}_1 - vec{v}_3 \
z_1 gt z & z_2 gt z & z_3 = z & (vec{v}_3) \
z_1 lt z & z_2 lt z & z_3 gt z & vec{e}_{13} - vec{e}_{23} \
z_1 = z & z_2 lt z & z_3 gt z & vec{v}_1 - vec{e}_{23} \
z_1 gt z & z_2 lt z & z_3 gt z & vec{e}_{12} - vec{e}_{23} \
z_1 lt z & z_2 = z & z_3 gt z & vec{v}_2 - vec{e}_{13} \
z_1 = z & z_2 = z & z_3 gt z & vec{v}_1 - vec{v}_2 \
z_1 gt z & z_2 = z & z_3 gt z & (vec{v}_2) \
z_1 lt z & z_2 gt z & z_3 gt z & vec{e}_{12} - vec{e}_{13} \
z_1 = z & z_2 gt z & z_3 gt z & (vec{v}_1) \
z_1 gt z & z_2 gt z & z_3 gt z & text{None} \
end{array}$$

There is absolutely nothing surprising in the table.



In practice, you can implement pseudocode similar to



Function z_contour(x1, y1, z1, x2, y2, z2, x3, y3, z3, z)
Let x = [0, 0, 0]
Let y = [0, 0, 0]
Let n = 0

If z1 == z:
x[n] = x1
y[n] = y1
n = n + 1

If z2 == z:
x[n] = x2
y[n] = y2
n = n + 1

If z3 == z:
x[n] = x3
y[n] = y3
n = n + 1

If (z1 < z and z2 > z) or (z1 > z and z2 < z):
x[n] = ( (z2 - z)*x1 + (z - z1)*x2 ) / (z2 - z1)
y[n] = ( (z2 - z)*y1 + (z - z1)*y2 ) / (z2 - z1)
n = n + 1

If (z1 < z and z3 > z) or (z1 > z and z3 < z):
x[n] = ( (z3 - z)*x1 + (z - z1)*x3 ) / (z3 - z1)
y[n] = ( (z3 - z)*y1 + (z - z1)*y3 ) / (z3 - z1)
n = n + 1

If (z2 < z and z3 > z) or (z2 > z and z3 < z):
x[n] = ( (z3 - z)*x2 + (z - z2)*x3 ) / (z3 - z2)
y[n] = ( (z3 - z)*y2 + (z - z2)*y3 ) / (z3 - z2)
n = n + 1

If n == 0:
Return (None)
Else
If n == 1:
Return Point(x[0], y[0], z)
Else
If n == 2:
Return Line(x[0], y[0], z, x[1], y[1], z)
Else:
Return Triangle(x1, y1, z, x2, y2, z, x3, y3, z)

End Function


to compute the intersection of the contour $z$ and the triangle.






share|cite|improve this answer









$endgroup$













    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "69"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    noCode: true, onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3029224%2fcan-you-compute-line-segment-that-crosses-a-triangle%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1












    $begingroup$

    Let
    $$bbox{
    vec{v}_1 = left [ begin{matrix} x_1 \ y_1 \ z_1 end{matrix} right ]
    } quad text{and} quad bbox{
    vec{v}_2 = left [ begin{matrix} x_2 \ y_2 \ z_2 end{matrix} right ]
    } , quad bbox{
    z_1 lt z lt z_2
    }$$

    then the contour at $z$ intersects the line segment between $vec{v}_1$ and $vec{v}_2$ at $vec{p}$,
    $$bbox{
    vec{p} = frac{z_2 - z}{z_2 - z_1}vec{v}_1 + frac{z - z_1}{z_2 - z_1}vec{v}_2
    }$$



    In a triangle with vertices $vec{v}_1$, $vec{v}_2$, and $vec{v}_3$, with $min(z_1 , z_2 , z_3) lt z lt max(z_1 , z_2 , z_3)$ there are exactly two such intersections; draw the line between those.



    If we use $vec{e}_{12}$ for the intersection point between vertices $vec{v}_1$ and $vec{v}_2$, $vec{e}_{13}$ for the intersection point between vertices $vec{v}_1$ and $vec{v}_3$, and $vec{e}_{23}$ for the intersection point between vertices $vec{v}_2$ and $vec{v}_2$, calculated using the above formula for $vec{p}$ for each respective pair of vertices, the complete table of possible cases is
    $$begin{array}{c|c|c|c}
    z_1 & z_2 & z_3 & z text{ contour line or (point) } \
    hline
    z_1 lt z & z_2 lt z & z_3 lt z & text{None} \
    z_1 = z & z_2 lt z & z_3 lt z & (vec{v}_1) \
    z_1 gt z & z_2 lt z & z_3 lt z & vec{e}_{12} - vec{e}_{13} \
    z_1 lt z & z_2 = z & z_3 lt z & (vec{v}_2) \
    z_1 = z & z_2 = z & z_3 lt z & vec{v}_1 - vec{v}_2 \
    z_1 gt z & z_2 = z & z_3 lt z & vec{v}_2 - vec{e}_{13} \
    z_1 lt z & z_2 gt z & z_3 lt z & vec{e}_{12} - vec{e}_{23} \
    z_1 = z & z_2 gt z & z_3 lt z & vec{v}_1 - vec{e}_{23} \
    z_1 gt z & z_2 gt z & z_3 lt z & vec{e}_{13} - vec{e}_{23} \
    z_1 lt z & z_2 lt z & z_3 = z & (vec{v}_3) \
    z_1 = z & z_2 lt z & z_3 = z & vec{v}_1 - vec{v}_3 \
    z_1 gt z & z_2 lt z & z_3 = z & vec{v}_3 - vec{e}_{12} \
    z_1 lt z & z_2 = z & z_3 = z & vec{v}_2 - vec{v}_3 \
    z_1 = z & z_2 = z & z_3 = z & text{ Entire triangle } \
    z_1 gt z & z_2 = z & z_3 = z & vec{v}_2 - vec{v}_3 \
    z_1 lt z & z_2 gt z & z_3 = z & vec{v}_3 - vec{e}_{12} \
    z_1 = z & z_2 gt z & z_3 = z & vec{v}_1 - vec{v}_3 \
    z_1 gt z & z_2 gt z & z_3 = z & (vec{v}_3) \
    z_1 lt z & z_2 lt z & z_3 gt z & vec{e}_{13} - vec{e}_{23} \
    z_1 = z & z_2 lt z & z_3 gt z & vec{v}_1 - vec{e}_{23} \
    z_1 gt z & z_2 lt z & z_3 gt z & vec{e}_{12} - vec{e}_{23} \
    z_1 lt z & z_2 = z & z_3 gt z & vec{v}_2 - vec{e}_{13} \
    z_1 = z & z_2 = z & z_3 gt z & vec{v}_1 - vec{v}_2 \
    z_1 gt z & z_2 = z & z_3 gt z & (vec{v}_2) \
    z_1 lt z & z_2 gt z & z_3 gt z & vec{e}_{12} - vec{e}_{13} \
    z_1 = z & z_2 gt z & z_3 gt z & (vec{v}_1) \
    z_1 gt z & z_2 gt z & z_3 gt z & text{None} \
    end{array}$$

    There is absolutely nothing surprising in the table.



    In practice, you can implement pseudocode similar to



    Function z_contour(x1, y1, z1, x2, y2, z2, x3, y3, z3, z)
    Let x = [0, 0, 0]
    Let y = [0, 0, 0]
    Let n = 0

    If z1 == z:
    x[n] = x1
    y[n] = y1
    n = n + 1

    If z2 == z:
    x[n] = x2
    y[n] = y2
    n = n + 1

    If z3 == z:
    x[n] = x3
    y[n] = y3
    n = n + 1

    If (z1 < z and z2 > z) or (z1 > z and z2 < z):
    x[n] = ( (z2 - z)*x1 + (z - z1)*x2 ) / (z2 - z1)
    y[n] = ( (z2 - z)*y1 + (z - z1)*y2 ) / (z2 - z1)
    n = n + 1

    If (z1 < z and z3 > z) or (z1 > z and z3 < z):
    x[n] = ( (z3 - z)*x1 + (z - z1)*x3 ) / (z3 - z1)
    y[n] = ( (z3 - z)*y1 + (z - z1)*y3 ) / (z3 - z1)
    n = n + 1

    If (z2 < z and z3 > z) or (z2 > z and z3 < z):
    x[n] = ( (z3 - z)*x2 + (z - z2)*x3 ) / (z3 - z2)
    y[n] = ( (z3 - z)*y2 + (z - z2)*y3 ) / (z3 - z2)
    n = n + 1

    If n == 0:
    Return (None)
    Else
    If n == 1:
    Return Point(x[0], y[0], z)
    Else
    If n == 2:
    Return Line(x[0], y[0], z, x[1], y[1], z)
    Else:
    Return Triangle(x1, y1, z, x2, y2, z, x3, y3, z)

    End Function


    to compute the intersection of the contour $z$ and the triangle.






    share|cite|improve this answer









    $endgroup$


















      1












      $begingroup$

      Let
      $$bbox{
      vec{v}_1 = left [ begin{matrix} x_1 \ y_1 \ z_1 end{matrix} right ]
      } quad text{and} quad bbox{
      vec{v}_2 = left [ begin{matrix} x_2 \ y_2 \ z_2 end{matrix} right ]
      } , quad bbox{
      z_1 lt z lt z_2
      }$$

      then the contour at $z$ intersects the line segment between $vec{v}_1$ and $vec{v}_2$ at $vec{p}$,
      $$bbox{
      vec{p} = frac{z_2 - z}{z_2 - z_1}vec{v}_1 + frac{z - z_1}{z_2 - z_1}vec{v}_2
      }$$



      In a triangle with vertices $vec{v}_1$, $vec{v}_2$, and $vec{v}_3$, with $min(z_1 , z_2 , z_3) lt z lt max(z_1 , z_2 , z_3)$ there are exactly two such intersections; draw the line between those.



      If we use $vec{e}_{12}$ for the intersection point between vertices $vec{v}_1$ and $vec{v}_2$, $vec{e}_{13}$ for the intersection point between vertices $vec{v}_1$ and $vec{v}_3$, and $vec{e}_{23}$ for the intersection point between vertices $vec{v}_2$ and $vec{v}_2$, calculated using the above formula for $vec{p}$ for each respective pair of vertices, the complete table of possible cases is
      $$begin{array}{c|c|c|c}
      z_1 & z_2 & z_3 & z text{ contour line or (point) } \
      hline
      z_1 lt z & z_2 lt z & z_3 lt z & text{None} \
      z_1 = z & z_2 lt z & z_3 lt z & (vec{v}_1) \
      z_1 gt z & z_2 lt z & z_3 lt z & vec{e}_{12} - vec{e}_{13} \
      z_1 lt z & z_2 = z & z_3 lt z & (vec{v}_2) \
      z_1 = z & z_2 = z & z_3 lt z & vec{v}_1 - vec{v}_2 \
      z_1 gt z & z_2 = z & z_3 lt z & vec{v}_2 - vec{e}_{13} \
      z_1 lt z & z_2 gt z & z_3 lt z & vec{e}_{12} - vec{e}_{23} \
      z_1 = z & z_2 gt z & z_3 lt z & vec{v}_1 - vec{e}_{23} \
      z_1 gt z & z_2 gt z & z_3 lt z & vec{e}_{13} - vec{e}_{23} \
      z_1 lt z & z_2 lt z & z_3 = z & (vec{v}_3) \
      z_1 = z & z_2 lt z & z_3 = z & vec{v}_1 - vec{v}_3 \
      z_1 gt z & z_2 lt z & z_3 = z & vec{v}_3 - vec{e}_{12} \
      z_1 lt z & z_2 = z & z_3 = z & vec{v}_2 - vec{v}_3 \
      z_1 = z & z_2 = z & z_3 = z & text{ Entire triangle } \
      z_1 gt z & z_2 = z & z_3 = z & vec{v}_2 - vec{v}_3 \
      z_1 lt z & z_2 gt z & z_3 = z & vec{v}_3 - vec{e}_{12} \
      z_1 = z & z_2 gt z & z_3 = z & vec{v}_1 - vec{v}_3 \
      z_1 gt z & z_2 gt z & z_3 = z & (vec{v}_3) \
      z_1 lt z & z_2 lt z & z_3 gt z & vec{e}_{13} - vec{e}_{23} \
      z_1 = z & z_2 lt z & z_3 gt z & vec{v}_1 - vec{e}_{23} \
      z_1 gt z & z_2 lt z & z_3 gt z & vec{e}_{12} - vec{e}_{23} \
      z_1 lt z & z_2 = z & z_3 gt z & vec{v}_2 - vec{e}_{13} \
      z_1 = z & z_2 = z & z_3 gt z & vec{v}_1 - vec{v}_2 \
      z_1 gt z & z_2 = z & z_3 gt z & (vec{v}_2) \
      z_1 lt z & z_2 gt z & z_3 gt z & vec{e}_{12} - vec{e}_{13} \
      z_1 = z & z_2 gt z & z_3 gt z & (vec{v}_1) \
      z_1 gt z & z_2 gt z & z_3 gt z & text{None} \
      end{array}$$

      There is absolutely nothing surprising in the table.



      In practice, you can implement pseudocode similar to



      Function z_contour(x1, y1, z1, x2, y2, z2, x3, y3, z3, z)
      Let x = [0, 0, 0]
      Let y = [0, 0, 0]
      Let n = 0

      If z1 == z:
      x[n] = x1
      y[n] = y1
      n = n + 1

      If z2 == z:
      x[n] = x2
      y[n] = y2
      n = n + 1

      If z3 == z:
      x[n] = x3
      y[n] = y3
      n = n + 1

      If (z1 < z and z2 > z) or (z1 > z and z2 < z):
      x[n] = ( (z2 - z)*x1 + (z - z1)*x2 ) / (z2 - z1)
      y[n] = ( (z2 - z)*y1 + (z - z1)*y2 ) / (z2 - z1)
      n = n + 1

      If (z1 < z and z3 > z) or (z1 > z and z3 < z):
      x[n] = ( (z3 - z)*x1 + (z - z1)*x3 ) / (z3 - z1)
      y[n] = ( (z3 - z)*y1 + (z - z1)*y3 ) / (z3 - z1)
      n = n + 1

      If (z2 < z and z3 > z) or (z2 > z and z3 < z):
      x[n] = ( (z3 - z)*x2 + (z - z2)*x3 ) / (z3 - z2)
      y[n] = ( (z3 - z)*y2 + (z - z2)*y3 ) / (z3 - z2)
      n = n + 1

      If n == 0:
      Return (None)
      Else
      If n == 1:
      Return Point(x[0], y[0], z)
      Else
      If n == 2:
      Return Line(x[0], y[0], z, x[1], y[1], z)
      Else:
      Return Triangle(x1, y1, z, x2, y2, z, x3, y3, z)

      End Function


      to compute the intersection of the contour $z$ and the triangle.






      share|cite|improve this answer









      $endgroup$
















        1












        1








        1





        $begingroup$

        Let
        $$bbox{
        vec{v}_1 = left [ begin{matrix} x_1 \ y_1 \ z_1 end{matrix} right ]
        } quad text{and} quad bbox{
        vec{v}_2 = left [ begin{matrix} x_2 \ y_2 \ z_2 end{matrix} right ]
        } , quad bbox{
        z_1 lt z lt z_2
        }$$

        then the contour at $z$ intersects the line segment between $vec{v}_1$ and $vec{v}_2$ at $vec{p}$,
        $$bbox{
        vec{p} = frac{z_2 - z}{z_2 - z_1}vec{v}_1 + frac{z - z_1}{z_2 - z_1}vec{v}_2
        }$$



        In a triangle with vertices $vec{v}_1$, $vec{v}_2$, and $vec{v}_3$, with $min(z_1 , z_2 , z_3) lt z lt max(z_1 , z_2 , z_3)$ there are exactly two such intersections; draw the line between those.



        If we use $vec{e}_{12}$ for the intersection point between vertices $vec{v}_1$ and $vec{v}_2$, $vec{e}_{13}$ for the intersection point between vertices $vec{v}_1$ and $vec{v}_3$, and $vec{e}_{23}$ for the intersection point between vertices $vec{v}_2$ and $vec{v}_2$, calculated using the above formula for $vec{p}$ for each respective pair of vertices, the complete table of possible cases is
        $$begin{array}{c|c|c|c}
        z_1 & z_2 & z_3 & z text{ contour line or (point) } \
        hline
        z_1 lt z & z_2 lt z & z_3 lt z & text{None} \
        z_1 = z & z_2 lt z & z_3 lt z & (vec{v}_1) \
        z_1 gt z & z_2 lt z & z_3 lt z & vec{e}_{12} - vec{e}_{13} \
        z_1 lt z & z_2 = z & z_3 lt z & (vec{v}_2) \
        z_1 = z & z_2 = z & z_3 lt z & vec{v}_1 - vec{v}_2 \
        z_1 gt z & z_2 = z & z_3 lt z & vec{v}_2 - vec{e}_{13} \
        z_1 lt z & z_2 gt z & z_3 lt z & vec{e}_{12} - vec{e}_{23} \
        z_1 = z & z_2 gt z & z_3 lt z & vec{v}_1 - vec{e}_{23} \
        z_1 gt z & z_2 gt z & z_3 lt z & vec{e}_{13} - vec{e}_{23} \
        z_1 lt z & z_2 lt z & z_3 = z & (vec{v}_3) \
        z_1 = z & z_2 lt z & z_3 = z & vec{v}_1 - vec{v}_3 \
        z_1 gt z & z_2 lt z & z_3 = z & vec{v}_3 - vec{e}_{12} \
        z_1 lt z & z_2 = z & z_3 = z & vec{v}_2 - vec{v}_3 \
        z_1 = z & z_2 = z & z_3 = z & text{ Entire triangle } \
        z_1 gt z & z_2 = z & z_3 = z & vec{v}_2 - vec{v}_3 \
        z_1 lt z & z_2 gt z & z_3 = z & vec{v}_3 - vec{e}_{12} \
        z_1 = z & z_2 gt z & z_3 = z & vec{v}_1 - vec{v}_3 \
        z_1 gt z & z_2 gt z & z_3 = z & (vec{v}_3) \
        z_1 lt z & z_2 lt z & z_3 gt z & vec{e}_{13} - vec{e}_{23} \
        z_1 = z & z_2 lt z & z_3 gt z & vec{v}_1 - vec{e}_{23} \
        z_1 gt z & z_2 lt z & z_3 gt z & vec{e}_{12} - vec{e}_{23} \
        z_1 lt z & z_2 = z & z_3 gt z & vec{v}_2 - vec{e}_{13} \
        z_1 = z & z_2 = z & z_3 gt z & vec{v}_1 - vec{v}_2 \
        z_1 gt z & z_2 = z & z_3 gt z & (vec{v}_2) \
        z_1 lt z & z_2 gt z & z_3 gt z & vec{e}_{12} - vec{e}_{13} \
        z_1 = z & z_2 gt z & z_3 gt z & (vec{v}_1) \
        z_1 gt z & z_2 gt z & z_3 gt z & text{None} \
        end{array}$$

        There is absolutely nothing surprising in the table.



        In practice, you can implement pseudocode similar to



        Function z_contour(x1, y1, z1, x2, y2, z2, x3, y3, z3, z)
        Let x = [0, 0, 0]
        Let y = [0, 0, 0]
        Let n = 0

        If z1 == z:
        x[n] = x1
        y[n] = y1
        n = n + 1

        If z2 == z:
        x[n] = x2
        y[n] = y2
        n = n + 1

        If z3 == z:
        x[n] = x3
        y[n] = y3
        n = n + 1

        If (z1 < z and z2 > z) or (z1 > z and z2 < z):
        x[n] = ( (z2 - z)*x1 + (z - z1)*x2 ) / (z2 - z1)
        y[n] = ( (z2 - z)*y1 + (z - z1)*y2 ) / (z2 - z1)
        n = n + 1

        If (z1 < z and z3 > z) or (z1 > z and z3 < z):
        x[n] = ( (z3 - z)*x1 + (z - z1)*x3 ) / (z3 - z1)
        y[n] = ( (z3 - z)*y1 + (z - z1)*y3 ) / (z3 - z1)
        n = n + 1

        If (z2 < z and z3 > z) or (z2 > z and z3 < z):
        x[n] = ( (z3 - z)*x2 + (z - z2)*x3 ) / (z3 - z2)
        y[n] = ( (z3 - z)*y2 + (z - z2)*y3 ) / (z3 - z2)
        n = n + 1

        If n == 0:
        Return (None)
        Else
        If n == 1:
        Return Point(x[0], y[0], z)
        Else
        If n == 2:
        Return Line(x[0], y[0], z, x[1], y[1], z)
        Else:
        Return Triangle(x1, y1, z, x2, y2, z, x3, y3, z)

        End Function


        to compute the intersection of the contour $z$ and the triangle.






        share|cite|improve this answer









        $endgroup$



        Let
        $$bbox{
        vec{v}_1 = left [ begin{matrix} x_1 \ y_1 \ z_1 end{matrix} right ]
        } quad text{and} quad bbox{
        vec{v}_2 = left [ begin{matrix} x_2 \ y_2 \ z_2 end{matrix} right ]
        } , quad bbox{
        z_1 lt z lt z_2
        }$$

        then the contour at $z$ intersects the line segment between $vec{v}_1$ and $vec{v}_2$ at $vec{p}$,
        $$bbox{
        vec{p} = frac{z_2 - z}{z_2 - z_1}vec{v}_1 + frac{z - z_1}{z_2 - z_1}vec{v}_2
        }$$



        In a triangle with vertices $vec{v}_1$, $vec{v}_2$, and $vec{v}_3$, with $min(z_1 , z_2 , z_3) lt z lt max(z_1 , z_2 , z_3)$ there are exactly two such intersections; draw the line between those.



        If we use $vec{e}_{12}$ for the intersection point between vertices $vec{v}_1$ and $vec{v}_2$, $vec{e}_{13}$ for the intersection point between vertices $vec{v}_1$ and $vec{v}_3$, and $vec{e}_{23}$ for the intersection point between vertices $vec{v}_2$ and $vec{v}_2$, calculated using the above formula for $vec{p}$ for each respective pair of vertices, the complete table of possible cases is
        $$begin{array}{c|c|c|c}
        z_1 & z_2 & z_3 & z text{ contour line or (point) } \
        hline
        z_1 lt z & z_2 lt z & z_3 lt z & text{None} \
        z_1 = z & z_2 lt z & z_3 lt z & (vec{v}_1) \
        z_1 gt z & z_2 lt z & z_3 lt z & vec{e}_{12} - vec{e}_{13} \
        z_1 lt z & z_2 = z & z_3 lt z & (vec{v}_2) \
        z_1 = z & z_2 = z & z_3 lt z & vec{v}_1 - vec{v}_2 \
        z_1 gt z & z_2 = z & z_3 lt z & vec{v}_2 - vec{e}_{13} \
        z_1 lt z & z_2 gt z & z_3 lt z & vec{e}_{12} - vec{e}_{23} \
        z_1 = z & z_2 gt z & z_3 lt z & vec{v}_1 - vec{e}_{23} \
        z_1 gt z & z_2 gt z & z_3 lt z & vec{e}_{13} - vec{e}_{23} \
        z_1 lt z & z_2 lt z & z_3 = z & (vec{v}_3) \
        z_1 = z & z_2 lt z & z_3 = z & vec{v}_1 - vec{v}_3 \
        z_1 gt z & z_2 lt z & z_3 = z & vec{v}_3 - vec{e}_{12} \
        z_1 lt z & z_2 = z & z_3 = z & vec{v}_2 - vec{v}_3 \
        z_1 = z & z_2 = z & z_3 = z & text{ Entire triangle } \
        z_1 gt z & z_2 = z & z_3 = z & vec{v}_2 - vec{v}_3 \
        z_1 lt z & z_2 gt z & z_3 = z & vec{v}_3 - vec{e}_{12} \
        z_1 = z & z_2 gt z & z_3 = z & vec{v}_1 - vec{v}_3 \
        z_1 gt z & z_2 gt z & z_3 = z & (vec{v}_3) \
        z_1 lt z & z_2 lt z & z_3 gt z & vec{e}_{13} - vec{e}_{23} \
        z_1 = z & z_2 lt z & z_3 gt z & vec{v}_1 - vec{e}_{23} \
        z_1 gt z & z_2 lt z & z_3 gt z & vec{e}_{12} - vec{e}_{23} \
        z_1 lt z & z_2 = z & z_3 gt z & vec{v}_2 - vec{e}_{13} \
        z_1 = z & z_2 = z & z_3 gt z & vec{v}_1 - vec{v}_2 \
        z_1 gt z & z_2 = z & z_3 gt z & (vec{v}_2) \
        z_1 lt z & z_2 gt z & z_3 gt z & vec{e}_{12} - vec{e}_{13} \
        z_1 = z & z_2 gt z & z_3 gt z & (vec{v}_1) \
        z_1 gt z & z_2 gt z & z_3 gt z & text{None} \
        end{array}$$

        There is absolutely nothing surprising in the table.



        In practice, you can implement pseudocode similar to



        Function z_contour(x1, y1, z1, x2, y2, z2, x3, y3, z3, z)
        Let x = [0, 0, 0]
        Let y = [0, 0, 0]
        Let n = 0

        If z1 == z:
        x[n] = x1
        y[n] = y1
        n = n + 1

        If z2 == z:
        x[n] = x2
        y[n] = y2
        n = n + 1

        If z3 == z:
        x[n] = x3
        y[n] = y3
        n = n + 1

        If (z1 < z and z2 > z) or (z1 > z and z2 < z):
        x[n] = ( (z2 - z)*x1 + (z - z1)*x2 ) / (z2 - z1)
        y[n] = ( (z2 - z)*y1 + (z - z1)*y2 ) / (z2 - z1)
        n = n + 1

        If (z1 < z and z3 > z) or (z1 > z and z3 < z):
        x[n] = ( (z3 - z)*x1 + (z - z1)*x3 ) / (z3 - z1)
        y[n] = ( (z3 - z)*y1 + (z - z1)*y3 ) / (z3 - z1)
        n = n + 1

        If (z2 < z and z3 > z) or (z2 > z and z3 < z):
        x[n] = ( (z3 - z)*x2 + (z - z2)*x3 ) / (z3 - z2)
        y[n] = ( (z3 - z)*y2 + (z - z2)*y3 ) / (z3 - z2)
        n = n + 1

        If n == 0:
        Return (None)
        Else
        If n == 1:
        Return Point(x[0], y[0], z)
        Else
        If n == 2:
        Return Line(x[0], y[0], z, x[1], y[1], z)
        Else:
        Return Triangle(x1, y1, z, x2, y2, z, x3, y3, z)

        End Function


        to compute the intersection of the contour $z$ and the triangle.







        share|cite|improve this answer












        share|cite|improve this answer



        share|cite|improve this answer










        answered Dec 7 '18 at 8:14









        Nominal AnimalNominal Animal

        6,9002517




        6,9002517






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Mathematics Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3029224%2fcan-you-compute-line-segment-that-crosses-a-triangle%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Berounka

            Sphinx de Gizeh

            Different font size/position of beamer's navigation symbols template's content depending on regular/plain...