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
Thank you for your time.
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)
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.
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:
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
to fix it in relation to the grid
This page might be helpful for those who want some more intuition behind it:
In computer graphics, the midpoint circle algorithm is an algorithm used to determine the points needed for rasterizing a circle. Bresenham's circle algorithm is derived from the midpoint circle algorithm. The algorithm can be generalized to conic sections.
The algorithm is related to work by Pitteway and Van Aken.
This algorithm draws all eight octants simultaneously, starting from each cardinal direction (0°, 90°, 180°, 270°) and extends both ways to reach the nearest multipl...