How does ( math. acos, atan, sin, cos, tan) work in-depth?

Hey, I’ve been on a goal to learn roblox scripting mathemically to have more variety in my possible upcoming projects.

At the moment I am stuck on math functions such as [acos, atan, sin, cos, tan, and alike], main ones being sin, cos, tan.

Questions:
1.How do they work?
2.How can I Implement it into my projects?
3. Do you have any code examples?; Or InStudio visual examples?
4. How can I find an angle between 2 parts using them?

Previous Knowledge On Topic: I understand Cos, Tan, Sin as formulas to find missing parts of a triangle, but I cant quite picture it in a 3d environment in roblox. I also have a little bit of knowledge about graphing it.

^^^
From what I seen about graphing it: its a continuous wave, How can I go about implementing that in a 3d environment apart from creating waves ?

1 Like

That’s because they are the math functions, so you’ll need to do the 3D part yourself.

I mainly use these for CFrame nonsense related to circles.

(sine and cosine in specific)

These two functions are usually paired up with radians aswell so im hoping u know what those are

1 Like

To visualize you will also need to combine trigonometry with vectors which are basically arrows in 3d space.

One example is here to find an angle and such:

1 Like

I know you’re trying to be simple, but to minimize confusion I’ll politely say that is incorrect.

Vectors are arrows that point in a direction, in however many dimensions you want. They have a direction and magnitude, which is the length.

2 Likes

Well, have a seat. The trigonometric functions themselves (sine, cosine, and tangent: sin(), cos(), tan() respectively) have their roots in Calculus. For a computer to calculate them effectively, you use what’s known as a Tayor Series. You can read more about it here: Wikipedia: Taylor Series. There’s other series that’s based on Taylor series. The special case Maclaurin series, and there’s a power series.

As for the application of trig functions, here’s a brief rundown of them from NASA.

From there, you superimpose the right triangle onto what is known as a unit circle.


The arguments to trig functions are radians. The radian is defined as the radius of a circle laid down along the circumference of said circle. As such, it take about 6.28, or more exactly, 2π radians to make a complete circle. Sine and cosine are defined on the unit circle as shown. There are also connections to e^x and complex numbers. You can read more about the trig functions here: Wikipedia: Trigonometric Functions.

Basically, this is a summary of several semesters worth of higher mathematics (higher than basic algebra) condensed into one post. If you’re really interested, Sal over at Kahn Academy has some really good videos on this.

4 Likes

A few definitions:

  • Tau: Mathematical constant equivalent to 2 * pi
  • Radian: A unit of measurement used for the circumference of a circle, it is equivalent to the radius wrapped around the circumference and is ~ 59.3 degrees. To convert from degrees to radians you multiply by pi and divide by 180. To convert radians into degrees you multiply by 180 and divide by pi. There are tau radians in the whole circumference of a circle, and therefore pi radians in half a circle.
  • Sign: “Direction” of a number i.e. positive or negative. This can be found by doing math.sign(x: number) , it will return -1 for negative, 0 for 0 and 1 for positive.
  • Cosine: This is the ratio of hypotenuse to adjacent (hypotenuse divided by adjacent) (see triangle image).
  • Sine: This is the ratio of opposite to hypotenuse (again see triangle image).
  • Tangent: This is the ratio of opposite to adjacent (again see triangle image).
  • E: Euler’s number is a mathematical constant roughly equal to 2.71828 and is used in many things such as the natural logarithm (more detail under math.log())

math.acos(x: number)
This provides the arc cosine of the number x, the inverse of the cosine.

math.asin(x: number)
This provides the arc sine of the number x, the inverse of the sine. I.e. It takes the ratio of opposite to hypotenuse and returns the angle.

math.atan(x: number)
This provides the arc tangent of the number x, the inverse of the tangent in radians. I.e. It takes the ratio of opposite to adjacent and returns the angle

math.atan2(x: number)
This provides the arc tangent of y/x, the inverse of the tangent but uses the signs to determine the quadrant in radians. Because of this, it can handle x being 0.

math.cosh(x: number)
This provides the hyperbolic cosine of x. This is a complex one so I won’t go into detail, but it is the cosine relative to a hyperbola as opposed to a circle. This is equal to:

cosh(x) = (e^x + e^(-x)) / 2

math.exp(x: number)
This gives you e^x, and as such can be used to find e by doing math.exp(1) .

math.log(x: number, base: number = e)
This gives you the logarithm of x using the base, the base defaults to e for the natural logarithm. A logarithm is a the inverse of an indices (aka exponent). This means that you can use it to find what power was used:

math.log(8, 2) -- This is 3, because 2^3 is 8

math.log10(x: number)
This provides the base-10 (decimal aka “normal” number base) logarithm of x. Therefore, the following lines are the same:

math.log(x, 10)
math.log10(x)

math.sin(x: number)
This provides the sine of x (see definitions).

math.sinh(x: number)
This provides the hyperbolic sine of x. This is a complex one so I won’t go into detail, but it is the cosine relative to a hyperbola as opposed to a circle. This is equal to:

sinh(x) = (e^x - e^(-x)) / 2

math.modf(x: number)
There is no math.mod() function so I assume this is what you mean. It returns the integral and fractional parts of x. I.e. It splits a number into a whole and a decimal. For example, 2.3 → 2, 0.3. For whole numbers it will return the number and 0 e.g. 2 → 2, 0

math.tan(x: number)
This provides the tangent of x (see definitions).

math.tanh(x: number)
This provides the hyperbolic tangent of x. This is a complex one so I won’t go into detail, but it is the cosine relative to a hyperbola as opposed to a circle. This is equal to:

tanh(x) = sinh(x) / cosh(x)
10 Likes
5 Likes

One of the most useful applications I’ve found is being able to make use of spherical coordinates like this:

In order to convert between (x,y,z) and (r, theta, phi) you need to use sin, cos and tan.

5 Likes

Thank you guys for the input,I learned some things.

This is actually a topic in Calculus 3 with Analytical Geometry. The actual formulas to convert are here: Conversion between 3D Coordinate Systems. That website has the formulas to convert between Cylindrical, Cartesian, and Spherical coordinate systems. Now don’t get me started on triple integrals on a closed path :grin:.

2 Likes