I can understand most geometric and algebraic concepts that I have studied so far but even when I was just learning about Pi I have had a very big problem understanding it. I cannot seem to wrap my head around how to use Math.PI for creating circles. I am wondering how to create circles with a displacement (not sure if that's the correct term but I basically mean that the circle has a hollow center that it rotates around) either using GUIs or parts. I would like to further understand how to use Math.PI, sin, cos, tan, etc so that I can become better.
My current program for creating the next block is currently:
local center = script.Parent:WaitForChild("Center") local obj = script.Parent.Part local rotation = math.rad(70) local radius = center.Size.X obj = obj:Clone() obj.Parent = script.Parent obj.CFrame = obj.CFrame * CFrame.Angles(0, rotation, 0) * CFrame.new(radius * math.cos(rotation), 0, radius * math.sin(rotation))
I'm sure this is incorrect in many ways but I need help to fix it
This is a pretty big topic. But, the motivation and idea are pretty easy to explain.
When you are writing positions, we use (x,y)
format because it's really easy to compute with:
Go up? Add to y
.
Go right? Add to x
.
What's hard is when you ask "which way is 39 degrees"? There isn't some nice way to describe that in our system.
Let's fix 0 degrees to be going right (+x), 90 degrees to be going up (+y), 180 degrees to be going left (-x) and 270 degrees to be going down (-y).
Getting around to 360, we're back where we started, going right (+x).
In between, say, at 45 degrees, there's some +x and some +y (but not as much at 0 or 90 degrees).
How much in between is given by sin and cosine.
Sine looks like this (given by radians). It waves up and down between -1 and 1.
Cosine looks like the same thing, but shifted over so that wherever sine is 0, cosine is -1 or 1 (and vice versa).
Radians are an alternative way to measure angle. Basically, instead of 360 degrees in a circle, you have 2*pi
radians. If you don't want to think with radians (they make calculus really nice when you get there) you can use the Lua functions math.deg(radiansAmount)
and math.rad(degreesAmount)
to convert between.
math.cos
and math.sin
use radians not degrees.
One way to view the use of trigonometry is polar coordinates. It says that
(x,y) = ( r * cos(t) , r * sin(t) )
Where t
is the angle (usually written with the Greek theta) and r
is the radius, length, or magnitude.
Please let me know what parts of this need expanding or improvement by dropping a comment.
We want to go to the position cos(t), sin(t)
and be rotated by t
.
That position would be denoted by radius * Vector3.new(math.cos(rotation), 0, math.sin(rotation))
To rotate it by the right amount, we could multiply that position (as a CFrame) by CFrame.Angles(0, rotation, 0)
or we could use the 2 Vector3 CFrame.new
constructor.
local pos = Vector3.new() -- Center of circle local circle = radius * Vector3.new( math.cos(rotation), 0, math.sin(rotation) ) -- Option 1 obj.CFrame = CFrame.new(pos + circle, pos + circle * 2) -- Option 2 obj.CFrame = CFrame.new(pos + circle) * CFrame.Angles(0, rotation, 0) -- These may be 90 degrees off from on another, I'm not sure.