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

    Vector.angle_between() -- Direction?

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 4 Posters 3.2k Views 4 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.
    • daikuD Offline
      daiku
      last edited by

      I'm trying to rotate a comp inst so that it is parallel to the green axis. I have a vector that represents the component, and I use that vector's angle_between method to create a (rotation) transformation object to apply to my comp inst. It works right most of the time, but sometimes, it rotates in the wrong direction. It seems that angle_between never returns a negative value, even if I want to rotate in a "backwards" direction. Is there a better way to find the angle? Thanks, CB.

      Clark Bremer
      http://www.northernlightstimberframing.com

      1 Reply Last reply Reply Quote 0
      • Didier BurD Offline
        Didier Bur
        last edited by

        The angle_between method returns a value between 0 and PI, so 270° is the same for it than PI/2 😢
        This is really a weird way of returning angle IMHO 8O
        Nobody knows (at least not me) why 'they' coded this that way.
        I'm afraid you'll have to test the two vectors to know in which trigonometric quadrant (0°->90°,90°->180°,180°->270°,270°->360°) they are, to get the "real" angle between them.
        But perhaps you could also use this:
        your_component_instance.transformation.yaxis = your_angle
        Hope this helps 😕

        DB

        1 Reply Last reply Reply Quote 0
        • daikuD Offline
          daiku
          last edited by

          Thanks, DB, that helps a lot.

          I just changed my code to try using the angle_between angle, and then check the result to see if it's where I expect it to be. If not, then I reverse the angle, and try again. Lots of code, but correct behavior now! Thanks again. CB.

          Clark Bremer
          http://www.northernlightstimberframing.com

          1 Reply Last reply Reply Quote 0
          • R Offline
            RickW
            last edited by

            I created a vector1.flat_angle(vector2) method that does this work for you.

            RickW
            [www.smustard.com](http://www.smustard.com)

            1 Reply Last reply Reply Quote 0
            • Didier BurD Offline
              Didier Bur
              last edited by

              Where's this gem, Rick ? I don't see it at smustard 😲

              DB

              1 Reply Last reply Reply Quote 0
              • TIGT Offline
                TIG Moderator
                last edited by

                If you have pathcopy.rb you get vector.flat_angle.rb...

                TIG

                1 Reply Last reply Reply Quote 0
                • Didier BurD Offline
                  Didier Bur
                  last edited by

                  OK OK OK 😳
                  Thanks for answering., have a nice day 😛

                  DB

                  1 Reply Last reply Reply Quote 0
                  • R Offline
                    RickW
                    last edited by

                    Yeah, sorry about that. I suppose I shoul give it its own spot for developer use 😄

                    RickW
                    [www.smustard.com](http://www.smustard.com)

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

                    Advertisement