I want an accuracy of about 0.000001
.
typedef struct p {
long double x;
long double y;
}point;
point rotate_point(long double cx,long double cy,long double angle,point p) //pivot then angle then point to rotate
{ // cout<<"\ncx="<<cx<<"cy="<<cy<<"x="<<p.x<<"y="<<p.y;
angle=(angle/100)*pi*2;
// translate point back to origin:
p.x -= cx;
p.y -= cy;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(20);
// rotate point
long double xnew = p.x * cosl(-angle) - p.y * sinl(-angle);
long double ynew = p.x * sinl(-angle) + p.y * cosl(-angle);
// translate point back:
p.x = xnew + cx;
p.y = ynew + cy;
cout<<"x="<<p.x<<"y="<<p.y;
return p;
}
Here is the code segment which I am using I am using the function rotate_point
to rotate a point about a given pivot, here cx
, cy
are the pivots, point
is the point to rotate in clockwise direction, angle
is the angle passed in degrees (I cant pass it in radians assume that). My problem is when I call the function with values rotate_point(50,50,25, p)
where p.x=50 p.y=100
then expected output is x=100 y=50
.
I am getting x=99.99999000666841262458 y=49.96838777042233631365
, x
is ok but y
is not in desired accuracy range.
Do not use the value
if you want accuracy. Please use
which is defined in
math.h
. In MSVC you also needto make the following values available.