sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Help with transformation

    Scheduled Pinned Locked Moved Developers' Forum
    14 Posts 3 Posters 343 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.
    • D Offline
      Davidfi1
      last edited by

      OK - I finished πŸ˜„ I think.
      This is what came out:

      def add_Filament( startPoint, endPoint , filament )
            @lineVector = startPoint.vector_to endPoint
            return if @lineVector.length.to_f - 1e-6 < 0.0 
      
            # Scaling and adding an instance of the filament
            @scale      = @lineVector.length.to_f / filament.bounds.height   #width #depth 
            @trans      = Geom;;Transformation.scaling 1, @scale, 1
            @instance   = Sketchup.active_model.active_entities.add_instance( filament, @trans )
      
            # if needed rotate the filament
            @lineVector.normalize!
            @instYaxis  = Geom;;Vector3d.new( 0, filament.bounds.height, 0 ).normalize #height givs the Y axis
            @rotDeg     = @instYaxis.dot( @lineVector )
            @rotDeg     = Math;;acos( @rotDeg )
            if @rotDeg.to_f - 1e-6 > 0.0
              if @rotDeg.to_f + 1e-6 > Math;;PI 
                @rotVector = Geom;;Vector3d.new( 0, 0, 1 )
              else # if PI
                @rotVector = @instYaxis.cross( @lineVector )
              end # if PI
              @trans       = Geom;;Transformation.rotation( ORIGIN, @rotVector, @rotDeg )
              @instance.transform!( @trans )
            end # if @rotDeg > 0.0
      
            # Moving the filament to the startPoint
            if not ( ORIGIN == startPoint )
              @trans       = Geom;;Transformation.new startPoint 
              @instance.transform!( @trans )
            end #if not ORIGEN
          end
      
      
      1 Reply Last reply Reply Quote 0
      • sdmitchS Offline
        sdmitch
        last edited by

        David, You did a bit more work than was required. The entire section regarding rotation is not needed. You only need to add ", @lineVector" to the last Transformation

        def add_Filament( startPoint, endPoint , filament )
              @lineVector = startPoint.vector_to endPoint
              return if @lineVector.length.to_f - 1e-6 < 0.0 
        
              # Scaling and adding an instance of the filament
              @scale      = @lineVector.length.to_f / filament.bounds.height   #width #depth 
              @trans      = Geom;;Transformation.scaling 1, @scale, 1
              @instance   = Sketchup.active_model.active_entities.add_instance( filament, @trans )
        
              # Moving the filament to the startPoint
              if not ( ORIGIN == startPoint )
                @trans    = Geom;;Transformation.new startPoint, @lineVector
                @instance.transform!( @trans )
              end #if not ORIGEN
            end
        
        

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

        http://sdmitch.blogspot.com/

        1 Reply Last reply Reply Quote 0
        • D Offline
          Davidfi1
          last edited by

          Do I need to do the checking ORIGIN etc..?
          Or it should be:

          
          def add_Filament( startPoint, endPoint , filament )
             @lineVector = startPoint.vector_to endPoint
             return if @lineVector.length.to_f - 1e-6 < 0.0
          
             # Scaling and adding an instance of the filament
             @scale      = @lineVector.length.to_f / filament.bounds.height   #width #depth
             @trans      = Geom;;Transformation.scaling 1, @scale, 1
             @instance   = Sketchup.active_model.active_entities.add_instance( filament, @trans )
          
             # Moving And Rotating the filament to the @lineVector
             @trans    = Geom;;Transformation.new startPoint, @lineVector
             @instance.transform!( @trans )
          end # def add filament
          
          

          P.S - Why filament.bounds.height is the length of the Y axis of the component?
          I thought height is the Z axis - no?

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

            No you don't need the ORIGIN check. Since you don't specify a location when adding the instance, it is by default placed at the origin.

            I agree, you would think height would be Z but no, bounds.width=X,bounds.height=Y, and bounds.depth=Z.

            Doing the scaling when adding the instance is something I had never thought of so I learned something too.

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

            http://sdmitch.blogspot.com/

            1 Reply Last reply Reply Quote 0
            • D Offline
              Davidfi1
              last edited by

              hhh - doesnt work πŸ˜„
              All our work for nothing

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

                @davidfi1 said:

                hhh - doesnt work πŸ˜„
                All our work for nothing

                Why doesn't it work? How is it failing?

                Provide screen shots or sample model.

                How the component is made and the axes defined will always determine how it orients when placed.

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

                http://sdmitch.blogspot.com/

                1 Reply Last reply Reply Quote 0
                • D Offline
                  Davidfi1
                  last edited by

                  Well, In the documentation it says that if the second parameter is a vector
                  It will be used as a Z axis - this is what is happenening!.

                  Quote:
                  Geom::Transformation.new(origin, zaxis) creates a Transformation where origin is the new origin, and zaxis is the z axis. The x and y axes are determined using an arbitrary axis rule.

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

                    @davidfi1 said:

                    Well, In the documentation it says that if the second parameter is a vector
                    It will be used as a Z axis - this is what is happenening!.

                    Quote:
                    Geom::Transformation.new(origin, zaxis) creates a Transformation where origin is the new origin, and zaxis is the z axis. The x and y axes are determined using an arbitrary axis rule.

                    That's why I mentioned how the orientation of the component when created would be critical. If you could post a model with the component in it would make it much easier to figure out what you need to do to correct the problem. Just a wild guess but try this

                    		# Moving the filament to the startPoint
                    		xa,ya,za=@lineVector.axes
                    		@trans  = Geom;;Transformation.new xa,za,ya,startPoint
                    		@instance.transform!( @trans )
                    
                    

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

                    http://sdmitch.blogspot.com/

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      Davidfi1
                      last edited by

                      Thank you.
                      I will post the G-Code importer I am workin on soon
                      Then you could play with it and see if it is possible to make the original code more elegant.
                      The code I posted works!. It is a little ... well ... not very elegant - but it works πŸ˜„

                      1 Reply Last reply Reply Quote 0
                      • D Offline
                        Davidfi1
                        last edited by

                        Posted the first vertion of the importer at
                        http://sketchucation.com/forums/viewtopic.php?f=323&t=50067

                        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