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

    Transformation Newbie...

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 347 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.
    • T Offline
      tday
      last edited by

      Martin says this is the best newbie forum on Earth!
      http://www.martinrinehart.com/models/tutorial/tutorial_toc.html

      Although I can't consider myself a complete newbie - transformations make me feel that way:

      I'm trying to add a face entity to an existing group nested within a
      component instance. The model structure looks like this:

      model > dynamic component instance > group

      I'm trying to add a new face to the nested group through Ruby. There
      is no edit context when the ruby tool is initialized.

      the code:

      #@ip2,@ip3,@ip4 are input points defining three corners of the
      

      rectangular face
      #@ptCalculated is the fourth computed corner of the rectangular
      face
      #@spacegroupdef is the existing group inside a DC instance

      #put the rectangle in a group temporarily so the face and 4 edges
      

      can be transformed as a unit
      bumpgroup = @spacegroupdef.entities.add_group
      bumpgroup.name = "temp bumpgroup"
      #insert the new face
      face1 =
      bumpgroup.entities.add_face(@ip2.position,@ip3.position,@ip4.position,@ptCalculated)

      trans_array = Array.[](1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)
      
      #first, rotate - no rotation required
      
      #second, scale
      trans_array[0]= trans_spacegroup.inverse.to_a()[0]
      trans_array[5]= trans_spacegroup.inverse.to_a()[5]
      #If the transform! is conducted at this time, the scaling is
      

      correct

      #I'm sure the input point comes from within the existing face that
      

      is in the nested group
      trans_array[12] = -(@ip2_transformation.to_a()[12]) #Xt
      trans_array[13] = -(@ip2_transformation.to_a()[13]) #Yt

      new_transform_2 = Geom::Transformation.new(trans_array)
      
      bumpgroup.transform! new_transform_2
      

      The translation executes but it is not correct.
      I have tried using two separate transformations in different orders.
      First scale, then translate as above with the same result.

      Also first translate, then scale. In this case the translate works,
      but after applying the scale I get incorrect results.

      Not sure where I am going wrong. Any ideas about what I need to do to
      get the X and Y translation correct?

      Kind thanks!

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

        You are picking the points in the model.
        The group has a transformation within the component-definition
        The component-instance has a transformation within the model.
        You have four points.
        Make a transformation that uses the instance and group transformations [inverse] and apply that to the points [got from the ip's or calculated]
        Then add the face to the group from the transformed points...
        p2=@ip2.position
        p3=@ip3.position
        p4=@ip4.position
        p5=@ptCalculated
        tr=@spacegroupdef.transformation.inverse * spacegroup.transformation.inverse
        [p2,p3,p4,p5].each{|p|p.transform!(tr)}
        bumpgroup.entities.add_face(p2,p3,p4,p5)

        I haven't tested this but you need to somehow apply the containers' transformations backwards onto the face's points...

        TIG

        1 Reply Last reply Reply Quote 0
        • T Offline
          tday
          last edited by

          Thank you TIG,

          I understand the concept - and will let you know how it goes.

          T

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

            InputPoint.transformation
            http://code.google.com/intl/no/apis/sketchup/docs/ourdoc/inputpoint.html#transformation

            Gives you the transformation for the input point. Will probably be useful to you for converting between local and model co-ordinates.

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

            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