[英]What might cause the same SSE code to run a few times slower in the same function?
[英]What might cause to get exactly the same output of trigonometric functions in different angles
嘗試使用circle()
手動繪制一條線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
您在代碼部分中輸入了角度並由此計算angle*pi/180
時會遇到一些錯誤。 對於60度, angle*pi/180
實際上為1.0472。 對於示例輸出中的其他角度-70、80、90,您顯然不會再進行計算,並且仍為1.0472。 我不知道為什么-您粘貼的示例代碼顯然不是打印顯示的調試輸出的代碼(例如,粘貼的代碼中沒有任何內容打印“輸入角度”或進行設置)。
找出負責緩沖區更新的線程在需要更新輸入之后立即使用mutex.lock()
鎖定緩沖區,該緩沖區將在最近繪制。 當狀態鎖定時,我強制其繪制(這意味着它應該更新角度)。 由於它無法更新角度,解決方案是僅在緩沖區同時解鎖和修改后才繪制。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.