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

    Face orientation

    Scheduled Pinned Locked Moved Developers' Forum
    11 Posts 4 Posters 2.9k 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.
    • TIGT Offline
      TIG Moderator
      last edited by

      The method normal = face.normal returns a vector perpendicular to the face.
      The method north_angle = Sketchup.active_model.shadow_info['NorthAngle'] returns the north angle in degrees.
      Set up a vector and transform it by that angle.
      north_vector = Y_AXIS.clone tr = Geom::Transformation.rotation(ORIGIN,Z_AXIS,north_angle.degrees) north_vector.transform!(tr)
      now find the angle between normal and north_vector
      angle = (normal.angle_between(north_vector)).radians
      However, I suspect this isn't what you want as it's a '3D angle' and you will probably want the angle 'in plan'... Therefore you need to 'flatten' the ' normal' first.
      flat_normal = normal.clone flat_normal.z = 0 if flat_normal.length == 0 #face is 'flat' on ground! angle = -999 else angle = (flat_normal.angle_between(north_vector)).radians end
      Now you have the angle in plan between the model's north and the face's normal [flattened].
      IF it's '-999' you know it's a 'flat' face which doesn't face 'north at all!
      You can then puts string version of these angles into your external text file...
      πŸ€“

      TIG

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

        Thank you for that reply and piece of code too... I will implement it in sometime and let you know if that it is what I want! πŸ˜„

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          @riteshrpatil said:

          When I say the word 'Orientation' I mean to get the direction of every face relative to the N direction, i.e with the Axes in Sketchup.

          North direction in a model is not the same as the model axis in SkechUp.
          And if you mean the axis direction, do you then mean the global model axis, or the current user defined axis? Or even active group/component axis?

          Thomas Thomassen β€” SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

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

            I mean the global North direction... suppose I have a simple model in SketchUp (having 4 walls one roof and one floor) and I want to know the orientation of the walls and roof.

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

              My sample code read the 'model-north' as set using the 'north' protractor, rather than the plain 'Y_AXIS'.
              It's actually easier if you want to use that, as you miss out some steps...

              TIG

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

                I make my question more clear.

                The green line/axis in Sketchup leads towards North direction from the origin. Now you can see the model as shown in the attached image. The wall which is marked as 'Wall 1' will have orientation of 90 degrees as it is perpendicular to the green axis. The wall which is marked as 'Wall 2' will have orientation of 180 degrees as it is parallel to the green axis. Similarly the wall exactly opposite to the 'Wall 1' will have orientation 270 degrees.

                Now my question is: How can I achieve '90' for 'Wall 1' and '180' for 'Wall 2' and so on?


                Sketchup Model

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

                  IF your North is equal to model axis Y [green] - although it need not be so - the method I outlined using face.normal.angle_between(Y_AXIS).radians will return the angle between the wall's normal and the Y-axis in degrees.
                  In your example 'wall-1' is NOT at 90.0 degrees to the Y-axis it is at 0.0 degrees - as it is facing 'due-north' [if north==Y_AXIS]!
                  If you really want to report it like that, then you just add 90.0 onto the result!
                  I think the angles will also go counter-clockwise so you might need to 'flip' the results if you insist on this method and that 'wall-2' is at angle measure clockwise!

                  TIG

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

                    I finally managed to get what I wanted after little playing on the code which you sent... My working code is as follows.

                    	def azimuth
                    		normal = self.normal
                    
                    		return 0 if normal.x == 0 and normal.y == 0
                    
                    		normal.z = 0
                    		angle = normal.angle_between(Geom;;Vector3d.new(0,-1,0)).radians
                    		angle = 360-angle if normal.x < 0
                    
                    		return angle +90
                    	end
                    
                    
                    1 Reply Last reply Reply Quote 0
                    • M Offline
                      MaryamR
                      last edited by

                      Code: Select all
                      def azimuth
                      normal = self.normal

                            return 0 if normal.x == 0 and normal.y == 0
                      
                            normal.z = 0
                            angle = normal.angle_between(Geom::Vector3d.new(0,-1,0)).radians
                            angle = 360-angle if normal.x < 0
                      
                            return angle +90
                         end
                      

                      hello i using Sketchup C/C++ api in a C/C++ code and i need to get orientation of walls and roofs from a house model like yours, is it possible to use this code too or is it just for Ruby ?

                      i also need to have roofs' degree of tilt , how can i do that ? does anyone have an idea ?

                      thnx a lot !!

                      1 Reply Last reply Reply Quote 0
                      • M Offline
                        MaryamR
                        last edited by

                        hello how do u make difference between the walls (wall 1, wall 2) and when u receive the orientations how do u know each orientation belongs to which wall (wall 1 or wall 2 ) ?

                        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