sketchucation logo sketchucation
    • Login
    โ„น๏ธ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    [Code] Skew Transformation from axes

    Scheduled Pinned Locked Moved Developers' Forum
    21 Posts 8 Posters 3.7k Views 8 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.
    • jiminy-billy-bobJ Offline
      jiminy-billy-bob
      last edited by

      Thanks!

      25% off Skatter for SketchUcation Premium Members

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

        Thanks.
        PS: Use [code] rather than [ruby:1g3n3drk] to keep indents etc.
        I edited the OP...

        TIG

        1 Reply Last reply Reply Quote 0
        • eneroth3E Offline
          eneroth3
          last edited by

          Thanks TIG!

          My website: http://julia-christina-eneroth.se/

          1 Reply Last reply Reply Quote 0
          • fredo6F Offline
            fredo6
            last edited by

            Thanks for posting. Good to know. I think I may have come across this case some time ago, but did not think of encapsulate it as a Transformation, which is an elegant solution.

            One small remark: you can check the orientation of 2 vectors by
            (xaxis*yaxis) % zaxis > 0
            which is equivalent, but faster than
            xaxis*yaxis).angle_between(zaxis) < 90.degrees

            Fredo

            1 Reply Last reply Reply Quote 0
            • eneroth3E Offline
              eneroth3
              last edited by

              @fredo6 said:

              Thanks for posting. Good to know. I think I may have come across this case some time ago, but did not think of encapsulate it as a Transformation, which is an elegant solution.

              One small remark: you can check the orientation of 2 vectors by
              (xaxis*yaxis) % zaxis > 0
              which is equivalent, but faster than
              xaxis*yaxis).angle_between(zaxis) < 90.degrees

              Fredo

              Thanks!

              I had the feeling there had to be a more idiomatic way but didn't know it. It's at times like these I wish I had studied more math. There is no math at my school of architecture despite it being a part of the faculty of engineering at the university ๐Ÿ˜• . All I know about cross products and matrices have I learned by making plugins and I don't think I've ever used a dot product before ๐Ÿ˜ฒ .

              Well, at least I'm making progress. Before I even know of cross multiplication I used to offset the origin point in one axis and apply a 90 degree rotation transformation using the other axis to get a new point that I then could subtract the origin from to get a perpendicular vector. ๐Ÿ˜›

              My website: http://julia-christina-eneroth.se/

              1 Reply Last reply Reply Quote 0
              • fredo6F Offline
                fredo6
                last edited by

                ...and there is the magic formula by thomthom to check if two faces are coplanar (actually have parallel planes)

                face1.normal % face2.normal > 0.9999999991

                Fredo

                1 Reply Last reply Reply Quote 0
                • eneroth3E Offline
                  eneroth3
                  last edited by

                  @fredo6 said:

                  ...and there is the magic formula by thomthom to check if two faces are coplanar (actually have parallel planes)

                  face1.normal % face2.normal > 0.9999999991

                  Fredo

                  That's a nice one! When making my upright extruder I first tried the samedirection? method but it has some issues with the precision and see faces as co-planar sometimes when they aren't (just as the built in Soften Edges feature). Instead I looped the vertices on one face and used classify_point on the other face to see if any vertex position were considered not on plane. In the future I'll use this instead!

                  My website: http://julia-christina-eneroth.se/

                  1 Reply Last reply Reply Quote 0
                  • icehuliI Offline
                    icehuli
                    last edited by

                    @fredo6 said:

                    ...and there is the magic formula by thomthom to check if two faces are coplanar (actually have parallel planes)

                    face1.normal % face2.normal > 0.9999999991

                    Fredo

                    I have never known this operator "%" on vectors. ๐Ÿ˜ฎ ๐Ÿ˜ฎ ๐Ÿ˜ฎ Fredo, could you explain to me how it works....

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

                      @icehuli said:

                      I have never known this operator " %" on vectors....., could you explain to me how it works....

                      Geom::Vector3d#%()
                      is an alias for the dot() method, ie:
                      Geom::Vector3d#dot()

                      @unknownuser said:

                      (https://en.wikipedia.org/wiki/Dot_product)":dlvmfrbf]
                      Geometrically, it is the product of the Euclidean magnitudes of the two vectors and the cosine of the angle between them. The name "dot product" is derived from the centered dot " ยท " that is often used to designate this operation; the alternative name "scalar product" emphasizes that the result is a scalar (rather than a vector).

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • fredo6F Offline
                        fredo6
                        last edited by

                        Dot product is 0 if the vectors are perpendicular.
                        It is 1 if they have the same direction (assuming they are normalized) and -1 for opposite direction.

                        Fredo

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

                          @fredo6 said:

                          "assuming they are normalized"

                          Does normalizing first remove any variance that could throw off the comparison (with -1, 0 or 1) afterward ?

                          Or would it be safer to use:
                          vec1.perpendicular?(vec2)
                          vec1.parallel?(vec2) && vec1.samedirection?(vec2)
                          vec1.parallel?(vec2) && ! vec1.samedirection?(vec2)

                          I also wonder about ThomThom's magic comparison.

                          Is it the same on 64-bit SketchUp ?

                          I mean why 10 decimal places ? Is it SketchUp's internal tolerance ?

                          Ie, (0.001 x 0.001 x 0.001) ... which is 9 decimal places.

                          I'm not here much anymore.

                          1 Reply Last reply Reply Quote 0
                          • sdmitchS Offline
                            sdmitch
                            last edited by

                            If you have a component instance that has been skewed, how do you determine which axis is skewed?

                            Nothing is worthless, it can always be used as a bad example.

                            http://sdmitch.blogspot.com/

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

                              @fredo6 said:

                              ...and there is the magic formula by thomthom to check if two faces are coplanar (actually have parallel planes)

                              face1.normal % face2.normal > 0.9999999991

                              Fredo

                              hm... this must be something from and old version of CleanUp? It was never reliable. What I do now is take all the vertices of the faces and generate a best-fit plane - then I check if each of the vertices is on the plane.

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

                              1 Reply Last reply Reply Quote 0
                              • fredo6F Offline
                                fredo6
                                last edited by

                                Well, I think I found it it an old post!. And it seems to work fine for the purpose.

                                Indeed there are alternate methods, the problem being to detect the false positive, that is faces that would be co-planar by the formula, but would not in the model drawn by Sketchup.

                                Fredo

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

                                  @thomthom said:

                                  @fredo6 said:

                                  ...and there is the magic formula by thomthom to check if two faces are coplanar (actually have parallel planes)
                                  face1.normal % face2.normal > 0.9999999991

                                  hm... It was never reliable.

                                  I was hoping you'd answer the questions I posed (above) in this post:
                                  http://sketchucation.com/forums/viewtopic.php?f=180%26amp;t=65068%26amp;view=unread#p597160

                                  I'm not here much anymore.

                                  1 Reply Last reply Reply Quote 0
                                  • fredo6F Offline
                                    fredo6
                                    last edited by

                                    Face.normal returns a normalized vector.

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

                                      @fredo6 said:

                                      Well, I think I found it it an old post!. And it seems to work fine for the purpose.

                                      Indeed there are alternate methods, the problem being to detect the false positive, that is faces that would be co-planar by the formula, but would not in the model drawn by Sketchup.

                                      Fredo

                                      Checking the plane might in some cases yield false for some cases where SU is able to merge. But this is rare. Comparing normal had the opposite of yielding true in cases where SU would not be able to merge.

                                      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

                                        @dan rathbun said:

                                        @thomthom said:

                                        @fredo6 said:

                                        ...and there is the magic formula by thomthom to check if two faces are coplanar (actually have parallel planes)
                                        face1.normal % face2.normal > 0.9999999991

                                        hm... It was never reliable.

                                        I was hoping you'd answer the questions I posed (above) in this post:
                                        http://sketchucation.com/forums/viewtopic.php?f=180%26amp;t=65068%26amp;view=unread#p597160

                                        As Fredo mentions, face.normal already return a unit vector. The issue is that comparing vectors is too unreliable in edge cases.

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

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

                                          So what is the solution here?

                                          Is it some extra text in the API docs explaining how best to test for face coplanarity ?

                                          Or would it be a new API method for the Sketchup::Face class:
                                          face.coplanar_with?(other_face)
                                          or a module method?:
                                          Geom::faces_coplanar?(face1,face2)

                                          I'm not here much anymore.

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

                                            No sure where it would fit in the docs. Maybe we can add a Wiki section on the GitHub repo that host the new docs.

                                            This scenario is so common though that a face.coplanar_with?(other_face) might be a nice addition.

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

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

                                            Advertisement