尝试使用circle()
(在其周围绘制一个实心圆圈)手动绘制一条线,稍微更新其中心变量,该变量是我图像上的坐标。通过将 sin(a) 和 cos(a) 添加到平面的 X 和 Y 来进行更新,其中“a”是角度。这边走:
// This is a multi threaded application.
// part of another function where i update the 'angle'variable
// ............
if (buffer.modified()) // If buffer is modified
{
for (int k = 0; k < PB; k++)
{
if (buffer.data[k]>0)
{
size=buffer.data[k];
angle = k;
break;
}
}
buffer.unmodify(); // Disable flag
draw_line( size, angle);
}
// ............
// ............
//The draw_line() function in an infinite loop
// ............
// circle() function goes here
// ............
//update coordinates
x_coord += sin(angle*pi/180);
y_coord += cos(angle*pi/180);
//update circle()'s center Point
image.start.x = x_coord;
image.start.y = y_coord;
//show the results
cout<<"
cos("<<angle*pi/180<<")="<<cos(angle*pi/180)<<"
sin("<<angle*pi/180<<")="<<sin(angle*pi/180)<<endl;
// ............
// ............
圆圈和更新函数循环在一起。这是一个名为:
circle(bckg, image.start, 1, Scalar( color[0],color[1],color[2] ), FILLED,LINE_8 );
预计代码在 sin(60) 和 sin(70) 上具有不同的值,但该行与调试输出保持相同。一探究竟:
//THE OUTPUT
input angle: 30
cos(0.523599)=0.866025 sin(0.523599)=0.5
input angle: 60
cos(1.0472)=0.5 sin(1.0472)=0.866025
input angle: 70
cos(1.0472)=0.5 sin(1.0472)=0.866025
input angle: 80
cos(1.0472)=0.5 sin(1.0472)=0.866025
input angle: 90
cos(1.0472)=0.5 sin(1.0472)=0.866025