Geom::Vector3d.linear_combination
-
This code produces a vector between
vector1
andvector2
.vector = Geom;;Vector3d.linear_combination 0.5, vector1, 0.5, vector2
This code produces a vector 3/4 way between
vector1
andvector2
.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?
-
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,
-
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. -
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. -
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
-
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?
-
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
Advertisement