# -*- coding: utf-8 -*-
"""
Created on Fri Jan 27 06:24:59 2023

@author: 2017
"""

###   Implementering av sinus funksjonen

import numpy as np
x= 10
#4*(np.pi)/3 +0*np.pi

print(np.sin (x))

s=0.0    #variabelen som skal faa sinusverdien
omloep = 2*np.pi
x= x % omloep    #reduserer til foerste omloep fra 0 til 2pi.
def sinus(x):   
    s= x -x**3/6 +x**5/120 -x**7/5040 + x**9/362880 -x**11/39916800 + x**13 /6227020800 -x**15 / 1307674368000
    return(s) 

def cosinus(x):   
    s= 1 -x**2/2 +x**4/24 - x**6/720 + x**8/40320 - x**10 / 3628800 + x**12 /479001600 - x**14/ 87178291200
    return(s) 


oevrehalvdel =  x <= np.pi

print('oevrehalvdel ' ,oevrehalvdel)

if oevrehalvdel == False :
    x = 2*np.pi - x    #Reflekterer om x-aksen

foerstekvadrant = x <= np.pi/2

if foerstekvadrant == False :    #Reflekterer om y-aksen
    x= np.pi - x 
    
print('foerstekvadrant ' ,foerstekvadrant)
    
#print(x)

under45 = x <= np.pi / 4 

print('under45 ', under45)

if under45 == True:
  s =  sinus (x)
else:
      s= cosinus (np.pi/2 -x)
   
if  oevrehalvdel == False:
    s = -s
    
print(s)      



