I am making a library for math functions, intended to test and challenge my programming and math skills. A necessary part of this is trig: Sine, Cosine, Tangent, and derivatives/inverses, using degrees or radians.
I have spent hours searching the web for implementation of Taylor Series or CORDIC algorithm using degrees AND/OR radians, to no avail.
def sin(x):
if numerics.degrad == 'deg':
#compute sin(x) using degrees or radians, make sure to return the result in degrees
Please be informed, numerics.degrad is a string value to be referenced from any function in the library or terminal. Usual values are 'deg' or 'rad'. Also, I am trying to avoid importing libraries like numpy or math.
UPDATE: I tried today(11-12-19) to emulate sine by generating a parabola which intersected one waveform. The hope was to check which waveform the angle would land on, then use the according quadratic equation. That did not work. Results in DESMOS were off by up to 0.2 units, and my python implementation was just plain wrong.
# desmos implementation, where y is the output and x is the angle:
# y=0.0001234567901234(x-90)^2+1
# lays closely over a sine wave graphed with y=sin(x).
# here is my python implementation:
def sin(anglein): #return the result of sine of the supplied angle, using the mode
if degrad == 'deg':
const = 0.0001234567901234
angle = anglein
while angle > 360: #should return the corresponding angle within 0-360 degrees
angle -= 360
return((const * ((angle - 90) * (angle - 90))) + 1)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…