Square From Cosine & Sine

Hello, I am having trouble making a square from cosine and sine functions.

My thought process is basically you can set the X-Axis and Z-Axis with Cos and Sin then use some sqrt function for the corner growths. If anyone has any experience with this I would appreciate the help, a lot. Thank you!!

Visual e.x.
image

2 Likes

Can’t offer much help but I know for certain cosine and sine are used for making circles

Edit: Maybe by using rounding to a grid this may be achievable.

1 Like

You cannot get the shape you want from a unit circle (cos, sin). I would recommend two for loops, with an if statement to skip filling in where y > 0 and y < maximum_y


local maximum_size = 10
for y = 0, maximum_size, 1 do
	if y > 0 and y <= maximum_size then
		-- place entire row
		for x = 0, maximum_size, 1 do
			place_block(x, y)
		end
	else
		-- only place left/right
		place_block(0, y)
		place_block(maximum_size, y)
	end
end
2 Likes

Hey, I actually made a script that does what you want, but you can’t use cosine and sine because the hypotenuse lengths (the distance from the center cube to outside cube) is different for every thing. Here’s one that works if you put the script inside a part:

local xSize = 50
local ySize = 20
local yCubes = 10
local xCubes = 10
local part = script.Parent

for y = 0, yCubes - 1, 1 do
	if y == 0 or y == yCubes - 1 then
		for x = 0, xCubes - 1, 1 do
			local clone = part:Clone()
			clone.Script:Destroy()
			clone.BrickColor = BrickColor.random()
			
			clone.Position = Vector3.new(part.Position.X - xSize/2 + x*(xSize/(xCubes - 1)), part.Position.Y, part.Position.Z - ySize/2 + y * (ySize/(yCubes - 1)))
			
			clone.Name = "XCube"
			clone.Parent = workspace
		end
	else
		local clone = part:Clone()
		clone.Script:Destroy()
		clone.BrickColor = BrickColor.random()
		
		clone.Name = "YCube"
		clone.Position = Vector3.new(part.Position.X - xSize/2, part.Position.Y, part.Position.Z - ySize/2 + y * (ySize/(yCubes - 1)))
		
		local clone2 = part:Clone()
		clone2.Script:Destroy()
		clone2.BrickColor = BrickColor.random()
		
		clone2.Name = "YCube"
		clone2.Position = Vector3.new(part.Position.X + xSize/2, part.Position.Y, part.Position.Z - ySize/2 + y * (ySize/(yCubes - 1)))
		
		clone.Parent = workspace
		clone2.Parent = workspace
	end
end
3 Likes

This answer is a bit late, but the current answers don’t really satisfy me. Contrary to what others stated, it is perfectly possible to use cosine and sine functions to plot a square. All you have to do if clamp the results of the cosine and sine functions. Like so:

-- Since the functions are clamped by half their max value (1), you have to multiply
-- by 2 to receive a "proper" solution.
local x = math.clamp(math.cos(angle), -0.5, 0.5)*2
local y = math.clamp(math.sin(angle), -0.5, 0.5)*2

To add to this, if you plot the Y-axis of a circle and compare that to the Y-axis of a square, you’ll see that the square is just a clamped version of the circle.

Circular graph
graph1

Rectangular graph
graph2

5 Likes

I thought you could, I would’ve never guessed the clamping solution though :laughing:

Thanks again, I really appreciate it!!

2 Likes

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