[OpenSCAD] A possible solution, was Re: boolean logic in openscad
william_a_adams at msn.com
Thu Oct 27 00:51:33 CEST 2011
Thanks for the suggestions. I won't always be doing '&' with such a nice number, so having a generalized form that can deal with any bit pattern would be extra useful. The shifting, and general bit twiddling would be useful as well. Perlin Noise is a concept from 3D Graphics. It is a basic component in procedural texture mapping. Whenever you see marble, wood, or even landscapes that are generated algorithmically, there is probably usage of Perlin noise, or something like it. I've played around with some simple procedural texture mapping in OpenScad. Now I want to up the game so that I can see prettier pictures in the viewer. -- William
- Shaping clay is easier than digging it out of the ground.
> To: william_a_adams at msn.com; chrysn at fsfe.org; openscad at rocklinux.org
> CC: threedee at nonabelian.com
> From: threedee at nonabelian.com
> Subject: A possible solution, was Re: [OpenSCAD] boolean logic in openscad
> Date: Wed, 26 Oct 2011 14:50:09 -0700
> > Date: Wed, 26 Oct 2011 19:50:09 +0200
> > From: chrysn at fsfe.org
> > To: openscad at rocklinux.org
> > Subject: Re: [OpenSCAD] boolean logic in openscad
> > On Wed, Oct 26, 2011 at 01:36:10PM +0000, William Adams wrote:
> > > I am wanting to implement a function that has the following pattern
> > > func(x) = (x<<13) & 0x7fffffff[...]?
> > are you aware that this is just the same as func(x) = (x*8192) % 2147483648;
> > (that is, in more readable but non-openscad notation, x*(2^13) % 0x80000000)?
> > (at least, if you expect x to behave like an integer -- i couldn't
> > correlate your sniplet to the source code i found when quickly looking
> > it up.)
> > regards
> > chrysn
> I am not familair with Perlin functions but I
> think Chrysn here comes closest to a solution.
> Given his observation that the AND operation
> can be replaced by MOD in the case of a group
> of contiguious bits, the only missing operator
> in OpenSCAD is the shift operator. No big deal.
> Let me go just a bit further to find:
> func(x) = (x<<13) & 0x7fffffff
> func(x) = ((2^13)*x) mod 2^31
> func(x)/2^13 = x mod 2^18
> func(x) = (2^13)*(x mod 2^18)
> func(x) = 8192*(x mod 262144)
> which, I believe, can be implemented in many
> languages (including OpenSCAD) as
> func(x) = 8192*(x % 262144).
> Does that accomplish what you have in mind for
> Perlin functions?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the OpenSCAD