我有繪製餅圖的中心點,半徑和角度,但the Pie function需要4點作爲輸入數據。有沒有人有任何轉換功能或更好的解釋呢?如何調用Pie函數?
2
A
回答
2
的四點餅功能:
- 上邊框的左上角。
- 邊界矩形的右下角。
- 指向標記餅圖開始的圓上的點。
- 指向標記餡餅末端的圓圈(逆時針)。
轉換:
中心點:CX,賽揚 半徑,R 角度:一個
假設你的餡餅從高層開始。
- X1 = CX-R,Y1 = CX + R
- X2 = CX + R,Y2 =賽揚-R
- X3 = CX,Y3 = Y1
- X4 = CX + R罪(a),Y4 = Cy + rcos(a)
你可能不得不在某個地方翻轉一個標誌,但是這應該是有用的。
用兩個不同角度的(a和b):
- X3 = CX + R SIN(a)中,Y3 =賽揚+ R cos(A)
- X4 = Cx + r sin(b),Y4 = Cy + r cos(b)
0
這是用(舊)C++編寫的,但大多數應該很容易地轉換爲Delphi(或幾乎任何其他)。它還假定輸入是以百分比(整圓爲100%)而不是原始角度,但(再次)應該很容易處理。它以弧度轉換百分比到角度,所以從其他單位轉換應該是一個很小的調整。
class section {
double percent;
int color;
public:
section(double percent_, int color_) :
percent(percent_), color(color_) {}
void draw(HDC destination, POINT const ¢er, int diameter, double &start_angle);
};
void section::draw(HDC destination, POINT const ¢er, int radius, double &start_angle) {
double start_x, start_y, end_x, end_y;
double angle, end_angle;
int top = center.y - radius;
int bottom = center.y + radius;
int left = center.x - radius;
int right = center.x + radius;
// now we have to convert a percentage to an angle in radians.
// there are 100 percent in a circle, and 2*PI radians in a
// circle, so we figure this percentage of 2*PI radians.
angle = percent/100.0 * 2.0 * 3.1416;
end_angle = start_angle + angle;
// Now we have to convert these angles into rectangular
// coordinates in the window, which depend on where we're
// putting the chart, and how big we're making it.
start_x = center.x + radius * cos(start_angle);
start_y = center.y + radius * sin(start_angle);
end_x = center.x + radius * cos(end_angle);
end_y = center.y + radius * sin(end_angle);
// Now we need to actually draw the pie section by selecting
// the correct color into the DC, drawing the section, then
// selecting the original brush back, and deleing our brush.
HBRUSH brush = CreateSolidBrush(color);
HBRUSH old_brush = (HBRUSH)SelectObject(destination, brush);
Pie(destination, left, top, right, bottom,
(int)start_x, (int)start_y, (int)end_x, (int)end_y);
SelectObject(destination, old_brush);
DeleteObject(brush);
// our sole awareness of other sections: the next section will
// start wherever we finished.
start_angle = end_angle;
}
相關問題
- 1. 如何調用函數中的函數?
- 2. 如何調用函數中的函數
- 3. 如何在函數內調用函數?
- 4. 如何在函數中調用函數?
- 5. 如何調用函數內部函數?
- 6. jQuery flot pie調整大小
- 7. 如何調用JS函數
- 8. 如何調用javascript函數
- 9. 如何調用onClick函數
- 10. JavaScript,如何調用函數
- 11. 如何調用javascript函數?
- 12. 如何調用PHP函數?
- 13. 如何調用函數setOnItemClickListener
- 14. 如何調用函數
- 15. 如何調用jquery函數?
- 16. 如何調用javascript函數
- 17. 如何調用.change()函數?
- 18. YII如何調用函數?
- 19. 如何調用函數
- 20. 如何調用該函數?
- 21. 如何調用IEnumerable函數
- 22. 如何NSLog調用函數
- 23. $ $如何調用函數?
- 24. 如何函數會調用
- 25. 如何調用函數
- 26. 如何調用javascript函數
- 27. 如何調用Javascript函數
- 28. 如何調用JavaScript函數?
- 29. 如何調用自調用函數
- 30. 如何在調用javascript函數時調用gwt函數
由此得出一個餡餅從零到角A,哪裏的角B來了,所以我們必須從A餡餅到B? – Maysam 2010-07-19 19:25:58