• Login
sketchucation logo sketchucation
  • Login
πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Help with transformation

Scheduled Pinned Locked Moved Developers' Forum
14 Posts 3 Posters 343 Views
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 10 Jan 2013, 19:55

    Hi Guys
    I need some help using the correct Geom::Transformation.

    My task is to place a component and scale it's x axis, between two points.

    I need to figure out what is the Geom::Transformation needed for
    the add_instance method.
    Geom::Transformation.scaling xscale, 1, 1 will do the scaling
    Geom::Transformation.axes startPoint , xaxis, yaxis, zaxis
    moves the component to the first point and changes its axis

    How do I combine the transformations and what do I need to use for
    xscale, xaxis, yaxis, zaxis?

    Thank you
    David.

    1 Reply Last reply Reply Quote 0
    • D Offline
      Dan Rathbun
      last edited by 10 Jan 2013, 20:59

      It would be easier to just place the instance at the desired insert point, and then afterward apply the non-uniform scaling transform.

      Within some method:

      ipoint = Geom;;Point3d.new( x, y, z )
      tp = Geom;;Transformation.new( ipoint )
      ts = Geom;;Transformation.scaling( xscale, 1.0, 1.0 )
      inst = ents.add_instance( defn, tp )
      inst.transform!( ts )
      

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • D Offline
        Davidfi1
        last edited by 11 Jan 2013, 06:41

        Dan, what did you say about the second point?
        I need to rotate the new component's x axis to be in line with the two points.

        1 Reply Last reply Reply Quote 0
        • D Offline
          Dan Rathbun
          last edited by 11 Jan 2013, 07:13

          @unknownuser said:

          My task is to place a component and scale it's x axis, between two points.

          OK.. gotcha.

          You also need a y-axis vector

          def place_and_tweek( defn, pt1, pt2 )
            xvec = pt1.vector_to( pt2 )
            yvec = xvec.axes[1] # ???
            tp = Geom;;Transformation.new( pt1 )
            inst = ents.add_instance( defn, tp )
            ts = Geom;;Transformation.scaling( xvec.length, 1.0, 1.0 )
            inst.transform!( ts )
            ta = Geom;;Transformation.new( pt1, xvec, yvec )
            inst.transform!( ta )
          end
          
          

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • D Offline
            Davidfi1
            last edited by 14 Jan 2013, 20:09

            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
            • S Offline
              sdmitch
              last edited by 15 Jan 2013, 02:17

              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 15 Jan 2013, 05:37

                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
                • S Offline
                  sdmitch
                  last edited by 15 Jan 2013, 14:38

                  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 15 Jan 2013, 20:13

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

                    1 Reply Last reply Reply Quote 0
                    • S Offline
                      sdmitch
                      last edited by 15 Jan 2013, 20:49

                      @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 15 Jan 2013, 21:39

                        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
                        • S Offline
                          sdmitch
                          last edited by 15 Jan 2013, 22:41

                          @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 16 Jan 2013, 05:50

                            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 17 Jan 2013, 16:50

                              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
                              1 / 1
                              • First post
                                1/14
                                Last post
                              Buy SketchPlus
                              Buy SUbD
                              Buy WrapR
                              Buy eBook
                              Buy Modelur
                              Buy Vertex Tools
                              Buy SketchCuisine
                              Buy FormFonts

                              Advertisement