Need Math Formula for Future Project

It wasn’t going to be used now, but will be used for future projects.

Length is pointing the black line
5 degrees in radians pointing out the green line

Anyone know how to find the length of the brown line? It would be really useful if you have the formula for it. Thanks

“5 degrees in radians”

What? Did you mean “5 radian”? That can’t be 5 radian. A triangle can’t be more than pi radian.

1 Like

math.rad(5) or am i wrong?

Then you mean 5 degrees, don’t put radian into it.

You want tangent.

tan(angle) = opposite/adjacent
tan(5) = opposite/100
opposite = 100 * tan(5)

In Lua this translates to…

local opposite = length * math.tan(math.rad(angle))
5 Likes

thanks ill try it out soon

And for the future, learning the basic of sin cos and tan are always useful:

1 Like

That’s just finding 5 degrees in radians.

Personal recommendation: don’t work in radians unless you’re totally comfortable with them. Roblox is just being difficult when they require them.

What you need to learn for this is trigonometrical ratios.

Here is a triangle. Hypotenuse is the big long part (it’s always the longest side), opposite is the one to the side, and adjacent is the one that, if you drew a line from the normal of the hypotenuse (middle) you’d touch it. Don’t worry too much about this for now.

This applies to any right-angled triangle (has one 90 degree angle in it). You can tell it’s a right angled triangle as it has a square in one of the corner.

Now, the you may be aware of functions on your calculator called sin, cos, and tan. Look funky, right? Well, they’re your new friends for anything angle. They dictate the ratios between triangles in a circle radius (you’ll probably learn about this more in school later on), and you can use them to find the angles.

So. There are three main rules for right angled triangles, and based on what values you know or want to find you have to decide which one to use. This is SOHCAHTOA.
So, SOHCAHTOA is an acronym for the ratios, which are:

Sin(angle) = opposite / hypotenuse
Cos(angle) = adjacent / hypotenuse
Tan(angle) = opposite / adjacent

Example: if you want to find the hypotenuse, and you know the angle and the opposite, you eliminate the ones you can use:

Tan(angle) = opposite / adjacent
This equation doesn’t have any mention of hypotenuse, so you shouldn’t try calculating the hypotenuse from it (obviously)

Cos(angle) = adjacent / hypotenuse
This equation does have hypotenuse, but you don’t know the adjacent! You can’t use this one either.

Sin(angle) = opposite / hypotenuse
Hey! You know angle and opposite, and want to find hypotenuse! This is the one.

So, to use this, let’s pretend the angle is 45 degrees, and the opposite is 12 cm

Sin(45) = 12 / hypotenuse

So, rearranged, we can find hypotenuse

Hypotenuse = 12 / Sin(45)
So, we’ve just found the hypotenuse! Score :smiley:

Now, in your case, you want to find the opposite, when you know the hypotenuse and opposite, and angle! You’re being spoilt. You can do:

Sin(angle) = opposite / hypotenuse
OR
Tan(angle) = opposite / adjacent

Let’s rearrange again.

Sin(5) = opposite / 50
(Let hypotenuse be 50)
So, hence
Opposite = 50 x Sin(5)

Let’s turn this into Lua now!

local hyp = 50
local angle = 5

local opp = hyp * math.sin(math.rad(angle)) // radians because Roblox is difficult
print(“found it! Answer is ” .. tostring(opp))

Hope this helps :slight_smile:

1 Like

Radians are love, radians are life.
Seriously, radians are awesome for a lot of more complex geometry and physics

5 Likes

Agreed. They’re lovely for people like us, but by 75% of programmers on Roblox, they’re hardly (if ever) used.
Roblox should take degrees for default on functions, and then give the option to use radians.

But why? Ignoring that changing the behaviour will break almost every game, radians just make more sense. Degrees are 360 completely arbitrarily, whereas radians have a clearly defined system to them. Usually you won’t even have to think about degrees or radians.

1 Like

No, this is a bad idea.

1 Like

…For us, maybe. I’m happy to work in radians. I’m just saying that when I was a 13 year old developer learning to code (like most new coders) I had no working knowledge of radians. It isn’t fitting with Roblox’s brand of being easy to learn and easy for younger kids to program in.

I didn’t know about radians before Roblox. Here was my thought process:

  1. Tried to use math.sin or something similar with degrees.

  2. Got an incorrect result. Got confused.

  3. Tested math.sin with values like 90, got completely “wrong” answers.

  4. Looked up math.sin, saw it used radian. Also saw math.rad. Used that. Worked!

  5. Later looked up radian, found it made a lot more sense, removed all my math.rad.

This is how it should be. Radian make more sense as an end result. It serves as a good opportunity to teach people. It’s not worth changing.

6 Likes