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

Problem with face.normal directions...help!

Scheduled Pinned Locked Moved Developers' Forum
10 Posts 5 Posters 446 Views 5 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
    renderiza
    last edited by 31 Aug 2013, 17:23

    In the graph below I can work out if a face is normal is facing on the direction specified in the first four examples. But I don't know how to evaluate if a face normal is facing giving the directions specified in the last four graph examples. Any help will be Appreciated!

    http://s11.postimg.org/jj4tvgdki/question.jpg

    http://s11.postimg.org/ohsc9zhdd/question.jpg

    If my problem is not clear please let me know I will try to explain it better...cheers!

    [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

    1 Reply Last reply Reply Quote 0
    • R Offline
      renderiza
      last edited by 31 Aug 2013, 20:18

      I think this might be it...Sorry not very good at math πŸ˜• πŸ˜’

      Top Right = f1nx > 0 and f1ny > 0

      Top Left = f1nx < 0 and f1ny > 0

      Button Right = f1nx > 0 and f1ny < 0

      Button Left = f1nx < 0 and f1ny < 0

      [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

      1 Reply Last reply Reply Quote 0
      • C Offline
        Chris Fullmer
        last edited by 31 Aug 2013, 20:20

        I'm not quite sure I understand, but I think I might have something helpful.

        Find the dot product of the face's normal and the x_axis. If its a positive number, then the face normal is in the positive x range. Do the same for the y and z (if you need z). Try this code snippet, it will tell you if the face normal is pointing in a positive or negative x,y,z direction. Or it will tell you if the face normal is perpendicular to the model x,y, or z axis.

        face=Sketchup.active_model.selection[0]
        norm = face.normal
        dot_products = {}
        dot_products["x"] = norm.dot(X_AXIS)
        dot_products["y"] = norm.dot(Y_AXIS)
        dot_products["z"] = norm.dot(Z_AXIS)
        
        dot_products.each do |key, value|
        
        case 
          when value < 0
            puts "#{key} direction is a negative direction"
          when value == 0 
            puts "#{key} direction is perpendicular to the #{key} axis"
          when value > 0
            puts "#{key} direction is a positive direction"
         end
        end
        

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

        1 Reply Last reply Reply Quote 0
        • R Offline
          renderiza
          last edited by 31 Aug 2013, 20:29

          Thanks Chris Fullmer your example does the job as well.

          Here is another example that will select faces that are pointing to the top right...

          model = Sketchup.active_model
          sel = model.selection
          ents = model.active_entities
          faces = ents.grep(Sketchup;;Face)
          
          faces.each do |face|
          	f1nx = face.normal.x
          	f1ny = face.normal.y
          	
          	#Face looking top right 
          	if f1nx > 0 and f1ny > 0 
          		sel.add face
          	end
          end
          

          [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

          1 Reply Last reply Reply Quote 0
          • T Offline
            tt_su
            last edited by 2 Sept 2013, 15:29

            That image in the OP isn't loading for me...

            1 Reply Last reply Reply Quote 0
            • R Offline
              Rich O Brien Moderator
              last edited by 2 Sept 2013, 15:34

              now?

              Download the free D'oh Book for SketchUp πŸ“–

              1 Reply Last reply Reply Quote 0
              • C Offline
                Chris Fullmer
                last edited by 2 Sept 2013, 15:36

                nope, not yet. It never showed for me either, I had to click on it to follow the link.

                Lately you've been tan, suspicious for the winter.
                All my Plugins I've written

                1 Reply Last reply Reply Quote 0
                • T Offline
                  TIG Moderator
                  last edited by 2 Sept 2013, 15:37

                  No.
                  The image links aren't working... πŸ˜•

                  http://s11.postimg.org/jj4tvgdki/question.jpg

                  http://s11.postimg.org/ohsc9zhdd/question.jpg

                  http://s11.postimg.org/z4m5fepiq/question.jpg

                  Above is http://s11.postimg.org/z4m5fepiq/question.jpg NOT these...
                  http://s11.postimg.org/jj4tvgdki/question.jpg ]
                  http://s11.postimg.org/ohsc9zhdd/question.jpg

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • R Offline
                    Rich O Brien Moderator
                    last edited by 2 Sept 2013, 15:39

                    I see it. NA NA NA-NA NA

                    Download the free D'oh Book for SketchUp πŸ“–

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      TIG Moderator
                      last edited by 2 Sept 2013, 15:52

                      Back to the question...
                      NorthEast Quadrant: normal.y>0 normal.x>0
                      SouthEast Quadrant: normal.y<0 normal.x>0
                      SouthWest Quadrant: normal.y<0 normal.x<0
                      NorthWest Quadrant: normal.y>0 normal.x<0

                      As you said:
                      Due North: normal.y==1 normal.x==0
                      Due East: normal.y==0 normal.x==1
                      Due South: normal.y==-1 normal.x==0
                      Due West: normal.y==0 normal.x==-1

                      Exactly Vertical: normal.z==0
                      Upwards Facing: normal.z>0
                      Downwards Facing: normal.z<0
                      Exactly Up: normal.z==1
                      Exactly Down: normal.z==-1

                      TIG

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

                      Advertisement