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

How do you apply math functions effectively in scripting - knowingly?

Asked by 10 years ago

How do you apply math functions effectively in scripting - knowingly?

(How do you learn when to use math functions in rbx.lua and when to use them and how they work.

0
What you're doing here is asking for a math lesson. To be fair, I too wish to know *how* trig functions work, but that's a level of calculus still above my head. If you want explanations of how to use the math library's functions, pay attention in math class. If you want to learn now, google "trig lessons". Khan Academy has a very nice course on it. adark 5487 — 10y

2 answers

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

Computer programming is coming up with a computer program to solve a problem..

That means, when you set down to write a program, you have two things in mind:

  • A problem to solve
  • An idea of how to solve it

You have a bunch of "tools" to build your way towards a complete solution, and different mathematical properties, structures, and functions are a piece of that.

You have to learn when it's appropriate to use each one.


I tend to think of solving math problems as many, many islands. Many of them are bridged by simple operations / methods, (e.g., "I have x, I need to get y so that y * y = x". The "islands" would be "x" and "y", and the "bridge" is the square root).

In general, writing a program is describing which bridges to take so that if you're in a place that looks a certain way, you know how to get to a (related) place that looks a different way.


Lua has a very small standard library. If you want to look at all of the math functions that Lua supports, you can look up the math library.

It contains trigonometry (cos, sin, tan, and their inverses acos asin, atan, atan2), angle conversion (deg and rad), exponentiation (log, log10, exp), constants (pi), and powers (sqrt, pow).

ROBLOX provides more math structures in the form of vectors and CFrames (CFrames correspond to matrices).

ROBLOX's vectors support linear interpolation (lerp) the cross and dot products (cross and dot), magnitude/norm/length (magnitude), normalization (unit), and others.

0
Is there any sources for Cos sin and tan mostly that easily explain the possiblities of Use for them besides wikipedia, because wikipedia tends to make everything very equation upcessed. Blockeus 68 — 10y
Ad
Log in to vote
0
Answered by
Jonibus 30
10 years ago

Elaborate on math functions. Do you mean how would you do math operations? Because there is a function dump of math functions for RBX.Lua that do some more complex operations in math, which can be found here: http://wiki.roblox.com/index.php?title=Function_dump/Mathematical_functions

If you mean how do you do actual math, you'd want to know the operators.

  • is addition
  • is subtration
  • is multiplication / is division ^ is exponent/to the power of % is modulus

You can write out equations the same as you normally would, and Lua follows the order of operations. For example...

print(2 * 5 + 8 - (3 * 2)^2) -- note this was not calculated and is probably an insane number

If you meant something else, let me know.

0
I believe he meant these math functions: http://wiki.roblox.com/index.php?title=Function_dump/Mathematical_functions Redbullusa 1580 — 10y

Answer this question