Talk:Sin - Math

From the Fallout4 CreationKit Wiki
Jump to navigation Jump to search

All the first three basic trigonometric functions calculate their results by first getting the radial distance, this is because the hypotenuse and the opposite can only be found with papyrus through this method. For the sake of providing an example, I'll use the sine function. This is mainly for people that only knows basic trig and obviously not for those who know advanced geometry/trig/calc. Remember SOHCAHTOA? SOH means sine(opposite / hypotenuse). So what is the radial distance? This is a component of the polar coordinate system and you don't need to worry about that system for this, just that you need to use part of it to get the radial distance. For the sake of simplicity is it basically the hypotenuse and the goal is to find that first so you can then find the opposite.

Alright, let's begin. Say the player's X is 2048 and the Y is 407 and the Z angle is 87°, decimals were removed to keep things clean.

; 0.998629: We'll need this value to check the accuracy of our math.

Float hypotenuse = Math.sqrt(Math.Pow(2048, 2)+ Math.Pow(407, 2)) ; 2088 - yes that uses a part of the Pythagorean theorem.
Float opposite = Math.sin(87.0) * hypotenuse                      ; 2085
Float fakeSine = opposite / hypotenuse
"My fake sine function:" 0.998563                                 ; Slightly off because many decimals were removed, but it checks out.

There, you know how how to reverse engineer the Math.Sin function. You also know what's happening when people use the player's Z rotation for things like moveTo. What's happening is that the player's Z angle help forms an 'invisible' triangle. --Lisselli (talk) 2021-04-03T08:42:39 (EDT)