c - Radius of an Ellipse at a given angle with given length and width -
i writing function in c returns radius of ellipse @ given angle given length , width; writing calculation in c:
unfortunately platform not support math.h
there sin
, cos
functions built in can use.
how write calculation in c , store in int
?
i have tried:
int theta = 90; int = 164; int b = 144; float aa = (((a^2) * ((sin_lookup(deg_to_trigangle(theta)))^2)) + ((b^2) * ((cos_lookup(deg_to_trigangle(theta)))^2))) / (trig_max_angle^2); float result = (a * b) / (my_sqrt(aa)); int value = (int)result;
easy enough
int getradius(double a, double b, double theta) { double s = sin(theta), c = cos(theta); return (a * b) / sqrt((a*a)*(s*s)+(b*b)*(c*c)) }
though i'm not sure why want return int
. you'll loose lot of precision.
the ^
operator not way powers. it's bitwise xor. common mistake new (c) programmers make. math.h
has function pow()
calculating powers, said can't use math.h
. these values raised second power, it's pretty easy multiply manually.
Comments
Post a Comment