????
/**?*/
/**
?????*?畫帶箭頭的線
?????*?
*/
????
public
?
void
?paintk(GC?g,?
int
?x1,?
int
?y1,?
int
?x2,?
int
?y2)?
{

????????
double
?H?
=
?
10
;?
//
箭頭高度???
????????
double
?L?
=
?
7
;
//
底邊的一半??
????????
int
?x3?
=
?
0
;
????????
int
?y3?
=
?
0
;
????????
int
?x4?
=
?
0
;
????????
int
?y4?
=
?
0
;
????????
double
?awrad?
=
?Math.atan(L?
/
?H);?
//
箭頭角度???
????????
double
?arraow_len?
=
?Math.sqrt(L?
*
?L?
+
?H?
*
?H);
//
箭頭的長度???
????????
double
[]?arrXY_1?
=
?rotateVec(x2?
-
?x1,?y2?
-
?y1,?awrad,?
true
,?arraow_len);
????????
double
[]?arrXY_2?
=
?rotateVec(x2?
-
?x1,?y2?
-
?y1,?
-
awrad,?
true
,?arraow_len);
????????
double
?x_3?
=
?x2?
-
?arrXY_1[
0
];?
//
(x3,y3)是第一端點???
????????
double
?y_3?
=
?y2?
-
?arrXY_1[
1
];
????????
double
?x_4?
=
?x2?
-
?arrXY_2[
0
];
//
(x4,y4)是第二端點???
????????
double
?y_4?
=
?y2?
-
?arrXY_2[
1
];

????????Double?X3?
=
?
new
?Double(x_3);
????????x3?
=
?X3.intValue();
????????Double?Y3?
=
?
new
?Double(y_3);
????????y3?
=
?Y3.intValue();
????????Double?X4?
=
?
new
?Double(x_4);
????????x4?
=
?X4.intValue();
????????Double?Y4?
=
?
new
?Double(y_4);
????????y4?
=
?Y4.intValue();
????????
//
g.setColor(SWT.COLOR_WHITE);
????????
//
畫線
????????g.drawLine(x1,?y1,?x2,?y2);
????????
//
畫箭頭的一半
????????g.drawLine(x2,?y2,?x3,?y3);
????????
//
畫箭頭的另一半
????????g.drawLine(x2,?y2,?x4,?y4);

????}
????

????
/**?*/
/**
?????*取得箭頭的繪畫范圍
?????
*/
????
public
?
double
[]?rotateVec(
int
?px,?
int
?py,?
double
?ang,?
boolean
?isChLen,

????????????
double
?newLen)?
{

????????
double
?mathstr[]?
=
?
new
?
double
[
2
];
????????
//
矢量旋轉函數,參數含義分別是x分量、y分量、旋轉角、是否改變長度、新長度???
????????
double
?vx?
=
?px?
*
?Math.cos(ang)?
-
?py?
*
?Math.sin(ang);
????????
double
?vy?
=
?px?
*
?Math.sin(ang)?
+
?py?
*
?Math.cos(ang);

????????
if
?(isChLen)?
{
????????????
double
?d?
=
?Math.sqrt(vx?
*
?vx?
+
?vy?
*
?vy);
????????????vx?
=
?vx?
/
?d?
*
?newLen;
????????????vy?
=
?vy?
/
?d?
*
?newLen;
????????????mathstr[
0
]?
=
?vx;
????????????mathstr[
1
]?
=
?vy;
????????}
????????
return
?mathstr;
????}
posted on 2007-09-21 09:39
JJCEA 閱讀(5292)
評論(4) 編輯 收藏 所屬分類:
swt日記