Rotating into XY plane
-
Hi all!
Is there some code around that will take any face and rotate it into the xy plane? -
Duncan,
The best is to use the Transformation class.
You need of course to indicate an origin point and an angle
The code below will work on a single face or a list of facesdef face_rotation_XY(list_faces, origin, angle) t = Geom;;Transformation.rotation origin, Z_AXIS, angle Sketchup.active_model.active_entities.transform_entities t, list_faces end
Fredo
-
Thanks Fredo,
I am thinking my question could have been phrased more clearly. I was looking for some code that will take an arbitrarily placed face (perhaps with no edges lying in the xy, xz, or yz planes) and transform it into the XY plane.
The transformation would be a combination of two rotations.
-
Thank you Fredo. I did in fact wish a privileged direction. Worked like a charm.
-
Nice example Fredo6:
Its too bad we don't have a permanent place to store these types of examples. Someone at SU should be collating this stuff, if not, at least to improve the totally sad state of affairs, where only words are used to describe how the Ruby API is to be implemented in SU.
Most programming languages use the same old irrelevant tired examples on how to learn programming.
Example: how to code "hello my name is?Here we have a 3d program, with a Ruby API, and the best description to date is to describe
the API in words, most of which don't even use synonyms in the description."A picture is worth a thousand words" ....... Hello out there SU technical staff!
Lets get a bit more creative, like the 1000's that use this program. -
Then, you can use a reverse Axis transformation.
The following code would for instance transform any given face to be in the XY plane, with its barycentre at the Origin.axes = face.normal.axes origin = face.bounds.center t = Geom;;Transformation.axes(origin, axes[0], axes[1], axes[2]).inverse Sktechup.active_model.entities.transform_entities t, face
The drawback of the above method is that the orientation of the transformed face in the XY plane is not predetermined.
So, if you wish to have a privileged direction, for instance an edge of the face to define the X axis, then use the following code instead, which will ensure that the selected <edge> defines the X axis, and that the Origin corresponds to the Start vertex of the edge.
origin = edge.start.position xvec = origin.vector_to edge.end.position zvec = face.normal yvec = zvec * xvec t = Geom;;Transformation.axes(origin, xvec, yvec, zvec).inverse
Note that you can use the transformation <t> to calculate the coordinates of points to reconstruct a copy of the face, instead of transform it.entities = Sketchup.active_model.entities face.loops.each do |loop| f = entities.add_face loop.vertices.collect { |v| t * v.position } entities.erase_entities f unless loop.outer? # for holes end
Hope this help!
Fredo
Advertisement