Get Intersection line between two rectangles in 3D












0















I am trying to find a way to get the line (two points in 3D space) of the intersection between two rectangles.



I ran into this question: Intersection between two rectangles in 3D



But this is not my issue. In that question, the rectangle is treated as only the bounds (the perimeter), while I am looking for the rectangle as a whole (think about a picture frame vs the picture itself).



I've figured out that, in every case, there will either be an intersection line (two points), or no intersection at all. If the intersection was just on the borders, therefore just a point, it can be treated as no intersection in my case.



My scenario is that one of these rectangle represents a "static" surface, which cannot move or change. The other one represents a "dynamic" surface, which I have to adapt to avoid crossing



Example:



enter image description here



Once I obtain p1 and p2, which are points in the 3D space, my goal is to modify the Dynamic rectangle into a 3d polygon, which will no longer cross the static rectangle, like this:



enter image description here



So you can see why "edge intersections" are irrelevant to my situation. I am turning "real" intersections into edge intersections, so any edge intersection doesn't require me to do anything with it.



I am only looking for a formula, starting with two sets of 4 points (the rectangles), that would give me the two points of the line of their intersection, or would tell me that there is no (relevant) intersection.



Every formula I've found on this site or others doesn't fit my needs, or doesn't let me input arbitrary rectangles (for example, I can't fix my problem with a formula that uses planes or that treats a rectangle as simply 4 lines)



I am, of course, trying to code it (in C#), therefore any code answer is a great help, but I am confident that even a math-only answer would suffice for me to produce the code from it, therefore I will accept an answer that is only composed of pseudo-code or straight up mathematical formulas, provided they are either simple enough or explained well enough for me to understand what is happening.










share|improve this question

























  • Tough problem with a lot of edge cases. Not simple. CAD tools do this well. Why would you not be able to use a tool?

    – duffymo
    Jan 2 at 21:25













  • I did not give out the whole picture here, but the rectangles are actually a big simplification of what I have, so having our own solution instead of using a tool is more flexible

    – Kaito Kid
    Jan 3 at 13:20
















0















I am trying to find a way to get the line (two points in 3D space) of the intersection between two rectangles.



I ran into this question: Intersection between two rectangles in 3D



But this is not my issue. In that question, the rectangle is treated as only the bounds (the perimeter), while I am looking for the rectangle as a whole (think about a picture frame vs the picture itself).



I've figured out that, in every case, there will either be an intersection line (two points), or no intersection at all. If the intersection was just on the borders, therefore just a point, it can be treated as no intersection in my case.



My scenario is that one of these rectangle represents a "static" surface, which cannot move or change. The other one represents a "dynamic" surface, which I have to adapt to avoid crossing



Example:



enter image description here



Once I obtain p1 and p2, which are points in the 3D space, my goal is to modify the Dynamic rectangle into a 3d polygon, which will no longer cross the static rectangle, like this:



enter image description here



So you can see why "edge intersections" are irrelevant to my situation. I am turning "real" intersections into edge intersections, so any edge intersection doesn't require me to do anything with it.



I am only looking for a formula, starting with two sets of 4 points (the rectangles), that would give me the two points of the line of their intersection, or would tell me that there is no (relevant) intersection.



Every formula I've found on this site or others doesn't fit my needs, or doesn't let me input arbitrary rectangles (for example, I can't fix my problem with a formula that uses planes or that treats a rectangle as simply 4 lines)



I am, of course, trying to code it (in C#), therefore any code answer is a great help, but I am confident that even a math-only answer would suffice for me to produce the code from it, therefore I will accept an answer that is only composed of pseudo-code or straight up mathematical formulas, provided they are either simple enough or explained well enough for me to understand what is happening.










share|improve this question

























  • Tough problem with a lot of edge cases. Not simple. CAD tools do this well. Why would you not be able to use a tool?

    – duffymo
    Jan 2 at 21:25













  • I did not give out the whole picture here, but the rectangles are actually a big simplification of what I have, so having our own solution instead of using a tool is more flexible

    – Kaito Kid
    Jan 3 at 13:20














0












0








0








I am trying to find a way to get the line (two points in 3D space) of the intersection between two rectangles.



I ran into this question: Intersection between two rectangles in 3D



But this is not my issue. In that question, the rectangle is treated as only the bounds (the perimeter), while I am looking for the rectangle as a whole (think about a picture frame vs the picture itself).



I've figured out that, in every case, there will either be an intersection line (two points), or no intersection at all. If the intersection was just on the borders, therefore just a point, it can be treated as no intersection in my case.



My scenario is that one of these rectangle represents a "static" surface, which cannot move or change. The other one represents a "dynamic" surface, which I have to adapt to avoid crossing



Example:



enter image description here



Once I obtain p1 and p2, which are points in the 3D space, my goal is to modify the Dynamic rectangle into a 3d polygon, which will no longer cross the static rectangle, like this:



enter image description here



So you can see why "edge intersections" are irrelevant to my situation. I am turning "real" intersections into edge intersections, so any edge intersection doesn't require me to do anything with it.



I am only looking for a formula, starting with two sets of 4 points (the rectangles), that would give me the two points of the line of their intersection, or would tell me that there is no (relevant) intersection.



Every formula I've found on this site or others doesn't fit my needs, or doesn't let me input arbitrary rectangles (for example, I can't fix my problem with a formula that uses planes or that treats a rectangle as simply 4 lines)



