Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Testing Edges on a Plane

    SDK Help
    0
    6
    413
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

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

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

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

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

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

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            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)
            
            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              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"[URL-REMOVED] (it's in the docs as well). Also note the links on further reading in there.
              The Computerphiles did also a nice

              on this topic.


              [URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

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

                May I close this issue?

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post