Math-problem
-
hi,
i cannot find my mistakewith
@run = 30
@lwidthplus = 20the formula
angle2 = (Math.tan(@lwidthplus/@run))*180/Math::PI
does not give me the right angle.
as far , as i understand
(Math.tan(@lwidthplus/@run)) gives me the RAD
and
*180/Math::PI should give me the degrees
any idea, where my mistake is?
thanx stan
-
The numeric methods:
.degrees
.radianswill do the conversions for you.
No need for PI and convolutions...AND use floats for length, angles etc, rather than integers [which are OK for 'counting' but not any maths]:
30.0 not 30
180.0 not 180
etc
Because
20 / 30 >> 0
whereas
20.0 / 30.0 >> 0.666666666666667
etc -
try
@run = 30.0
@lwidthplus = 20.0p.s. are you sure that you are using Math.tan instead of Math.atan ?
-
hi tig & icehuli,
@tig: yes, the numbers come from another modules and should be float (with direct input "45.degrees" in tr for angle2 the object is turned by 45 degr.)
in the code below i tried the 'simple way', not clear to me, why it still does not work
@icehuli
see the code, the function should be the right onenew_line = @entities2.add_line pfm1, pfm2 # gives vertical line @vector = new_line.line[1] point = [0,0,0] # angle = (Math.tan(@lwidthplus/@run)) # x,y come from another module angle2 = angle.degrees # trying to become degrees # puts "@lwidthplus",@lwidthplus #gives >> 7.8740157480315 (equiv. to 20) puts "@run",@run #gives >> 11.8110236220472(equiv. to 30) puts angle #gives >> 1.5574077246549, should be 0,6666666 ( = 20/30 >> about 34 degr.) puts angle2 #gives >> 0.0271818925912213 # tr = Geom;;Transformation.rotation(point,@vector,angle2) # turnes somehow group.entities.transform_entities(tr, group.entities.to_a) # @m_pf_l = group.to_component defn = @m_pf_l.definition defn.name = "@m_pf_l"
it must be something very simple....but i cannot see it!
stan
-
You confuse methods...
angle.degrees
makes the number into radians - useful of you want to input user-friendly values like45.degrees >> 0.785398163397449 radians
is much more intuitive thanMath::PI/4.0 >> 0.785398163397448 radians
etcThen
angle.radians
makes the number into degrees - useful if you have calculated an angle in radians but want it displaying in a user-friendly degree format...0.785398163397448.radians >> 45.0 degrees
-
hi tig, ok. i will make tests and learn.
but anyway:why does
angle = Math.tan(20.0/30.0)
give (by puts angle)
0.786842889472977
instead of
0.66666666 (normal tangens)
and if 0.786842889472977 = 20/30 in radians,
why does angle.radians then not give 33.69 degrees?
sorry, i am confused, i seem to misunderstand someting totaly...
stan
-
if 20.0 and 30.0 are the edges, 20.0/30.0 is already the tangent value. You should use Math.atan to get the angel out of it.
so in short:angel = (Math.atan(@lwidthplus/@run)).radians
-
hi icehuli,
that's it! of course, i already had the tanges, so......sometimes it's so clear afterwards...
thanx a lot, the method works now!new_line = @entities2.add_line @pfm1, @pfm2 @vector = new_line.line[1] point = [0,0,0] angle = (Math.atan(var4/@run)).radians angle = 360 - (Math.atan(var4/@run)).radians if var5 == "right" tr = Geom;;Transformation.rotation(point,@vector,angle.degrees) @group.entities.transform_entities(tr, @group.entities.to_a)
stan
Advertisement