• Login
sketchucation logo sketchucation
  • Login
πŸ”Œ Quick Selection | Try Didier Bur's reworked classic extension that supercharges selections in SketchUp Download

Geom::Vector3d.linear_combination

Scheduled Pinned Locked Moved Developers' Forum
7 Posts 4 Posters 454 Views 4 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
    thomthom
    last edited by 24 Feb 2009, 11:15

    This code produces a vector between vector1 and vector2.

    vector = Geom;;Vector3d.linear_combination 0.5, vector1, 0.5, vector2
    

    This code produces a vector 3/4 way between vector1 and vector2.

    vector = Geom;;Vector3d.linear_combination 0.25, vector1, 0.75, vector2
    

    What I don't understand is why there's two weight arguments.
    Why isn't it:

    vector = Geom;;Vector3d.linear_combination vector1, vector2, 0.75
    

    ?

    What happens if you do this:

    vector = Geom;;Vector3d.linear_combination 0.25, vector1, 0.25, vector2
    

    ? What kind of value is returned then?

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

    1 Reply Last reply Reply Quote 0
    • S Offline
      scottlininger
      last edited by 24 Feb 2009, 18:08

      Hey Thom,

      The weights don't strictly have to be between 0 and 1 or add up to 1, but that's generally what you want. What's happening is each vector's length is being multiplied by its weight, and then they are combined.

      Here are some examples:

      # This yields Vector3d(0.5, 0.5, 0)
      Geom;;Vector3d.linear_combination 0.5, [1,0,0], 0.5, [0,1,0]
      
      # This yields Vector3d(1, 1, 0)
      Geom;;Vector3d.linear_combination 1.0, [1,0,0], 1.0, [0,1,0]
      
      # This yields Vector3d(2, 1, 0)
      Geom;;Vector3d.linear_combination 2.0, [1,0,0], 1.0, [0,1,0]
      
      # This yields Vector3d(2, 1, 0)
      Geom;;Vector3d.linear_combination 1.0, [2,0,0], 1.0, [0,1,0]
      
      

      Best way to get your head around it is to type some variations into the console. (That's what I did. Let me know if you see any weirdness and I could peek at the source code to be sure. πŸ˜„)

      Cheers,

      • Scott Lininger
        SketchUp Software Engineer
        Have you visited the Ruby API Docs?
      1 Reply Last reply Reply Quote 0
      • T Offline
        thomthom
        last edited by 24 Feb 2009, 21:40

        So, to produce a vector which is an average between two normals, is this the right method, or should it be by making a Transformation of each vector and use the Transform.interpolate method?
        I was playing around in the console with these methods and I seemed to get the same results.

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

        1 Reply Last reply Reply Quote 0
        • J Offline
          Jim
          last edited by 26 Feb 2009, 01:08

          This is probably a dumb question, but what is a practical application of a linear_combination? I'm not sure I would recognize when it would be useful.

          Hi

          1 Reply Last reply Reply Quote 0
          • C Offline
            Chris Fullmer
            last edited by 26 Feb 2009, 02:01

            I just recently used it to find an edge normal (or whatever the accurate technical term is). It is for my vertical line maker script, now I'm adding "normal" line support. You can click on an edge, and my script draws a line along the edge normal, which is the linear combination of the 2 faces that the edge has contact with. In my case, I am just using 50/50 weight because I want it to be precisely in between the 2 face normals. I'm sure there's reasons to weight it differently. Maybe for things that manipulate geometry with weight values, like the smoove tool?

            Chris

            Lately you've been tan, suspicious for the winter.
            All my Plugins I've written

            1 Reply Last reply Reply Quote 0
            • J Offline
              Jim
              last edited by 26 Feb 2009, 02:09

              Aha! Like Joint PushPull where you might have a vertex at the common location of 3 faces, and then you can get a vector from the normals of all 3 faces to use when extruding the faces?

              Hi

              1 Reply Last reply Reply Quote 0
              • C Offline
                Chris Fullmer
                last edited by 26 Feb 2009, 02:18

                That is exactly right. Thats a great script that probably makes prodigious use of that method. Now if only I could figure out the rest of the vector3d methods πŸ˜•

                Chris

                Lately you've been tan, suspicious for the winter.
                All my Plugins I've written

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

                Advertisement