• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Units problem

Scheduled Pinned Locked Moved Developers' Forum
3 Posts 3 Posters 350 Views
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.
  • C Offline
    confitex architure
    last edited by 21 Mar 2008, 22:23

    first I define a variable, that define a Z ccordinate (in cm because my drawing units are so)

    $startcoord = 100
    
    

    Then I put a component in memory to get its boundaries

    	
    component_path = Sketchup.find_support_file filename , dirname
    $instance = definitions.load component_path 
    
    	bounds = $instance.bounds
    	bmax = bounds.max
    	bmaxx = bmax.x
    	bmaxy = bmax.y
    	bmaxz = bmax.z #in this case 20,0cm f.e.
    
    
    

    The problem is that when I ask to return the bmaxz value, I get it in cm because the component itself file is drawn in cm. if I make an addition of addition = bmaxz+$startcoord (20,0cm + 100) It's transformed into inches (I presume) and addition.to_cm returns an "unrounded" value 120,00000000002.
    I tried do define $startcoord as 100.0.cm but it doesn't change it.

    please help

    1 Reply Last reply Reply Quote 0
    • J Offline
      Jim
      last edited by 22 Mar 2008, 00:34

      I am guessing you mean the inaccuracy of floating point arithmetic. If so, it's explained clearly in the MS article:

      http://support.microsoft.com/kb/125056

      Items 2, 3, and 4 apply directly to Ruby.

      @unknownuser said:

      SUMMARY
      There are many situations in which precision, rounding, and accuracy in floating-point calculations can work to generate results that are surprising to the programmer. There are four general rules that should be followed:

      1. In a calculation involving both single and double precision, the result will not usually be any more accurate than single precision. If double precision is required, be certain all terms in the calculation, including constants, are specified in double precision.

      2. Never assume that a simple numeric value is accurately represented in the computer. Most floating-point values can't be precisely represented as a finite binary value. For example .1 is .0001100110011... in binary (it repeats forever), so it can't be represented with complete accuracy on a computer using binary arithmetic, which includes all PCs.

      3. Never assume that the result is accurate to the last decimal place. There are always small differences between the "true" answer and what can be calculated with the finite precision of any floating point processing unit.

      4. Never compare two floating-point values to see if they are equal or not- equal. This is a corollary to rule 3. There are almost always going to be small differences between numbers that "should" be equal. Instead, always check to see if the numbers are nearly equal. In other words, check to see if the difference between them is very small or insignificant.

      Hi

      1 Reply Last reply Reply Quote 0
      • T Offline
        TIG Moderator
        last edited by 22 Mar 2008, 14:15

        Try something like (bmaxz+$startcoord).to_cm - SUp uses the 'inch' as its units and that's what the bmax returns - if you want it to return dims in other units try things like .to_cm ...

        TIG

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        1 / 1
        • First post
          3/3
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement