sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Angle between two edges in a face?

    Scheduled Pinned Locked Moved Developers' Forum
    11 Posts 3 Posters 686 Views 3 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.
    • thomthomT Offline
      thomthom
      last edited by

      I'm trying to find the angles between edges in a face. I tried this:

      <span class="syntaxdefault"><br />def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">full_angle_between</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> vector1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> vector2</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> normal </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">  angle </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> vector1</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">angle_between</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> vector2 </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">  direction </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> normal </span><span class="syntaxkeyword">%</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> vector1 </span><span class="syntaxkeyword">*</span><span class="syntaxdefault"> vector2 </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">  angle </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> 360</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">degrees </span><span class="syntaxkeyword">-</span><span class="syntaxdefault"> angle if direction </span><span class="syntaxkeyword"><</span><span class="syntaxdefault"> 0.0<br />  angle<br />end<br /></span>
      

      normal is the face normal
      vector1 and vector2 both origin from the same vertex and to the opposite vertices

      But in a rectangle this yielded one 90 corner and three 270 degree corners.

      So how can one find the angle between two edges ( 0...360 degrees ) relative to a face?

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

      1 Reply Last reply Reply Quote 0
      • cottyC Offline
        cotty
        last edited by

        Are you able to provide a little image which shows the variables vector1, vector2, normal?
        Cotty

        my SketchUp gallery

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

          @cotty said:

          Are you able to provide a little image which shows the variables vector1, vector2, normal?
          Cotty

          I added more to the description in the original post.

          full_angle_between.png

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

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

            If it is of any importance, "vector1" and "vector2" was just picked at random in the illustration. The red "vector1" might be "vector2" for all I know.

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

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

              The order of how I received the vectors seemed to make the difference.

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

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

                ### this code lists each vertex with its angle, for a selected face
                def vangles()
                  model=Sketchup.active_model
                  ss=model.selection
                  face=ss[0]
                  edges=face.edges
                  edges << edges[0]
                  pairs=[]
                  edges[0..-2].each_with_index{|e,i|
                    pairs << [e,edges[i+1]]
                  }
                  norm=face.normal
                  angles=[];ctr=0
                  pairs.each{|pr|
                    e0=pr[0]
                    e1=pr[1]
                    vert=e0.start
                    verts=e0.vertices+e1.vertices
                    b=Hash.new(0)
                    verts.each{|v|b[v]+=1}
                    b.each{|k,v|vert=k if v > 1}
                    everts=verts-[vert]
                    vec0=vert.position.vector_to(everts[0])
                    vec1=vert.position.vector_to(everts[1])
                    angle=(vec0.angle_between(vec1))
                    angle=360.degrees-angle if norm==(vec0*vec1).normalize!
                    angles << [ctr, angle.radians]
                    ctr+=1
                  }
                  puts angles
                end
                ###
                

                TIG

                1 Reply Last reply Reply Quote 0
                • cottyC Offline
                  cotty
                  last edited by

                  Is it possible to calculate two angles, one for +direction and one for -direction and chose the little one? I don't know about ruby, sorry...
                  Cotty

                  my SketchUp gallery

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

                    I've solved the problem. Code is posted in this thread: http://forums.sketchucation.com/viewtopic.php?f=180&t=39625

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

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

                      @thomthom said:

                      I've solved the problem. Code is posted in this thread: http://forums.sketchucation.com/viewtopic.php?f=180&t=39625

                      Which presumably has a similar affect as my code ?

                      TIG

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

                        @tig said:

                        @thomthom said:

                        I've solved the problem. Code is posted in this thread: http://forums.sketchucation.com/viewtopic.php?f=180&t=39625

                        Which presumably has a similar affect as my code ?

                        Angles seem to be correct, until you add a hole on the face. Then your pairs won't be correct as one pair might contain edges from two different loops.

                        And my starting position is with a vertex given - and from there I need to work out it's normal. To process the whole face would lead to duplicate processing.

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

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

                          My code was a quick example to show that you could get the correct angles.
                          Of course edges=face.edges can easily be replaced with edges=face.outer_loop.edges or we iterate through the loops to get their edges in turn...
                          BUT if its for only one vertex it's then easy enough to find the two edges belonging to that vertex [and that face] and run similar code on them to get the angle between them, using the face normal and vectors cross comparison to trap for concave corner angles >180 degrees... remembering to trap for ==180.degrees, as well as < and >...

                          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