• Login
sketchucation logo sketchucation
  • Login
🔌 Quick Selection | Try Didier Bur's reworked classic extension that supercharges selections in SketchUp Download

Math-problem

Scheduled Pinned Locked Moved Developers' Forum
8 Posts 3 Posters 272 Views 3 Watching
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.
  • A Offline
    artmusicstudio
    last edited by 20 Nov 2013, 11:30

    hi,
    i cannot find my mistake

    with

    @run = 30
    @lwidthplus = 20

    the 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

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 20 Nov 2013, 11:42

      The numeric methods:

      .degrees
      .radians

      will 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

      TIG

      1 Reply Last reply Reply Quote 0
      • I Offline
        icehuli
        last edited by 20 Nov 2013, 11:47

        try

        @run = 30.0
        @lwidthplus = 20.0

        p.s. are you sure that you are using Math.tan instead of Math.atan ?

        1 Reply Last reply Reply Quote 0
        • A Offline
          artmusicstudio
          last edited by 20 Nov 2013, 12:59

          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 one

          
                  new_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

          1 Reply Last reply Reply Quote 0
          • T Offline
            TIG Moderator
            last edited by 20 Nov 2013, 13:53

            You confuse methods...
            angle.degrees makes the number into radians - useful of you want to input user-friendly values like 45.degrees >> 0.785398163397449 radians is much more intuitive than Math::PI/4.0 >> 0.785398163397448 radians etc

            Then
            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

            TIG

            1 Reply Last reply Reply Quote 0
            • A Offline
              artmusicstudio
              last edited by 20 Nov 2013, 14:25

              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

              1 Reply Last reply Reply Quote 0
              • I Offline
                icehuli
                last edited by 20 Nov 2013, 14:38

                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

                1 Reply Last reply Reply Quote 0
                • A Offline
                  artmusicstudio
                  last edited by 20 Nov 2013, 18:31

                  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

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

                  Advertisement