Scale non-uniform along vector?
-
Thanks Dan. Appreciate it.
I have looked at the API. Can't get the comments working so I miss out a few "goodies" there I think..
But as far as I have gotten, scaling Non-uniformly takes 4 arguments. Orgin, scale x, scale y, scale z.
You second advice would have to be plan "B". I have thought of doing something like that, but I'll try to avoid it cause there is plenty of transformations done before the group is even on the face.
I'm working on a method (Cris code gave me an idea)that might possibly work. Just need to retrieve the group local x,z,y axis? If I can.. This is what I have got so far. Could probably use a case method...
You pass in the group, scaling, and vector. Where vector=(edge.start.vector_to(edge.end))def vec_scale(group, scaling, vector) #vector need to be parallel or perpendicular or scaling wont work. ##TRANS- and Center#### gents=group.entities bbox=group.bounds bbox_c=bbox.center group_x=group.transformation.xaxis group_y=group.transformation.yaxis group_z=group.transformation.zaxis if group_x.perpendicular? vector xscale = scaling else xscale = 1 end if group_y.perpendicular? vector yscale = scaling else xscale = 1 end if group_z.perpendicular? vector zscale = scaling else zscale = 1 end t = Geom;;Transformation.scaling(bbox_c, xscale, yscale, zscale) gents.transform_entities(t, gents.to_a)#Normaly you apply t to group. But I need to do it to entities. end
-
You should know that IF the DynamicComponents extension is loaded, it adds some methods for
ComponentInstance
andGroup
instance objects.for Group and ComponentInstance:
local_transformation() scaled_size() unscaled_size()
for ComponentInstance ONLY:
copy()
# works like Group.copy()
description()
and for DC ComponentInstances ONLY:
set_last_size(lenx,leny,lenz) last_scaling_factors()
-
Edit: Think the method works now
Not 100% tested in all angles yet. Changed my code in previous post.
-
Oops. Sorry Dan, must have typed while you post your message.
Your info: Really? Did not have a clue about that. Thats is good news for further developpment. Thank you.
-
Ah typical . Too early to celebrate.. It doesent work of axis= face tilted.
Get strange new error no implicit conversion to float from nil
I guess group_x=group.transformation.xaxisis only gonna work if the group is aligned to global axis. Therefore when tilted it has nothing=nil??
-
group.transformation.x_axis
is returning the vector of the component's local x axis. It should never return nil I don't think. I can't play with your code at the moment, but maybe later today I can test it out.
You should note that its possible/normal? for 2 vectors to perpendicular to the one you're testing against. So it will scale in 2 directions, not just one (I think).
-
gt=group.transformation og=gt.origin xa=gt.xaxis ya=gt.yaxis
[za=face.normal
orza=xa.cross(ya)
]
Use a rotation transformation about og and za by the angle_between xa and vector ?
Then do a scaling transformation along the xaxis only to match (vector.length / groupX.bounds.width) [where you have used add_instance on group.entities.parent [==definition] temporarily added to the face.parent.entities, at the origin with no further transformation as groupX ?]
Then invert the rotation transformation...
All done ? -
@unknownuser said:
is returning the vector of the component's local x axis
So it IS the local axis we are dealing with here. Since the scaling is only working on Global axis I persumed it wasen't. Thats good then(hopefully).
@unknownuser said:
You should note that its possible/normal? for 2 vectors to perpendicular to the one you're testing against. So it will scale in 2 directions, not just one
Uh oh That's NOT good! I will do some further testing to se if it fails.
Thanks for all your help.
-
Hello TIG. I typed when your answer came in. Bad timing today
Will try your code and report back. Looks interesting.
Thanks a million!!
-
I'm not sure I quite understand where to use you code, TIG. When Importing the component definition?
That could be difficult in this case...
This particular tiling is in it's own method. In the plugin there are other "tiling" methods. So cannot do any altering to the component def. before calling the method of choice. Unless I rewrite the definition loader-method. Could be done of course..In your code: vector.length / groupX.bounds.width. Is that to determine the scale?
The way this feature will work in the plugin, is that the USER determin number of rows, some code like: edge.length/numbers of rows to determin groupX.bounds.width.
So I'll add that part to your code-snippet?
Edited. Changed some info to clarify things, it's not good to write topics saturday nights :
I think Chris was right about conflicts i vectors(Edge can be perpendicular to 2 axes of course).
So I've scrapped that code..
See if I can incorporate TIG's code, and see if it works. I think I get the idea of it.
-
@unknownuser said:
gt=group.transformation
og=gt.origin
xa=gt.xaxis
ya=gt.yaxis
[za=face.normal
or za=xa.cross(ya)]
Use a rotation transformation about og and za by the angle_between xa and vector ?
Then do a scaling transformation along the xaxis only to match (vector.length / groupX.bounds.width) [where you have used add_instance on group.entities.parent [==definition] temporarily added to the face.parent.entities, at the origin with no further transformation as groupX ?]
Then invert the rotation transformation...
All done ?Is it that this code is to be used when comp.definition( or group) is at Origin=flat on "ground"?
Cause I get some funky results.. Havent tried "hard" yet. Will elaborate more after lunch....I've tried something like this where vector is edge:
gt=group.transformation og=gt.origin xa=gt.xaxis ya=gt.yaxis za=@face.normal #@face=reference to the face.selection za=xa.cross(ya) #?? x_to_vec=xa.angle_between vector tr1=Geom;;Transformation.rotation(og, za, x_to_vec)#req. rotation angle group.transform!(tr1) ts = Geom;;Transformation.scaling(og, scaling, 1, 1) group.transform!(ts) tr=tr1.invert! group.transform!(tr)
-
BTW:
This special kind of tiling method will not take any rotation(angle) other than 90.degrees as an argument. The group(hatches) will always have to be perpendicular to the edge.
-
the group is from its untransformed bounds [from a temporary instance of it added to the face.parent.entities].
You know how long the 'edge' is [edge.length] so you can work out the ratio of the two values...
Now you can use that to scale the group.entities with a scaling-transformation along the xaxis only... and thereby the original group is scaled as needed.
Erase the temporary instance of the group to tidy up... -
Yeah, thanks TIG. All what you say is true.
All these transformations got my head spinning. So I ditched the scaling in the tilingmethod. Went with scaling(y in this case) at ORIGIN, just after loading the component. Before placing it on the face. Not as flexible as in a method, but it will hopefully work. I think Dan suggested something similar, earlier on in this thread.
Maybe that's what you had in mind all along as well, TIG. I just coulden't see it then..
Edit: When I reread you thread, did you mean to scale entities and that would become a "local" scale? Cause i did some scaling in x or y and it was in fact a global scale. The group moved from the face and tilted, even when putting the origin at center of bbox. I can't recall 100% sure if it was the group OR the entities I scaled. Ah heck. I'll try tomorrow then.. Like I said, rather had this transformation separate in the tiling method..
Advertisement