# Generating Block Circles

I have a function that puts a block at (x,y,z)

Note: For now, assume y is 0, as offsets ect. can be made later.

My goal is to make an generator which makes a 2d “block” circle.

Currently, It’s not working so well. My end goal is a equation which can make a circle like this (with varried radius) Currently, I have this:

``````	local r = 20
for x=-r,r,unitSize do
local n = math.floor((math.sqrt(-(x^2) + (r^2)))/unitSize)*unitSize
placeObj(Vector3.new(x,20,n))
placeObj(Vector3.new(x,20,-n))
end
``````

4 Likes

Trigonometry approach:

``````local radius = 20
local number_of_parts = 20
local circle = math.pi * 2

for i=1, number_of_parts do
local angle = circle / number_of_parts * i
local x_pos = math.cos(angle) * radius
local y_pos = math.sin(angle) * radius

local part = Instance.new('Part', workspace)
part.Size = Vector3.new(1,1,1)
part.Anchored = true
part.Position = Vector3.new(x_pos, 0, y_pos)
end
``````

You may want to round the position to the grid from what I see.

Or if you have the “nodes” already, you can just check magnitude from center to each node.

17 Likes

Is it possible to implement `CFrame:ToObjectSpace()` to position in ratio to the “grid” present? Or would it be too complicated? I can’t figure out a way to implement this.

I know I can make a circle, the problem I’m having is making it work in a grid fashion

Dividing and math.floor works for me most of the times
Depending on what you want to make, you’d need different approaches.

I’m not exactly sure what do you want to achieve with ToObjectSpace, but in the end, you’d have to go back to diving and math.floor from what I can think of.

I’ve tried using math.floor like this:

``````math.floor(y_pos/unitSize)*unitSize)
``````

It seems to act weirdly, though

I just thought it would be easier to position the parts using CFrames in relation to the grids CFrame (kind of like an index). But the solution you proposed above works too.

Better add an extra bracket with that. What was “weird” about it?

Thanks for the help, I used

``````math.floor((y_pos/unitSize)+0.5)*unitSize)
``````

to fix it in relation to the grid

You could also just use this:
https://www.mathopenref.com/coordcirclealgorithm.html