Changing the orientation and position of the axis?
-
Hello all,
I am writing a little program with a user interface that is supposed to draw rectangular openings on a face that is user specified (with constraints) but I have run into a bit of a snag.
Here is the essence of my program:
-the a user draws a rectangle, with the rectangle tool, and is 'allowed' to translate and rotate this rectangle in the x-y plane
-based on the dimensions of the rectangle and some input for opening width and such, it is straightforward to define the four points of each opening...if the rectangle is just at the origin.
I've tried to make a transformation to the axes usingGeom::Transformation.axes origin, xaxis, yaxis, zaxis
,
but am unable to make these openings on the user's rectangle.
I think part of the problem is that I am misinterpreting what transformation.axes really does. Does anyone have any input as to how I could do this or a better explanation of transformation.axes or anything really?!
Thanks!
laura
p.s. if this is unclear, please, let me know -
I've had problems with the transformation.axes, too. To the best of my knowledge, which isn't that good, it rotates the part so that the transformation axes are aligned to the global axes. As for a possible solution, I found it easiest to just do the math to adjust for the face.normal.
-
Hi Laura,
Applying a transformation to geometry is available for groups and components.
If your user rectangle is not a group or component, you'll have to retrieve what the user did exactly (translation, rotation) with its rectangle. That's not simple IMHO.
If at first you make a group with the rectangle, then let the user translate/rotate it, it's really easy to draw openings in the rectangle because you can retrieve the group transformation and then draw your openings at origin and then apply the transformation to them, or each time you calculate a point of an opening boundary, apply the transformation to it:# Create the group; group=Sketchup.active_model.entities.add_group() # Draw the user rectangle here and let him translate/rotate it ... # get the group transformation; trans=group.transformation # Apply the transformation to a point of an opening; point.transform!(trans) # Explode the group if neede at the end of the draw; group.explode
Hope this helps,
Advertisement