Mick Hazelgrove wrote:
>
> I want to translate an object. I often come across the situation where I
> want to randomly add a increment to a translation either side of zero. ie
> translate x* (+or - increment) usually in a loop.
>
> I've used mod to alternate either side of zero but I'd like it to be random.
There are many solutions to this problem.
Below you can find two of my suggestions.
If you have prepared your randomization seed
e.g. like this:
#declare RR = seed(314);
Then to get what you wrote in the first post;
x (+ or -) y
you could write:
x + (2*int(rand(RR) + 0.5) - 1)*y
or
x + (rand(RR) > 0.5 ? 1 : -1)*y
To get what you wrote in your second post;
x* (+or - increment)
you could write:
x*(2*int(rand(RR) + 0.5) - 1)*increment
or
x*(rand(RR) > 0.5 ? 1 : -1)*increment
Tor Olav
--
mailto:tor### [at] hotmailcom
http://www.crosswinds.net/~tok/tokrays.html
Post a reply to this message
|