I am, of course, trying to code it (in C#), therefore any code answer is a great help, but I am confident that even a math-only answer would suffice for me to produce the code from it, therefore I will accept an answer that is only composed of pseudo-code or straight up mathematical formulas, provided they are either simple enough or explained well enough for me to understand what is happening.










share|improve this question
















I am trying to find a way to get the line (two points in 3D space) of the intersection between two rectangles.



I ran into this question: Intersection between two rectangles in 3D



But this is not my issue. In that question, the rectangle is treated as only the bounds (the perimeter), while I am looking for the rectangle as a whole (think about a picture frame vs the picture itself).



I've figured out that, in every case, there will either be an intersection line (two points), or no intersection at all. If the intersection was just on the borders, therefore just a point, it can be treated as no intersection in my case.



My scenario is that one of these rectangle represents a "static" surface, which cannot move or change. The other one represents a "dynamic" surface, which I have to adapt to avoid crossing



Example:



enter image description here



Once I obtain p1 and p2, which are points in the 3D space, my goal is to modify the Dynamic rectangle into a 3d polygon, which will no longer cross the static rectangle, like this:



enter image description here



So you can see why "edge intersections" are irrelevant to my situation. I am turning "real" intersections into edge intersections, so any edge intersection doesn't require me to do anything with it.



I am only looking for a formula, starting with two sets of 4 points (the rectangles), that would give me the two points of the line of their intersection, or would tell me that there is no (relevant) intersection.



Every formula I've found on this site or others doesn't fit my needs, or doesn't let me input arbitrary rectangles (for example, I can't fix my problem with a formula that uses planes or that treats a rectangle as simply 4 lines)



