Units problem
-
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
-
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:-
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.
-
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.
-
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.
-
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.
-
-
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 ...
Advertisement