I've been trying to get the final y coordinate, so I've accepted the initial y coordinate at 1 second time and found the inverse of it's cosine . I've then multiplies the angle with time and then converted to the y coordinate by using the required trigo function but the issue is in case of -2 coordinate my code gives -1.99.... which is not accurate.
Also require help in the part of converting a huge decimal value to two integral integer values as numerator and denominator, since multiplying by a power of 10 doesn't give accurate results and might need multiplication with a prime number.
Asked by: Liman_Rahman on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.
mathematically your approach is correct but since there is always a loss of precision when working with floating-point numbers(while doing any arithemetic/trigonometric operation) this apporach will never give accurate results.
Instead what you could do is create a structure which will allow you to operate on fractions. This was you can operate on p and q seperatly and it will never result in loss of precision.
struct fraction
{
int num; //numerator
int den; //denominator
};
fraction subtraction(fraction fract1,fraction fract2) //for subtraction of two fractions
{
fraction result;
result.num = (fract1.num * fract2.den) - (fract2.num* fract1.den);
result.den = (fract1.den * fract2.den);
return result;
}
fraction multiplication(fraction fract1,fraction fract2) //for multiplying two fractions
{
fraction result;
result.num = (fract1.num * fract2.num);
result.den = (fract1.den * fract2.den);
return result;
}
//likewise for other arithmetical operations
aslo you can't directly use trigonometric function to find cos (t*theta) as it will also not give precise results.
so you have to use divide and conquer + subtract and conquer strategy with memonization to get 100 pts.
we already have the value of cos(theta),
now if t is power of 2 then we can easily get value of cos(t*theta) using the identity cos (2*theta)=2*cos^2(theta) -1 in divide and conquer.
If t is not power of two then we can break t in two terms A and B ,where A is power of 2 and can use the identity : cos (A+B)=2cosA*cosB-cos(A-B)