• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

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.
  • R Offline
    riteshrpatil
    last edited by 5 Oct 2010, 06:15

    Hello,

    I am new to Ruby-Sketchup plugins. I am creating a plugin which gives me the geometry of the model in Sketchup. So far I have managed to get the area, texture of all the faces in a particular model - export it to a text file. But I also want get the orientation of all the faces in the model. 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. If this is possible then I can manipulate it further.

    Can anyone come up with a solution or a hint?

    Thanking in anticipation...

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 5 Oct 2010, 09:03

      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 5 Oct 2010, 11:21

        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
        • T Offline
          thomthom
          last edited by 5 Oct 2010, 11:37

          @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 5 Oct 2010, 11:53

            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
            • T Offline
              TIG Moderator
              last edited by 5 Oct 2010, 14:38

              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 7 Oct 2010, 06:17

                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
                • T Offline
                  TIG Moderator
                  last edited by 7 Oct 2010, 09:31

                  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 9 Dec 2010, 09:42

                    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 3 Feb 2016, 15:35

                      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 3 Feb 2016, 16:05

                        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