Parametric equations: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Mindraker
No edit summary
>Mindraker
No edit summary
(No difference)

Revision as of 01:07, 4 January 2009

Introduction

This tutorial will cover the basic notion of parametric equations, and how they apply to ROBLOX. Be careful with some of these scripts, they may lag your computer or cause it to freeze for a few moments or minutes.

Mathematical Functions and graphs

In algebra, you may be familiar with how a function is described with y on one side of the equals sign, and x on the other. For example:

y = x
y = x^2
y = x + 3

and so on.

There are other ways of describing functions, that do the exact same thing. For example, with the equation

y=x^2

we can also describe both y and x in terms of a third variable:

x=t
y=t^2

This does the exact same thing as y=x^2

Similarly, this works for more complex equations such as 2-D circles, spheres, etc:

The more familiar "x^2+y^2=r" equation for a circle now becomes:

x=a*cos(t)
y=a*sin(t)

How does this help me?

In ROBLOX, while you are scripting, you need to define the x, y, and z coordinates for the bricks you are graphing. With parametric equations, you are given a formula for each x, y, and z coordinate. All you have to do now is just input these formulae in a way that ROBLOX understands, and you can make some very fancy things.

What can I make with this?

Take a look at the article on Butterfly curves on MathWorld. You can make that fancy butterfly with a very short script, because they have given you all the formulae you need.

A butterfly using parametric equations
for i = 1,100, .1 do

x=math.sin(i)*(math.exp(1)^math.cos(i)-2*math.cos(4*i)-(math.sin(i/12))^5) 
--[[ this is the same formula on MathWorld  --]]
y=math.cos(i)*(math.exp(1)^math.cos(i)-2*math.cos(4*i)-(math.sin(i/12))^5) 
--[[ this is the same formula on MathWorld  --]]

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(100*x, 100*y, 100))
p.Size = Vector3.new(8,8,8)
p.Anchored = true
p.BottomSurface = "Smooth"
p.TopSurface = "Smooth"
p.Parent = game.Workspace
p.BrickColor = BrickColor.new(26) -- change this to whatever color you want

end

Notice that in the above example, x and y are defined using the i variable.

Deltoid curve

Other curves and shapes which would have been difficult to plot before become very simple. For example, the Deltoid curve:

Deltoid curve
for i = 1,100, .1 do

a=.5

x=2*a*math.cos(i)+a*math.cos(2*i)
y=2*a*math.sin(i)-a*math.sin(2*i)

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(100*x, 100*y, 100))
p.Size = Vector3.new(8,8,8)
p.Anchored = true
p.BottomSurface = "Smooth"
p.TopSurface = "Smooth"
p.Parent = game.Workspace
p.BrickColor = BrickColor.new(26)

end

As you can see here, too, the Parametric equations for x and y have been changed very little. I have chosen the value for z to be 100 because it is a constant -- in other words, it doesn't change. You can change the value of a to make the entire deltoid larger or smaller -- i.e., a value of .5 makes the deltoid smaller, a value of 2 makes it larger.

Epicycloids

There is an entire group of curves that can be made as "Epicycloids". The image shown below uses the value of k=7.2. Here, as well, the parametric equations can be plugged directly into Roblox:

Epicycloid k = 7.2 = 36/5
for i = 0,100, 1 do

k=1 -- change the value of k to the appropriate value

x=(k+1)*math.cos(i)-math.cos((k+1)*i)
y=(k+1)*math.sin(i)-math.sin((k+1)*i)

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(100*x, 100*y, 100))
p.Size = Vector3.new(8,8,8)
p.Anchored = true
p.BottomSurface = "Smooth"
p.TopSurface = "Smooth"
p.Parent = game.Workspace
p.BrickColor = BrickColor.new(26)

end

Hypocycloids

Hypocycloid k = 3.8

Similarly, there is a class of curves known as Hypocycloids

The above image is with the value of k=3.8. Wikipedia has several values and images on display with which to experiment.

for i = 0,100, .1 do

k=3.8

x=(k-1)*math.cos(i)+math.cos((k-1)*i)
y=(k-1)*math.sin(i)-math.sin((k-1)*i)

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(100*x, 100*y, 100))
p.Size = Vector3.new(8,8,8)
p.Anchored = true
p.BottomSurface = "Smooth"
p.TopSurface = "Smooth"
p.Parent = game.Workspace
p.BrickColor = BrickColor.new(26)

end

Hypotrochoids

Hypotrochoid, parameters are R = 5.0, r = 3, d = 5

