Author Topic: Rescaling (in x y z or all three) a plane or a part of a solid  (Read 2591 times)

samdavo

  • Hero Member
  • *****
  • Posts: 2587
  • the trick is knowin...^ > v < - which way's up?
This is just a modified version of prl's macro mtpm.d3m
I call it rapps.d3m  (rescale a plane or part of a solid - or grid - or mixture of planes )...

Both macros work on a solid, (or a grid), in point select mode.
However, whereas prl's macro changes a planar shape into a circle, with a rough scaling factor - 
this one simply scales EVERY point selected, and by a magnification factor (mf) that you input.
(or mfx, mfy, mfz as an alternative).
Note that a negative mf will give you a cross-over.

The "expansion centre" can be either the average of the points selected (the default),
or the origin (which you can obviously re-define immediately before running the macro)

(edit) probably best to use Origin - see below.

When would you use it?
Suppose you have extruded a cylinder - OR ANY OTHER SHAPE - into the z direction, and you want to exaggerate it's perspective taper.  You simply go to point select mode, select all points at the far end, and then run the macro.

(see the Superman perspective, reduced to 30% at one end)

Or maybe you have holes in a plate which you want to double in x and y directions, - or halve -
or maybe stretch by factor of 2 in x dirn relative to one end ( which must be made the origin at the outset) ... Hence plate D becomes plate E.

cheers
sam

PS I am confident that the macro could be improved - in keeping with my amateur status with such macros.

PS I have had to make the macro capable of amending a stack of points, up to 4000,  otherwise it couldn't handle the Superman example (2 cents)
« Last Edit: March 22, 2015, 02:44:01 AM by samdavo »

samdavo

  • Hero Member
  • *****
  • Posts: 2587
  • the trick is knowin...^ > v < - which way's up?
Re: Rescaling (in x y z or all three) a plane or a part of a solid
« Reply #1 on: March 20, 2015, 11:52:45 PM »
Likewise, herewith an extruded cylinder, which has been crushed (as an afterthought) using some slices,  and applying the macro to the points so created.  - Indeed, the points you change need not even be in the same solid or grid ,  i.e., you can amend two adjacent solids or grids at the same time.

PS the closest end of the pipe has been magnified with magnification factors, mfx, mfy, and mfz,
of
-2, -2, and +1 resp, - hence a comment in there somewhere that negative factors will reverse the shape,
« Last Edit: March 21, 2015, 12:39:31 AM by samdavo »

prl

  • Hero Member
  • *****
  • Posts: 3389
  • A Bézier Extrusion
Re: Rescaling (in x y z or all three) a plane or a part of a solid
« Reply #2 on: March 21, 2015, 01:20:42 AM »
a modified version of prl's macro mtpm.d3m  I call it rapps.d3m

This is what makes the forum shine in my opinion.  Taking something; exploring it, improving it, pondering it, then creating something better, and sharing it.  Thanks Sam.

samdavo

  • Hero Member
  • *****
  • Posts: 2587
  • the trick is knowin...^ > v < - which way's up?
Re: Rescaling (in x y z or all three) a plane or a part of a solid
« Reply #3 on: March 21, 2015, 01:25:25 AM »
thanks prl
I'm not sure why you checked for any duplication of points in your macro - and certainly in my case, I don't think it would make any difference, (edit - since then I've changed my mind ...)  but I've left it there  (and crossed my finders that "count" and "new count" correctly adjust itself when it deletes a duplication).
« Last Edit: March 21, 2015, 10:44:57 PM by samdavo »

prl

  • Hero Member
  • *****
  • Posts: 3389
  • A Bézier Extrusion
Re: Rescaling (in x y z or all three) a plane or a part of a solid
« Reply #4 on: March 21, 2015, 01:38:49 AM »
I'm not sure why you checked for any duplication of points in your macro -

Can't remember why I did that.  I know it slows down the macro because it is a brute-force clumsy subroutine.

samdavo

  • Hero Member
  • *****
  • Posts: 2587
  • the trick is knowin...^ > v < - which way's up?
Re: Rescaling (in x y z or all three) a plane or a part of a solid
« Reply #5 on: March 21, 2015, 02:03:54 AM »
PS I'm also sure it shouldn't regen after each change of point - but I forget the magic words to turn that off .

You remember Elma Fudd outside the cave (complete with anti-rabbit shotgun), and Bugs Bunny inside hiding,  and him asking "O Great Hunting Spirit, tell be what to do...  " ,,, well sometimes I feel like Elma Fudd here lol.
cheers

PS I enclose that tapered-Superman dcd file - if you select all points at the far end, you can either zoom it down even more, or zoom it up by (1/ 0.3) to get the original prismatic version - but it takes more than a minute - BECAUSE of that regen problem, and the number of points involved.

PS I enclose the original prismatic- Superman dcd file. In case anyone wants to play around with this.   I am guessing I am pushing my luck too far when I try to reduce one end to , say 25%, then back to normal.  A few points seem to become corrupted each time I've tried that - but simple planes and parts are no problem.
« Last Edit: April 16, 2015, 03:04:08 PM by samdavo »

prl

  • Hero Member
  • *****
  • Posts: 3389
  • A Bézier Extrusion
Re: Rescaling (in x y z or all three) a plane or a part of a solid
« Reply #6 on: March 21, 2015, 03:25:39 AM »
PS I'm also sure it shouldn't regen after each change of point - but I forget the magic words to turn that off .

Sam, remove the >redraw in the newpoint subroutine and make additions in blue

.
.
cont2:

sys(36)=2
for j = 1 to count
  ex2 = rx(j)
  ey2 = ry(j)
  ez2 = rz(j)
  gosub newpoint
next j

sys(1) = 0
sys(36)=0
regen

End

JJG

  • Hero Member
  • *****
  • Posts: 715
Re: Rescaling (in x y z or all three) a plane or a part of a solid
« Reply #7 on: March 21, 2015, 04:44:36 AM »
I gave a macro for doing such things, in the past :
http://forum.designcadcommunity.com/index.php?topic=3103.msg16654#msg16654
You should read the previous messages in this topic too.
 ;)

