Testing Edges on a Plane



  • On 23/06/2015 at 17:25, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   16 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    Hello, I've written a function to test if two edges are on the same plane. For example the edges

      
    P1 (0;300;0)   
    Q1 (0;300;30)   
    P2 (0;300;30)  
    Q2 (400;300;30)  
    

    are on the Y-Plane.

    But my function doesn't work and I don't know why.

      
    Int32 GetEdgesPlane (Vector64 p1, Vector64 q1, Vector64 p2, Vector64 q2) {  
      
      // return 1 for X, 2 for Y, 3 for Z and 0 if not on a Plane  
      GePrint(String::VectorToString(p1)+String::VectorToString(q1)+String::VectorToString(p2)+String::VectorToString(q2));     
      
      if (CompareFloatTolerant(p1.x,q1.x) && CompareFloatTolerant(q1.x,p2.x) && CompareFloatTolerant(p2.x,q2.x)) {  
          return 1;  
      } else if (CompareFloatTolerant(p1.y,q1.y) && CompareFloatTolerant(q1.y,p2.y) && CompareFloatTolerant(p2.y,q2.y)) {  
          return 2;  
      } else if (CompareFloatTolerant(p1.z,q1.z) && CompareFloatTolerant(q1.z,p2.z) && CompareFloatTolerant(p2.z,q2.z)) {  
          return 3;  
      } else {  
          return 0;  
      }  
    }  
    

    And here is a piece of my console output:

      
    (0;300;0)(0;300;30)(0;300;0)(0;300;30)  
    1  
    (0;300;0)(0;300;30)(0;300;30)(400;300;30)  
    0  
    (0;300;0)(0;300;30)(400;300;30)(400;300;0)  
    0  
    (0;300;0)(0;300;30)(400;300;0)(0;300;0)  
    2  
    (0;300;0)(0;300;30)(370;300;30)(400;300;30)  
    0  
    (0;300;0)(0;300;30)(400;300;30)(400;300;-370)  
    0  
    (0;300;0)(0;300;30)(400;300;-370)(370;300;-370)  
    0  
    (0;300;0)(0;300;30)(370;300;-370)(370;300;30)  
    0  
    (0;300;30)(400;300;30)(0;300;0)(0;300;30)  
    0  
    (0;300;30)(400;300;30)(0;300;30)(400;300;30)  
    0  
    (0;300;30)(400;300;30)(400;300;30)(400;300;0)  
    0  
    (0;300;30)(400;300;30)(400;300;0)(0;300;0)  
    0  
    (0;300;30)(400;300;30)(370;300;30)(400;300;30)  
    0  
    (0;300;30)(400;300;30)(400;300;30)(400;300;-370)  
    0  
    (0;300;30)(400;300;30)(400;300;-370)(370;300;-370)  
    0  
    

    As you can see, sometimes it works but the most time not. Can someone help?

    Thanks
    crush4



  • On 23/06/2015 at 18:01, xxxxxxxx wrote:

    very weird, your code looks fine, try to compare values manually without the function.



  • On 23/06/2015 at 19:01, xxxxxxxx wrote:

    the thing is, when I use some manual values it works 😕



  • On 24/06/2015 at 11:26, xxxxxxxx wrote:

    I found an error:

    I don't know why, but cinema does some little rounding erros:

    (0.00000000000000000000;300.00000000000000000000;-0.00000000000000710543)(0.00000000000000000000;300.00000000000000000000;29.99999999999999300000)(399.99999999999937000000;300.00000134122064000000;29.99998658895490800000)(400.00000000000000000000;300.00000000000000000000;-0.00000000000000710543)
    


  • On 29/06/2015 at 04:27, xxxxxxxx wrote:

    Hi,

    actually I don't think, Cinema is doing these rounding errors. Instead you can't expect floating point numbers to be precise. Certain numbers simply can't be displayed in IEEE754 floating point. And all kinds of things, like for example order of operations can have influence on the precision of your result. That's why you rather should not compare floats on equality.
    There's a small article on our development blog on the "weirdness of floating point" (it's in the docs as well). Also note the links on further reading in there.
    The Computerphiles did also a nice video on this topic.



  • On 26/08/2015 at 08:43, xxxxxxxx wrote:

    May I close this issue?


Log in to reply