Incorrect radius value.
-
I create an arc with a Radius of 5M on my drawing. Then when I read that value through Ruby I get either a value of 196 or 180 and I am not sure of the units. The length is also wrong. I find the edge then I get the curve off the edge then I get the radius from the curve.
entity.curve.radius.to_s
Any ideas how to get the correct value?
-
All angles from SketchUp is in radians.
All lengths are in inches - and comes as aLength
object (subclass ofFloat
)There are helper methods to deal with this:
Use
.radians
and.degree
to convert between angle and radians.
http://code.google.com/apis/sketchup/docs/ourdoc/numeric.html#radians
puts entity.curve.angle.radians.to_s
When you have a
Length
and want to display it to the user, just rely onLength.to_s
to present the length in the model units.
http://code.google.com/apis/sketchup/docs/ourdoc/length.html
puts entity.curve.radius.to_s
Make sure you know if you have a
Float
or aLength
object - make use of theLength
class, don't try to convert between other units unless you need to present anything to the user. Remember that aLength
converted to float returns the length in inches as that is the system unit for SketchUp. -
@antondeg said:
I create an arc with a Radius of 5M on my drawing. Then when I read that value through Ruby I get either a value of 196 or 180 and I am not sure of the units. The length is also wrong. I find the edge then I get the curve off the edge then I get the radius from the curve.
entity.curve.radius.to_s
Any ideas how to get the correct value?
How are you setting the radius to "5m" ?
You must use5.m
or equivalent?
When you get the radius in code it's in inches soentity.curve.radius.to_m.to_s
will return a string with it in meters.
In Entity Info it shows in 'current units'.
The 'length' of an arc given in Entity Info [or code] is the accumulative length of the arc's individual segments in current units - the more segments an arc has the nearer it is to the real length of a 'true' arc.
To calculate the true length of an arc find it's swept_angle=end_angle-start_angle [which is automatically in radians] and then use
length = 2*Math::PI*radius*swept_angle/(2*Math::PI) = radius*swept_angle
in inches
If it's a circle [i.e. edge.curve.is_polygon?] then use
length = 2*Math::PI*radius
TIP: to check if a Curve is an Arc, and therefore it can have a radius use
edge.curve.typename=="ArcCurve"
-
Thanks once I used to_m I got the correct value.
Advertisement