Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "zcommon.acs"
- function int q_acos(int x, int y, int p)
- {
- int baseangle = (3.141592653/2);
- int r = sqrt( pow(x, 2) + pow(y, 2) );
- int neg = 0;
- int big = 0;
- //Check if angle is over 180
- if (y < 0)
- {
- neg = 1;
- }
- //check if angle is over 90
- if (cos(baseangle) > (x/r))
- {
- big = 1;
- x = -x;
- }
- for (int i = 1; i <= p; i++)
- {
- if (cos(baseangle) > (FixedDiv(x,r)))
- {
- baseangle += (baseangle/(1+i));
- }else if (cos(baseangle) < (FixedDiv(x,r))){
- baseangle -= (baseangle/(1+i));
- }else{
- i = p;
- }
- }
- //if angle was over 90, fix
- if (big == 1)
- {
- baseangle = 3.141592653 - baseangle;
- }
- //if angle was over 180, fix
- if (neg == 0)
- {
- return baseangle;
- }else{
- return 3.141592653 + (3.141592653 - baseangle);
- }
- }
- function int pow(int x, int y)
- {
- int n = 1.0;
- while (y-- > 0) { n = FixedMul(n, x); }
- return n;
- }
Advertisement
Add Comment
Please, Sign In to add comment