Pythagorean Theorem

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search

This code will find the hypotenuse of a triangle given two sides.

This is a Stage Function, and as such must be created as a Quest Stage of a global script and called as a function. This assumes a Quest called Wiki with the variables declared. Therefore, you must modify this code to include the name of your Quest (assuming it is not Wiki, which it shouldn't be). Alternatively, however, it would not be difficult to incorporate this code into your script directly.

It involves Square Root, which means either also defining that Stage Function as well, or incorporating that code into this function. For the sake of simplicity, the function will be used here, as stage 10 of our Wiki quest. For your own use, substitute your own quest for "Wiki" and whichever stage number for the 10.

The list of variables you will need declared in your Global Script:

float inputA ;(one side of the triangle)
float inputB ;(the other side)
float input ;(from Square Root code)
float SqRt ;(output from Square Root)
float Hyp ;(the hypotenuse, your answer)

You are free to rename them, but remember to change the function code (and the Square Root code!).

;originally by JustTim
set Wiki.input to ( ( Wiki.inputA * Wiki.inputA ) + ( Wiki.inputB * Wiki.inputB ) )
SetStage Wiki 10
set Wiki.Hyp to Wiki.SqRt