Hypotrochoids are another example of curves that can be scripted with parametric equations. Here, the x and y formula are just as from wikipedia... and all you need to set are the values for R, r, and d (in this example the values have been provided by wikipedia!)

for i = 0,360, 1 do

R=5.0
r=3
d=5

x=((R-r)*math.cos(i))+d*math.cos(((R-r)/r)*i)
y=((R-r)*math.sin(i))-d*math.sin(((R-r)/r)*i)

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(100*x, 100*y, 100))
p.Size = Vector3.new(8,8,8)
p.Anchored = true
p.BottomSurface = "Smooth"
p.TopSurface = "Smooth"
p.Parent = game.Workspace
p.BrickColor = BrickColor.new(26)

end

Limaçon trisectrix

File:Limaçon trisectrix.PNG

The Limaçon trisectrix is a special instance of the trisectrix of Pascal (also called the limaçon of Pascal). Here, again, once you get the basic formula down, you can have a wide variety of curves with different values inserted into a and b.

for i = 0,360, 1 do

a=4
b=2

x=(a/2)+b*math.cos(i)+(a/2)*math.cos(2*i)
y=b*math.sin(i)+(a/2)*math.sin(2*i)


p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(100*x, 100*y, 100))
p.Size = Vector3.new(8,8,8)
p.Anchored = true
p.BottomSurface = "Smooth"
p.TopSurface = "Smooth"
p.Parent = game.Workspace
p.BrickColor = BrickColor.new(26)

end

Lissajous curve

a = 9, b = 8 (9:8)

"A Lissajous curve is the graph of the system of parametric equations

x=A*sin(at+δ), y=B*sin(bt) which describes complex harmonic motion."

for i = 1,1500, .5 do

A=1
B=1
a=9
b=8
phi=2

x=A*math.sin(a*i+phi)
z=B*math.sin(b*i)

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(1000*x, 100, 1000*z))
p.Size = Vector3.new(8,8,8)
p.Anchored = true
p.BottomSurface = "Smooth"
p.TopSurface = "Smooth"
p.Parent = game.Workspace
p.BrickColor = BrickColor.new(217)

end

3D Curves

Viviani's curve

File:Vivianiscurve.PNG
Viviani's curve
for t = 0,4*math.pi, .1 do

a=2
b=1

x=a*(1+math.cos(t))
y=math.sin(t)
z=2*math.sin(t/2) 

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(10*x, 10*y, 10*z))
p.Size = Vector3.new(1,1,1)
p.Anchored = true
p.BottomSurface = "Smooth"
p.TopSurface = "Smooth"
p.Parent = game.Workspace
p.BrickColor = BrickColor.new(26)

end

Clélies Curves

Clélies Curves and their values
a=4, m=4/5
for t = 0,4*math.pi, .05 do

a=4 -- radius
m=4/5

x = a * math.sin(m*t)*math.cos(t)
y = a * math.sin(m*t)*math.sin(t)
z = a * math.cos(m*t)

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(10*x, 10*y, 10*z))
p.Size = Vector3.new(1,1,1)
p.Anchored = true
p.BottomSurface = "Smooth"
p.TopSurface = "Smooth"
p.Parent = game.Workspace
p.BrickColor = BrickColor.new(26)

end

Tornado

Ever wanted to know how to make a tornado like the tornado hat?

tornado
for i = 1,15, .1 do

x=i*math.cos(i)
y=i
z=i*math.sin(i)

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(10*x, 10*y, 10*z))
p.Size = Vector3.new(8,8,8)
p.Anchored = true
p.BottomSurface = "Smooth"
p.TopSurface = "Smooth"
p.Parent = game.Workspace
p.BrickColor = BrickColor.new(26) -- change this to whatever color you want

end
File:Parcur10.PNG
for t = 1,20, .01 do

x=2*math.sin(3*t)*math.cos(t)
y=2*math.sin(3*t)*math.sin(t)
z=math.sin(3*t)

p = Instance.new("Part")
p.CFrame = CFrame.new(Vector3.new(10*x, 10*y, 10*z))
p.Size = Vector3.new(1,1,1)
p.Anchored = true
p.BottomSurface = "Smooth"
p.TopSurface = "Smooth"
p.Parent = game.Workspace
p.BrickColor = BrickColor.new(26) -- change this to whatever color you want

end

See Also

MathWorld, Butterfly curves

MathWorld, Parametric Equations

Wikipedia, Parametric Equations

Wikipedia, Epicycloids

Hypocycloids

Lissajous curve

Viviani's curve

Clélies curve

Parametric Curves in 3D