Changing transformation variables
-
Isn't a transformation an array? I get an error message when I a_transformation[12= 0.5], so my guess is that the transformation's name ("a_transformation") is not the array's name(?) Can I change a single transformation's variable value? Btw: I am a matrix math neophyte.
-
@honoluludesktop said:
Isn't a transformation an array? I get an error message when I a_transformation[12= 0.5], so my guess is that the transformation's name ("a_transformation") is not the array's name(?) Can I change a single transformation's variable value? Btw: I am a matrix math neophyte.
tra=object.transformation
.to_a
###to array
tra[12]=0.5 object.transformation=tra
This reset the item 12 in the transformation (the X location value) to 0.5... -
Thanks TIG, I kew it had to be something simple
-
I think there are many of us Matrix math newbies around here. But little by little we're comprehending some of this stuff. So don't be bashful.
The problem you are running into is that a_transformation is NOT an array object. It is a transformation object. Run this:
t = Geom;;Transformation.new([2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1]) arr = [2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1] t_arr = t.to_a puts t.class puts arr.class puts t_arr.class
"t" is class
Geom::Transformation
. "arr" is classArray
. It just so happens that transformation objects contain data that can be output to look like an array, but they are not actually arrays at all. To retrieve their array, or present their data in array form, use the.to_a
as I did in the example. So to change a transformation array element, you have to get the transformation, turn it into an array. Adjust the elements on that array. Then turn that array back into a transformation object. Then apply that transformation to your object. It might look like this:` gc = Sketchup.active_model.selection[0]
t_exist = gc.transformation.to_a
t_exist[12] = 0
t_exist[13] = 0
t_exist[14] = 0t_new = Geom::Transformation.new(t_exist)
gc.transformation = t_new`That code works when you have an group/component selected and then run the code in jim's web console. It will move your component to 0,0,0 and keep it's scale and rotation.
Hope that gets things sorted out a little,
Chris
-
You guys are too fast for me today. I just made another mistaken post, failed to edit it, and then had to deleted it.
What I tried, which the SUCF server failed to accomodate was to edit my post, while deleting it on another page. So I could retain a copy. Well "no can do", and both my pages crashed. Hope I didn't cause any confusion.
Chris, thats neat stuff. Helps me to understand.
-
Why is it that you want to poke values into slots in the transformation matrix? This should almost never be necessary.
-
@martinrinehart said:
Why is it that you want to poke values into slots in the transformation matrix? This should almost never be necessary.
It is a quick way to 'drop' stuff to z=0...
tra=object.transformation.to_a tra[14]=0.0 object.transformation=tra
Do this inside a loop of all selected groups for example and they are all set onto the 'ground'...
-
Its a quick way to move to a given point, if you don't want to find the vector to that point from the current point. I think it is also necessary to skew a somponent, since there is no skew command built into the API.
-
-
.move! will reset the scale and rotation of a component. So its not useful the way it is implemented. You have to first make a transformation object that includes the components scale and rotation, then replace its x,y,z values by hand. THen apply that transformation object to the group using .move! if you want to use the move method safely.
Try it out, if you have an animnation working using the .move! method. Just scale the component first, then run your animation on it and you will see it resets it's scale and rotation.
It is possible to workaround, and that is why the transformation matrix must be edited by hand.
Chris
-
@chris fullmer said:
.move! will reset the scale and rotation of a component.
You are right. I still want to hear from Hawaii, though. Suspect that he might have overlooked a method.
-
Hi Martin, I originally posted an application that did some simple transformations, and became interested in the subject. As you know I am a beginner at all of this and while experimenting, I tried to change some values just to see how my components would behaved, failed to do so, and asked for help
-
@honoluludesktop said:
Hi Martin, I originally posted an application that did some simple transformations, and became interested in the subject. As you know I am a beginner at all of this and while experimenting, I tried to change some values just to see how my components would behaved, failed to do so, and asked for help
Fine. I was afraid you overlooked available ways of getting stuff moved / rotated / scaled. I know I did when I started fiddling.
Advertisement