Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Circle Math - Help?

Asked by 10 years ago

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

0
Updated answer with specific circly code BlueTaslem 18071 — 10y

1 answer

Log in to vote
5
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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() -- 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.
0
How would I create a circle of parts that has a hollow center using what you just said? VariadicFunction 335 — 10y
0
The center of the parts would be described by (cos(t), sin(t)) for all t being the radian form of the degrees 0 to 360. BlueTaslem 18071 — 10y
0
Would r in the equation "r * cos(t)" be the radius of the center it is rotation around? VariadicFunction 335 — 10y
0
I updated the question with my current script VariadicFunction 335 — 10y
View all comments (3 more)
0
Yes, 'r' is the radius. adark 5487 — 10y
0
I updated it as I said earlier but when I test it it doesn't rotate around where I want it to VariadicFunction 335 — 10y
0
Math: Mental abuse to humans qq Perci1 4988 — 10y
Ad

Answer this question