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

    Edges, angles on rectangle triangle

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 5 Posters 942 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.
    • B Offline
      bizello
      last edited by

      Hi guys,
      I have an diagonal edge on XY plane and Z=0. I got its start and end points. I can calculate its length.
      I want to use Pitágoras to calculate a triangle rectangle.
      I didn´t know to calculate the edge's angle to draw the others sides.
      Cay you help me?
      Thanks since now.
      Sérgio

      Sérgio A.Bizello

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

        Angles for a right triangle is:
        sin(angle) = opposite/hypothenuse
        cos(angle) = adjacent/hypothenuse

        But can't you just use your start and end point positions to find the rectangle corners?

        Corner Points.png

        -Kwok

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

          @kyyu said:

          But can't you just use your start and end point positions to find the rectangle corners?

          -Kwok

          To do it the Kwok way:

          <span class="syntaxdefault">ents </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities<br />sp </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">position<br />ep </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">end</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">position<br />ents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_edges</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> sp</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[</span><span class="syntaxdefault">sp</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">x</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">ep</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">y</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">],</span><span class="syntaxdefault"> ep </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span>
          

          EDIT: a face will not be created inside the triangle.

          I'm not here much anymore.

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

            You can use the Geom::BoundingBox class, to let Sketchup do the work, IF the sides you want are aligned with the WorldAxis.

            Let's say you already have a reference to the Edge object as edge, and you want to draw sides in a clock-wise manner:

            <span class="syntaxdefault">bb </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">bounds<br />ep </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">end</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">position<br />spi </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> for i in 0</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">.4 </span><span class="syntaxcomment"># start pt index<br /></span><span class="syntaxdefault">  break i if bb</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">i</span><span class="syntaxkeyword">]==</span><span class="syntaxdefault">edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start<br />end<br />mpi</span><span class="syntaxkeyword">=[</span><span class="syntaxdefault">2</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">3</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> </span><span class="syntaxcomment"># mid pt index<br /></span><span class="syntaxdefault">ents </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities<br />ents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_edges</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> bb</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">spi</span><span class="syntaxkeyword">],</span><span class="syntaxdefault"> bb</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">mpi</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">spi</span><span class="syntaxkeyword">]],</span><span class="syntaxdefault"> ep </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span>
            

            I'm not here much anymore.

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

              @bizello said:

              I want to use Pitágoras to calculate a triangle rectangle.

              @kyyu said:

              Angles for a right triangle is:
              sin(angle) = opposite/hypothenuse
              cos(angle) = adjacent/hypothenuse

              To use math functions you qualify the method calls into the Math module.

              You are on Windows.. so get a copy of the Ruby 1.8.6 Reference
              (ruby-1.8.6-p398-doc-chm-2.zip) in this post:
              RUBY PROGRAMMING REFERENCES - CHM format
              Put the CHM help file somewhere, and make a shortcut to it.
              The Math module is listed in the Core Classes/Modules tree.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • B Offline
                bizello
                last edited by

                My script must enter an opening in a wall orthogonal or tilted.
                The calculations for horizontal and vertical walls are easier, but the script must also include sloped walls at any angle.
                The walls of the room must be obtained from an extruded face on the positive Z axis on the xy plane.
                You must select the face that will open like you're inside the room and facing the wall.
                Click the right button and select the action from the context menu.
                A dialog box opens and asks for the parameters of opening: width, height, sill, position (center, left or right) and distance from the corner
                in accordance with the position.
                Then they get the calculations:
                Checks whether element has selected and if it is a face (rule: not possible to make openings in floor or ceiling);
                Get the edges connected to that face and separates that are built in Z direction (equal xy coordinates) representing the wall height;
                According to the normal of the face, check what is the left edge, base to build on opening;
                Creates the vector with p1.vetor_to p2, between the left edge starting point and right edge, adding the Z coordinate value of the sill;
                This vector is baseline for the construction of the opening. With point.offset (vector distance) you can calculate the points
                to create the face, with distances from the corners
                This last action I thought making a very complex way, finding angles and applying Pythagoras, but with some tips and found a little more
                studying the API could do more easily.
                Thanks to everyone who answered this question.

                PS. But I would like to know how the best way to get the edge or face's angle from a axis or plane?

                Sérgio A.Bizello

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

                  You can specify any vector as Geom::Vector3d.new(x,y,z)
                  A face has a normal vector - face.normal
                  An edge has a vector - edge.line[1]
                  So...
                  vec1.angle_between(vec2)
                  returns the angle in radians between any two vectors, use .radiansto make it return as degrees...
                  The normal is always at 90 degrees to the plane so adding 90 degrees will return the 'slope'...
                  Vectors can be transformed - typically you make a rotation-transformation and turn it as needed... 🤓

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • C Offline
                    Cleverbeans
                    last edited by

                    Angles are only defined between two vectors, so finding the angle between a vector and a plane can vary depending on which vector in the plane you're interested in. Most of the time, the vector you're interested in is the angle between the vector and it's projection into the plane which can be calculated using the face.plane method and the Array.project_to_plane method. The only trick here is that vectors are not points, so you would have to either pick a point in the plane, then transform it by your vector or translating the plane to the origin and simply calling the vector3d.to_a method. As it turns out, the second method is much simpler since given a plane of of the form [x,y,z,c] then translating it to the origin is as easy as changing it to [x,y,z,0]. Here is the code

                    
                    def angle_between_vector_and_projection(vector,face)
                        plane = face.plane
                        plane[3] = 0
                        projection = Geom;;Vector3d.new(vector.to_a.project_to_plane(plane))
                        return vector.angle_between(projection)
                    end
                    
                    
                    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