sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Angles to vector

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 2 Posters 297 Views 2 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
      abakobo
      last edited by

      hi and many thanks for the precise answers i received for the previous question!

      while reading tutos on ruby/sketchup i kind of remember of an "angles to vector" method.. supposed it was in Geom but i found nothing similar in the api reference on http://www.sketchup.com/intl/en/developer/docs/ourdoc/geom.php. And i can't find the tuto anymore in the mess of my browser's history.

      so my question is: is there any function/method like this or do i have to sine/cosine the angles myself.

      grtz

      Abakobo

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

        vector1.angle_between(vector2)

        result in radians...
        See under 'Vector3d'...

        TIG

        1 Reply Last reply Reply Quote 0
        • A Offline
          abakobo
          last edited by

          thanks! but this is vector to angle...

          what i'm looking for is a method that ouputs a normalized Vector3d..
          the arguments would be it's projection angle on xy plane and xz plane (with x axis).. actualy i already made a method with cos/sin myself but i'm afraid it will slowdown calculations when in loops and suppose a method from ruby/sketchup stds would be faster as i suppose it is in a lower level...

          grtz

          abakobo

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

            There is no inbuilt method... but this will do it [flattened to Z-plane]

            def flat_angle(vector)
            	vec=Geom;;Vector3d.new(vector.x, vector.y, 0)
            	if vec.y < 0
            		return (2*Math;;PI)-(vec.angle_between(X_AXIS))
            	elsif vec.y > 0
            		return vec.angle_between(X_AXIS)
            	elsif vec.y == 0
            		if vec.samedirection?(X_AXIS)
            			return 0
            		else
            			return Math;;PI
            		end
            	end
            end
            

            it's easy to make methods for X & Y planes - just adjust vec= to suit those other planes and adjust the tests from vec.y & _AXIS etc...

            TIG

            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