Filling gaps of a circle with N amount of parts

I’m trying to make a circle of parts but I don’t know how to resize the length of the parts in order to close out all the gaps on the outside of the circle. The inner side of the parts may overlap.

Currently I’m using the formula to find the length of the sides of an N sided polygon by only knowing the radius, but it still leaves a gap.

This is the script:

local center = script.Parent

local PART_COUNT = 24
local RADIUS = 8

local TEMPLATE = Instance.new("Part")
TEMPLATE.Anchored = true
TEMPLATE.CanCollide = false

local double_pi = 2 * math.pi
local length = (2 * (RADIUS + TEMPLATE.Size.Z / 2)) * math.sin(math.rad(180) / PART_COUNT)

for i = 1, PART_COUNT, 1 do
	local part = TEMPLATE:Clone()
	part.Size = Vector3.new(length, TEMPLATE.Size.Y, TEMPLATE.Size.Z)
	part.Parent = workspace
	
	local angle = i * (double_pi / PART_COUNT)
	local x = math.cos(angle) * RADIUS
	local z = math.sin(angle) * RADIUS
	
	local position = (center.CFrame * CFrame.new(x, 0, z)).Position
	part.CFrame = CFrame.new(position, center.Position)
end

1 Like

Really, REALLY simple fix: Make the part’s 0.01 studs thicker or even bit less

Try this formula.
You just need to know the radius (which is your radius + half the width of hte Part you use, and the angle between the parts (in this case 360/24) for t.

nwm use the one below, just tangent issue

You’re calculating the length of the parts as the distance between 2 points on a circle (green) and then placing it tangent to the circle (red), as a result the length falls short.

Change the ‘math.sin’ to ‘math.tan’ in the length calculation

local length = (2 * (RADIUS + TEMPLATE.Size.Z / 2)) * math.tan(math.pi / PART_COUNT)

Also you can just use math.pi instead of math.rad(180)

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.