This is a pretty big topic. But, the motivation and idea are pretty easy to explain.
Coordinates (Points in Space)
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.
Trigonometry
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.
Your Specific Code
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()
local circle = radius * Vector3.new( math.cos(rotation), 0, math.sin(rotation) )
obj.CFrame = CFrame.new(pos + circle, pos + circle * 2)
obj.CFrame = CFrame.new(pos + circle) * CFrame.Angles(0, rotation, 0)
1 comment
Updated answer with specific circly code