I am, of course, trying to code it (in C#), therefore any code answer is a great help, but I am confident that even a math-only answer would suffice for me to produce the code from it, therefore I will accept an answer that is only composed of pseudo-code or straight up mathematical formulas, provided they are either simple enough or explained well enough for me to understand what is happening.







c# math 3d intersection rectangles






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 18:54







Kaito Kid

















asked Jan 2 at 20:40









Kaito KidKaito Kid

2031621




2031621













  • Tough problem with a lot of edge cases. Not simple. CAD tools do this well. Why would you not be able to use a tool?

    – duffymo
    Jan 2 at 21:25













  • I did not give out the whole picture here, but the rectangles are actually a big simplification of what I have, so having our own solution instead of using a tool is more flexible

    – Kaito Kid
    Jan 3 at 13:20



















  • Tough problem with a lot of edge cases. Not simple. CAD tools do this well. Why would you not be able to use a tool?

    – duffymo
    Jan 2 at 21:25













  • I did not give out the whole picture here, but the rectangles are actually a big simplification of what I have, so having our own solution instead of using a tool is more flexible

    – Kaito Kid
    Jan 3 at 13:20

















Tough problem with a lot of edge cases. Not simple. CAD tools do this well. Why would you not be able to use a tool?

– duffymo
Jan 2 at 21:25







Tough problem with a lot of edge cases. Not simple. CAD tools do this well. Why would you not be able to use a tool?

– duffymo
Jan 2 at 21:25















I did not give out the whole picture here, but the rectangles are actually a big simplification of what I have, so having our own solution instead of using a tool is more flexible

– Kaito Kid
Jan 3 at 13:20





I did not give out the whole picture here, but the rectangles are actually a big simplification of what I have, so having our own solution instead of using a tool is more flexible

– Kaito Kid
Jan 3 at 13:20












1 Answer
1






active

oldest

votes


















1














If you are OK with just algorithm rather than full code here is a sketch:




  1. Build 2 planes from the rectangles (any 3 points will do as in this answer)

  2. Find the intersection line I of those 2 planes as in this answer or find out that the planes are parallel so there is no intersection

  3. Find the intersections of the I line with the lines containing all sides of the rectangles as in this answer

  4. Check whether some points found in the previous step lie inside the corresponding sides of the rectangles (line segments). This step potentially can be merged with the previous one, but I put it separately for simplicity. Now you potentially have 0, 1 or 2 segments that represent the intersections of the I line with your two rectangles (note that here point is treated as an edge case of a segment where both ends are the same). If you don't have 2 segments, there is no intersection of the rectangles.

  5. Assuming at the previous step you found 2 segments (one in each rectangle) on the line I, you just need to find their intersection and it will be your answer (again, empty means no intersection).






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    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
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54012871%2fget-intersection-line-between-two-rectangles-in-3d%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














    If you are OK with just algorithm rather than full code here is a sketch:




    1. Build 2 planes from the rectangles (any 3 points will do as in this answer)

    2. Find the intersection line I of those 2 planes as in this answer or find out that the planes are parallel so there is no intersection

    3. Find the intersections of the I line with the lines containing all sides of the rectangles as in this answer

    4. Check whether some points found in the previous step lie inside the corresponding sides of the rectangles (line segments). This step potentially can be merged with the previous one, but I put it separately for simplicity. Now you potentially have 0, 1 or 2 segments that represent the intersections of the I line with your two rectangles (note that here point is treated as an edge case of a segment where both ends are the same). If you don't have 2 segments, there is no intersection of the rectangles.

    5. Assuming at the previous step you found 2 segments (one in each rectangle) on the line I, you just need to find their intersection and it will be your answer (again, empty means no intersection).






    share|improve this answer




























      1














      If you are OK with just algorithm rather than full code here is a sketch:




      1. Build 2 planes from the rectangles (any 3 points will do as in this answer)

      2. Find the intersection line I of those 2 planes as in this answer or find out that the planes are parallel so there is no intersection

      3. Find the intersections of the I line with the lines containing all sides of the rectangles as in this answer

      4. Check whether some points found in the previous step lie inside the corresponding sides of the rectangles (line segments). This step potentially can be merged with the previous one, but I put it separately for simplicity. Now you potentially have 0, 1 or 2 segments that represent the intersections of the I line with your two rectangles (note that here point is treated as an edge case of a segment where both ends are the same). If you don't have 2 segments, there is no intersection of the rectangles.

      5. Assuming at the previous step you found 2 segments (one in each rectangle) on the line I, you just need to find their intersection and it will be your answer (again, empty means no intersection).






      share|improve this answer


























        1












        1








        1







        If you are OK with just algorithm rather than full code here is a sketch:




        1. Build 2 planes from the rectangles (any 3 points will do as in this answer)

        2. Find the intersection line I of those 2 planes as in this answer or find out that the planes are parallel so there is no intersection

        3. Find the intersections of the I line with the lines containing all sides of the rectangles as in this answer

        4. Check whether some points found in the previous step lie inside the corresponding sides of the rectangles (line segments). This step potentially can be merged with the previous one, but I put it separately for simplicity. Now you potentially have 0, 1 or 2 segments that represent the intersections of the I line with your two rectangles (note that here point is treated as an edge case of a segment where both ends are the same). If you don't have 2 segments, there is no intersection of the rectangles.

        5. Assuming at the previous step you found 2 segments (one in each rectangle) on the line I, you just need to find their intersection and it will be your answer (again, empty means no intersection).






        share|improve this answer













        If you are OK with just algorithm rather than full code here is a sketch:




        1. Build 2 planes from the rectangles (any 3 points will do as in this answer)

        2. Find the intersection line I of those 2 planes as in this answer or find out that the planes are parallel so there is no intersection

        3. Find the intersections of the I line with the lines containing all sides of the rectangles as in this answer

        4. Check whether some points found in the previous step lie inside the corresponding sides of the rectangles (line segments). This step potentially can be merged with the previous one, but I put it separately for simplicity. Now you potentially have 0, 1 or 2 segments that represent the intersections of the I line with your two rectangles (note that here point is treated as an edge case of a segment where both ends are the same). If you don't have 2 segments, there is no intersection of the rectangles.

        5. Assuming at the previous step you found 2 segments (one in each rectangle) on the line I, you just need to find their intersection and it will be your answer (again, empty means no intersection).







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 3 at 2:11









        SergGrSergGr

        21.4k22243




        21.4k22243
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • 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.


            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%2fstackoverflow.com%2fquestions%2f54012871%2fget-intersection-line-between-two-rectangles-in-3d%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

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith