Re: How to generate random cubes within the domain of circle radius
You can place a cube inside a sphere (centered at the origin) by first
translating the cube on the X axis out to the radius of the circle, and
then generate random A and B values between 0-356, and rotating the cube on
2 axies. You'll have to do some minor tweaking to get the center right.
Hint: Use constants(variables) for all your numbers.
Code left as an exercise for the user. ;-)
Thus rasunag27 hast written on Mon, Jan 04, 2021 at 08:59:20PM -0700, and, according to prophecy, it shall come to pass that:
> Dear all,
> I am new to openScad. I want to generate random cubes on top of circle. The
> cubes should cover only the circle domain and not outside of it.
> I have written a script which takes x and y dimensions of cartesian
> coordinate and assigns the cube as a square.
> How to convert that to circular domain and assign only within the circular
> Below is the script.
> translate([0, 0, -0.5])
> circle(14, $fn = 50);
> for (x = rands(-14, 14, 50), y = rands(-14, 14, 50))
> translate([x, y, 0]) cube([0.5, 0.5, 0.5]);
> I have attached the circle and obtained cube image for reference.
> Image: Cubes on circle
> I do not want the cubes to go out of the circular domain. I tired working
> with "pi" value and using cosine and sine, but could not been able to do
> Any leads will be helpful.
> Thanks and Regards,
> Sunag R A.
> Sent from: http://forum.openscad.org/ >
> OpenSCAD mailing list
> [hidden email] > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
OpenSCAD Admin - email* me if you need anything, or if I've done something stupid...
* on the Forum, click on my MichaelAtOz label, there is a link to email me.
Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.
Firstly, I tried to implement your code and check the working method. But it
is giving me a parse error in the "let" method of function. Is there
anything I need to install or load to clear that error? I mean it is not
taking "let" method.
Thanks and Regards,
Sunag R A.
--------------- Original Message ---------------
There's a couple of more things that would need to be defined,
e.g. what happens with cubes at the border of the circle?
Assuming the cubes are placed safely inside and no requirements
regarding distribution, you could use random polar coordinates:
Thus rasunag27 hast written on Mon, Jan 04, 2021 at 11:06:32PM -0700, and, according to prophecy, it shall come to pass that:
> Since I tried to reinstall Openscad. As I am working in ubuntu, it is taking
> the version of 2015.03 - 1 only. It is not updating.
Ubuntu 18.04.5 LTS
You can install the snap with:
sudo apt update
sudo apt install snapd # If needed
sudo snap install openscad # Version 2019.05
sudo snap install openscad-nightly # Version 2021.01.03