Transformation / rotate of an existing component
-
hi,
i just cant get thru the syntax of transformations and need a small help at one point:i have a component defined and would like tu turn it along the vector-axis.
so (all within a module)- the vector and the point and the angle are defined
- the component is there (works perfectly without the last 3 lines below)
but
@m_pf_l = group.to_component # existng group to component defn = @m_pf_l.definition defn.name = "@m_pf_l" point = [0,0,0] # my point transformation = Geom;;Transformation.rotation point, vector, 45 t = defn.transformation
this code does not work. i know, i have a wrong connection to the component instance (i tried differet syntax-variantions), but
i don't want to use the code from the api-guide, since there they ADD an instance, but i want to turn the existing component.
so again, thanx for the tip
stan -
How about
### @m_pf_l = group.to_component defn = @m_pf_l.definition defn.name = "@m_pf_l" point = [0,0,0] # my point transformation = Geom;;Transformation.rotation(point, vector, 45.degrees) @m_pf_l.transform!(transformation)
Your
45
is 45 radians NOT degrees and worse still you are not applying the transformation to anything ?
I assume you want to transform the instance '@m_pf_l
' ?
You can't transform a definition - only entities, vertices, vectors, points etc - by various ways... -
hi tig,
yes, my problem was the right asignment...but to find this out with the ruby-api... :_)
so for one component it work for me.now i have an interesting issue with that:
i learned, that when i turn THE COMPONENT like this and
then make a instance (copy),
the new instance is not turned (transformed). i want to have the MASTER ELEMENT prepared and ready for copying.so i tried to turn the GROUP, before the component is created out of it:
group = entities.add_group @entities2 = group.entities new_line = @entities2.add_line pfm1, pfm2 # gives a vertical line @vector = new_line.line[1] point = [0,0,0] transformation = Geom;;Transformation.rotation (point, @vector, 45.degrees) group.transform!(transformation) # and then create a component @m_pf_l = group.to_component defn = @m_pf_l.definition defn.name = "@m_pf_l" componentinstance = entities.add_instance(@m_pf_l.definition, pf1) # pf1 is a defined point
to my surprise,
in the copy of the component then (new instance), the elements are also NOT TURNED.mysterious for me...
stan
-
You are jumbling rotating a 'container' and rotating 'its contents'.
If you have a rotation transformation 'tr
' and apply it to a group with:
group.transform!(tr)
Then that group is rotated about the point, but its entities [aka its contents] stay as they were relative to the container's internal axes - do it manually and edit the group to see the swiveled axes during the edit...
To rotate a group's entities use:
group.entities.transform_entities(tr, group.entities.to_a)
Then the entities are rotated inside the group.Alternatively, rotate the group and make it into a component - the new instance has the transformation of the original group. To replicate the placement with another instance you need to copy the original transformation and apply it when you add the new instance...
-
hi tig, thanx, that's the point.
i understood before, that "transforming " the container (group or component) has to be applied to the instances, too.
with your code i now have the desired access to its entities! wonderfull, thanx for that,
it works now , every transformation is passed to the component instances.
in that point, the ruby-skp-api gives too few syntax to play with...
thank you.
stan -
post scriptum:
now the transformations of components (turning around z) work,
but i found out, taht the bounding box ( = component internal axes) won't change with the transformation.
i read a lot topics about it, but found no solution.so, has the api a function to say something like
t = transformation...whatever....component_axes (point, angelx, angle y, angle z) ??
this would be very uswfull to prepare the components for use's edit in right directions!
thanx stan
-
An object like a group has a bounding-box with its XYZ axes a parallel to the groups' internal XYZ axes.
So if the geometry inside the group is made parallel to its internal axes then its bounds hug the geometry.
If you rotate the group its bounds rotate with it.
If you rotate the geometry inside the group then it is rotated relative to the group's internal axes.
So although the visible geometry is rotated the bounds stay as they were - now skewed...tr=Geom::Transformation(point, axis, angle) group.transform!(tr)
Rotates the group [AND its geometry inside] so the bounds rotate.
tr=Geom::Transformation(point, axis, angle) group.entities.transform_entities(tr, group.entities.to_a)
Rotates the group geometry inside BUT leaves the group where it was, so the bounds do not rotate - so it is skewed...
If you have skewed geometry that is made into a group the group.bounds are skewed relative to the geometry. To fix this first rotate the group then rotate the geometry in the opposite direction [use tr.inverse].
Visually it's unchanged but the bounds now match the geometry and the group is actually rotated...tr=Geom::Transformation(point, axis, angle) group.transform!(tr) group.entities.transform_entities(tr.inverse, group.entities.to_a)
Advertisement