Flip along Z
-
### untried code... instance=selection[0] definition=instance.definition ### find point for rotation point=instance.transformation.origin ###? ### or point=definition.origin ###? ### or point=??? tr=Geom;;Translation.scaling(point,1,1,-1) instance.transform!(tr) ### flips instance about it's z axis = -1
-
If you want the centre simply find the instance's bounds and the centre of that
point=instance.bounds.center
Then use that in my scaling transformation - a flip is just a scale -1 in any axis... -
Thanks TIG, I'll play with that. I had tried scaling to -1, but I think I was doing it wrong because I was scaling with a uniform factor of -1 and my component kept disappearing.
I did evenetually get this to work by flipping the way I showed above and then moving the origin as needed so that the component looks like it stays put. But this is requiring determining the pre-existing scale on the component (which I finally got that working too).
Anyhow, I think I have it working now, but I'll play with yours because it might be signinficantly easier Thanks!
Chris
-
So it seems I massively overthought this one.
All I really wanted to do was rotate an object using its x local x or y axis, 180 degrees.
Scaling uniformly with
Geom::Transformation.scaling center_point, -1, -1, -1
also gives an acceptable result. Thanks for pulling my head out (of the clouds) TIG You wouldn't believe the silliness I was going through using the point.offsets and vector scaling to get this to do what I wanted.......
Chris
-
Scaling -1 would be mirroring - not rotating.
-
Yes, and I think I like it as an option to include in what I'm working on. I think the rotation does closer to what I had in mind, but I'll throw in the mirroring if the user has ctrl-atl-option-prt_scrn-num_lock held down or something
Chris
-
Yea, speaking of what you're working on... what are you working on? Your transformation talk here recently has had be pondering.
-
Not much, I am adding a flipping capability to my componnet stringer. So its a tool that lets the user click on the string of components and it will flip them all so they are facing the other way.
But I've been using this as an excuse to attempt to learn the matrix and I've picked up some interesting things for sure!
Heres a snippet. This will tell you how much the selected component/group has been scaled in the z direction:
gp = Sketchup.active_model.selection[0] gpt = gp.transformation.to_a z_vec = Geom::Vector3d.new( gpt[8], gpt[9], gpt[10] ) z_scale = z_vec.length / gpt[15] z_scale
(I run that in the Jim's web console, with a group selected).
That is one of the things I was needing to know - just the z-scale.
I am holding on to hope that I might be able to figure this thing out yet!
Chris
-
Chris
Have you looked at my additional methods here http://forums.sketchucation.com/viewtopic.php?p=190874#p190874
-
How did I miss that? Thanks TIG! Reading through what it does, I think I can do around 1/2 of that now with the matrix. Mostly its just the rotation stuff that I still get lost on. I'm intersted to check out the code. Thanks for pointung me to it!
Chris
-
well in the end, I've had to mix and match some thoughts from this thread. I realized that I can ont doa simple rotation or scaling because in my case, I have to scale using the components local axis. If their axis is set on one of the sides of the component, I want it to rotate or scae around that axis, not the boundingbox centerpoint.
So I just threw in a way to determine the the center of the component on the local z axis. Had to account for component z-scaling AND if the axis was set somewhere inside the component (not at the very bottom for example). All in all, I've got it working like a charm now (I think!). It will be in the next component stringer.
Chris
Advertisement