[OpenSCAD] A possible solution, was Re: boolean logic in openscad
Dan Zuras 3D
threedee at nonabelian.com
Thu Oct 27 03:30:44 CEST 2011
> From: William Adams <william_a_adams at msn.com>
> To: <threedee at nonabelian.com>, <chrysn at fsfe.org>, <openscad at rocklinux.org>
> Subject: RE: A possible solution, was Re: [OpenSCAD] boolean logic in
> Date: Wed, 26 Oct 2011 22:51:33 +0000
> Thanks for the suggestions. I won't always be doing '&' with such a nice nu=
> mber=2C so having a generalized form that can deal with any bit pattern wou=
> ld be extra useful. The shifting=2C and general bit twiddling would be usef=
> ul as well. Perlin Noise is a concept from 3D Graphics. It is a basic comp=
> onent in procedural texture mapping. Whenever you see marble=2C wood=2C or=
> even landscapes that are generated algorithmically=2C there is probably us=
> age of Perlin noise=2C or something like it. I've played around with some s=
> imple procedural texture mapping in OpenScad. Now I want to up the game so=
> that I can see prettier pictures in the viewer. -- William
Again, I do not know of Perlin Noise.
Even so, let me suggest a few possibilities.
(1) If it is your purpose to use a linearly distributed
deterministic psuedo random number generator using the
operations available, there are many possibilities.
Those of the form (a*x) mod M probably have the most
history attached to them. The resulting formulae are
simple & easily understandable.
(2) If it is your purpose to implement functions of the
form (2^a*x) & (2^M-1) you now have a generalization of
the formula I gave you, namely (2^a)*(x mod 2^(M-a)) as
an equivalent calculation. The resulting formulae are
also simple & easily understandable.
(3) If it is your purpose to implement some more general
bit-twiddling, let me suggest that ANY arithmetic formula
no matter how inelegant or obscure can be hidden in some
formulae named bitAnd(x,y) or unsignedBitShift(x,s).
(4) Finally, if it is your purpose to find some 'efficient'
implementation of bit-twiddling in a language that does
not have it as a primitive, let me suggest that this is a
false optimization. Whatever it is you are using Perlin
functions for, OpenSCAD spends orders of magnitude more
time & space rendering the resulting solid than it will
in even the most inelegant & inefficient bit-twiddling
conceivable. We would help everyone far far more spending
time improving THAT than diddling the integer arithmetic.
You know your purpose. So you should know the best
approach to achieving it.
More information about the OpenSCAD