minstrel

  • Hero Member
  • *****
  • Posts: 700
Re: Rescaling (in x y z or all three) a plane or a part of a solid
« Reply #8 on: March 21, 2015, 10:05:24 AM »
Now, too cool!

Real nice one sam.  I was astounded with prl's initial mtpm.d3m and now you added even more goodies to it!

It makes it so easy to take a simple cylinder and morph it into a sledgehammer head....easy as 1-2-3 [mag, that is]
Thanks for another keeper!

...and prl's minor redraw tweek now makes it all happen instantaneously!  [Although is pretty neat to watch the performance in action...so I'll keep two versions.  One for those rushed and frantic moments; the other for leisurely entertainment]

JJG - I will dig up your marco and see what else can be done. 

Thanks again, to all you 'MacroFanatics'

samdavo

  • Hero Member
  • *****
  • Posts: 2587
  • the trick is knowin...^ > v < - which way's up?
Re: Rescaling (in x y z or all three) a plane or a part of a solid
« Reply #9 on: March 21, 2015, 03:45:22 PM »
JJG - thanks - Again there are mountains of good posts, macros and advice back there in those very valuable  archives, and I will certainly look at those particular macros as well.  :) 

(edit) After checking that thread a bit more thoroughly - I point out one difference between your macro and mine - and that is that mine is intended to work with point select mode, and a part of a solid, etc - not the full solid - as such, (think I am right),  normal handles don't work too reliably,  cheers 

Minstrel,
thanks also -
and that's my OTHER favorite quote ...  "when the only tool in your toolbox is a hammer, it's amazing how every problem that presents itself starts to resemble a nail".  :)
(but my favourite is prl's "My aim in life is to become the person my dog thinks I am").

PS I suspect that the "twisted sausage skin" effect that I posted in the final jpeg reply #1  above
And a better example attached here, called a twisted toffee wrap ...

(edit) refer next post, which is more accurate

 ( i.e. where I use a negative magnification value to reverse one of the circles), ...
 is effectively twisting every plane - SO THAT, (I imagine, - maybe, maybe not - you might like to confirm and maybe post the result), were you to import that into Sketchup, then the "plane" would only be coloured at one or other side of the twist in question. 

« Last Edit: March 22, 2015, 04:05:28 AM by samdavo »

samdavo

  • Hero Member
  • *****
  • Posts: 2587
  • the trick is knowin...^ > v < - which way's up?
Re: Rescaling (in x y z or all three) a plane or a part of a solid
« Reply #10 on: March 21, 2015, 06:30:14 PM »
I enclose a simplified more accurate version of the macro, rapps3.d3m, which
no longer offers the option of the average of the points as the expansion centre -
mainly because I found, for a circle for instance, that there are points at both start and end of the circle, and you get a warped-average effect as a result.  (probably partly why prl went to the lengths he did at the time, to eliminate duplicates).

Hence, with this latest macro, you have to set a new origin (eg and a temp working plane will achieve that if you don't want to change the old origin).

And I recommend using three magnification factors (rather than 1), "mfx, mfy, and mfz"  - and with the example enclosed, I used -1.5, -1.5, and 1.0   - reason being that it gives you more flexibility on where you set origin - eg if you look at the jpeg, the origin is the centre of the circle in the foreground (2 cents)

More accurate/reliable.
cheers
sam

PS minstrel
it also asks if you want to redraw each step (and gives you the option of yes or no ) - all to do with prl's suggested changes in reply #6 (and, if you opt for no = the default, then it is significantly quicker, eg for the superman example) - 2 cents
« Last Edit: March 21, 2015, 11:01:55 PM by samdavo »

prl

  • Hero Member
  • *****
  • Posts: 3389
  • A Bézier Extrusion
Re: Rescaling (in x y z or all three) a plane or a part of a solid
« Reply #11 on: March 22, 2015, 01:47:10 AM »
because I found, for a circle for instance, that there are points at both start and end of the circle . . .probably partly why prl went to the lengths he did at the time, to eliminate duplicates.

Sam, you are getting very good at all this!   You are starting to think like me . . . . same first and last points on closed planes do cause problems in odd little ways.  Other examples, a rectangle is defined by 5 points, a triangle by 4 four points etc.

samdavo

  • Hero Member
  • *****
  • Posts: 2587
  • the trick is knowin...^ > v < - which way's up?
Re: Rescaling (in x y z or all three) a plane or a part of a solid
« Reply #12 on: March 22, 2015, 02:52:25 AM »
prl
it's all about truth, justice, macros, and the American way !
ps thanks for your countless contributions to the forum.
And gee I wish I did think like you lol, but ...  I do cook a decent pancake - (provided someone else made the mix) - does that count?
« Last Edit: March 22, 2015, 02:56:00 AM by samdavo »