I want to create objects around a circle

I have already created objects around a circle with random position and radius
here is the problem
I want to place the objects only between 0-250° and 290-360°
As you can see in this code, objects appear around the circle as 360°
Now I want to remove objects between 250°-290°
what’s the solution?

here is my code :

for (const i = 1; i < 100; i++) {
const angle = Math.random() * Math.PI * 2;
const radius = 4 + Math.random() * 7;
const x = Math.cos(angle) * radius;
const z = Math.sin(angle) * radius;
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshStandardMaterial({
color: setTintColor(),
const cube = new THREE.Mesh(geometry, material);
cube.position.set(x, 0, z);

try this:
const angle = (Math.random() * 320 - 70) * Math.PI/180;

Thank you Raphael, it works
Can I change the center of rotation of Math.PI?
as you can see objects remove from center of the scene
I want to remove objects in a place other than the center of the scene

It’s hard to understand what you trying to do without a visual sample. But I guess you can try playing around by modifying the -70.

I’m sorry for that
I will try to explain more clearly
Usually, when we use Math.PI to create a circle with a desired radius, this circle is created at the center of the scene with the coordinates 0,0,0 and the specified radius.
Now, for example, I want the center of the circle created with Math.PI to be (2,2,0) and with the desired radius.
I made this image for better explanation

Isn’t it just a matter of offsetting the X and Z values to achieve the desired displacement?

Add your objects to a parent object or group and shift that parent to the desired location

as you can see X and Z values are random

yes X and Z
problem solved raphael
cube.position.set(x, 0, z - 2);
thank you

thank you forerunrun
Your tip helped me a lot

1 Like