Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    Precision when serializing degrees

    SDK Help
    0
    4
    489
    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 15/07/2013 at 15:47, xxxxxxxx wrote:

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

      ---------
      I am serializing an object (storing its parameters as a string and reading them back again from the string).
      For degree values, I do not get the precision I want.
      20° becomes 0.349 which then becomes 19.996 °
      30° becomes 0.524 which then becomes 30.023 °
      45° becomes 0.785 which then becomes 44.977 °
      etc.
      This will probably have no practical meaning, but it somehow looks "ugly" when you want a precise common value. 
      I use RealToString() forwards and ToReal() to get the value back again.
      Is there a way to get more precision?

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

        On 15/07/2013 at 16:32, xxxxxxxx wrote:

        Rotations are typically stored as Radians and not degrees ('becomes').  What you should do is maybe store the degree value and do the conversion back to radians when you read the information back to set the rotation values.  Floating point is inprecise as it is on computers, so be aware that you will get some variation (like 1.9999999 for 2.0). There is very little you can do to avoid this issue.

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

          On 16/07/2013 at 00:28, xxxxxxxx wrote:

          I have this:

              	GeData t_data;
              	node->GetParameter(FOO_ID, t_data, DESCFLAGS_GET_0);
              	LONG dataType = t_data.GetType();
          

          In case of degrees, dataType will be DA_REAL
          If there was a way to "detect degrees", if there had been a "DA_DEGREE", I could then, as you suggest, use the Deg(x) and Rad(s) to store, respectively read values, that gives nice looking results.

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

            On 16/07/2013 at 10:49, xxxxxxxx wrote:

            An update:
            I can now "detect degrees", thanks to the help I got in the recent thread with the title "Getting Description information".

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