cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

How to modify nested (to some degree) objects?

ptc-4604403
1-Visitor

How to modify nested (to some degree) objects?

Hello.

This is crucial to my project yet I have to admit I've hit a brick wall and cannot figure this out...

Let's say there is an object X and a defined transformation function transf().

Now there may be a need to directly transform my object - it would be transf(X) - and that works perfectly fine.

There may be a need to transform my object one step "deeper" - it would be vectorized transf(X) - and that works perfectly fine as well.

However how about transforming my object N steps "deeper"? Like generating all such results:

depth.jpg

Objects' structure is not known beforehand and is not fixed so I cannot write loops (while, for). Vectorization, recurssion has to be the answer... If it was C++ I would pass "memory address" and alter different portion of my object that way, but I'm not aware of a similar concept in Mathcad.

3 REPLIES 3
StuartBruff
23-Emerald III
(To:ptc-4604403)

You could try modifying shapeOf by passing transf in as argument, replacing the "for n elem N" loop with a "for k = 1 .. N" loop and then applying transf to Nk (if it's an object) or (recursively) applying shapeOf to Nk otherwise.

Not sure what you meant by that loop or, more specifically, how would one be able to initiate iterations in a single loop, but I think I'm starting to get the idea (by looking at shapeOf) and I wrote

deep.jpg

Which seems to work...

Wow, I guess it's good to ask something anonymously on the internet because I feel embarassed right now

StuartBruff
23-Emerald III
(To:ptc-4604403)

Pranas Pranas wrote:

Not sure what you meant by that loop or, more specifically, how would one be able to initiate iterations in a single loop, but I think I'm starting to get the idea (by looking at shapeOf) and I wrote

deep.jpg

Which seems to work...

Wow, I guess it's good to ask something anonymously on the internet because I feel embarassed right now

Yes, that will work ... The Recursion is strong with this one.

http://www.gifmania.co.uk/Star-Wars/yoda/sw2.gif

I had a few specific cases in mind when breaking it down into a loop (depending upon what you wanted to do with the results, but the vectorization will work as shown (if you trust your depth control, otherwise you might want to add an 'on error' handler when you do the function call and/or put an 'IsObject' check in).

Stuart

Announcements

Top Tags