sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Angle between north and face

    Scheduled Pinned Locked Moved Developers' Forum
    9 Posts 4 Posters 493 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.
    • K Offline
      krisjaniszakis
      last edited by

      I have come a cross several posts about angle between but none of them answered my question.

      I want to calculate angle between north and any face in model.
      There should not any restriction if i change north or model.

      #the way how i get north angle north_angle = Sketchup.active_model.shadow_info['NorthAngle']

      Below is algorithm what I want to achieve:

      [pre:2rvuqfdo]x=north_angle
      y=face_angle
      z=angle_between
      if(x>360)
      z=y
      else
      if(x>0)
      if(x+y>360)
      z=x-360+y
      else
      z=x+y
      end
      end
      end[/pre:2rvuqfdo]

      1 Reply Last reply Reply Quote 0
      • K Offline
        krisjaniszakis
        last edited by

        Can some one see:

        1. why if I change north angle result is not changing?

        ` north_angle = Sketchup.active_model.shadow_info['NorthAngle']
        north_vector = Y_AXIS.clone
        north_vector.z = 0
        flat_normal = entity.normal.clone
        flat_normal.z = 0
        point = ORIGIN
        up = Z_AXIS
        rotation = north_angle.degrees
        tr = Geom::Transformation.rotation(point,up,rotation)
        north_vector.transform (tr)
        angle = (flat_normal.angle_between(north_vector)).radians

            if flat_normal.x < 0
               angle = 360-angle
            else
               angle
            end`
        
        1 Reply Last reply Reply Quote 0
        • jolranJ Offline
          jolran
          last edited by

          Hi!

          No response ey? I give it a try.

          Maybe this code is part of a larger piece, otherwise I have a little trouble following your logic.

          Have never used shadow info, and do not have time to look up the methods revolving that.
          Does it really return an angle?

          What is entity ? a face?

          Unless you are going to use those variables later why not just enter:

          tr = Geom::Transformation.rotation(ORIGIN, Z_AXIS, rotation)
          Does not really matter for solving this problem though..

          Try putting a bang to it! Edit in place..

          north_vector.transform! (tr)

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            @krisjaniszakis said:

            Can some one see:

            1. why if I change north angle result is not changing?

            north_vector.transform(tr)

            @unknownuser said:

            ](http://www.sketchup.com/intl/en/developer/docs/ourdoc/vector3d#transform)":d4kps6d6]The original vector is unchanged by this method.

            @unknownuser said:

            ](http://www.sketchup.com/intl/en/developer/docs/ourdoc/vector3d#transform!)":d4kps6d6]The vector itself is modified.

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • jolranJ Offline
              jolran
              last edited by

              Hi Dan.

              Yes modify the vector in place was the idea. Bad one ?

              Found a roundup regarding shadow info that might be intresting for Kris:

              http://sketchucation.com/forums/viewtopic.php?f=180&t=28829&p=250402&hilit=northangle#p250402

              Havent delt with shadow info before so I can only hint some links..

              1 Reply Last reply Reply Quote 0
              • K Offline
                krisjaniszakis
                last edited by

                @jolran said:

                Hi!

                No response ey? I give it a try.

                Maybe this code is part of a larger piece, otherwise I have a little trouble following your logic.

                Have never used shadow info, and do not have time to look up the methods revolving that.
                Does it really return an angle?

                What is entity ? a face?

                Unless you are going to use those variables later why not just enter:

                tr = Geom::Transformation.rotation(ORIGIN, Z_AXIS, rotation)
                Does not really matter for solving this problem though..

                Try putting a bang to it! Edit in place..

                north_vector.transform! (tr)

                I just wanted to automating angle between north and face.
                With entity I meant "face".

                Here is updated code

                ` north_angle = Sketchup.active_model.shadow_info['NorthAngle']
                flat_normal = entity.normal.clone
                flat_normal.z = 0
                north_vector = Y_AXIS.clone
                north_vector.z = 0
                point = ORIGIN
                up = Z_AXIS
                rotation = north_angle.degrees
                tr = Geom::Transformation.rotation(point,up,rotation)
                north_vector.transform! (tr)
                angle = (north_vector.angle_between(flat_normal)).radians

                    if flat_normal.x < 0
                       angle = 360-angle
                    else
                       angle
                    end`
                

                And here is Sketchup screenshot with my experiment.

                http://s8.postimg.org/dco1b0rrp/face2.jpg

                For this example script gives that angle between will be 100but not 50, where is the problem ?

                1 Reply Last reply Reply Quote 0
                • jolranJ Offline
                  jolran
                  last edited by

                  Hi!

                  I think it's important to determine what you mean angle between north and face.

                  I wonder if it's the face normal you want to work with in this example?
                  Maybe that why youre not getting the result you was expecting.

                  (if the face is vertical al the time(not flat on the ground), then the normal vector comparison should be a reliable method.)

                  You might perhaps be happier working with some of the face edges?

                  If your face is fairly uncomplex and you know that a particular edge has a min or max X,Y,Z value you can retrieve that edge and use edge.line[1], and do a comparison from there.

                  Just an idea..

                  1 Reply Last reply Reply Quote 0
                  • JuantxoJ Offline
                    Juantxo
                    last edited by

                    I'm not sure what are you looking for but here you have the
                    angle between north an a vector normal to face (with z=0) (Not valid for face in xy plane)

                    
                    northvec=Geom;;Vector3d.new( Math;;sin(Sketchup.active_model.shadow_info['NorthAngle'].degrees), Math;;cos(Sketchup.active_model.shadow_info['NorthAngle'].degrees),0)
                    
                    vec=face.normal
                    vec.z=0
                    
                    result= northvec.angle_between(vec).radians
                    
                    
                    1 Reply Last reply Reply Quote 0
                    • K Offline
                      krisjaniszakis
                      last edited by

                      Thanks it was the thing I was looking for 😄

                      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