私は次の問題に固執しています。 私は長方形(50x40 pxは位置:x1、y1と言うことができます)とcirle(半径30、positin x2、y2)を持っています。今、私は明らかにRECT円の唯一の特定の点を結ぶそれらJava - 静的な大きさを持つ2つのオブジェクトの間に矢印を描く
void drawArrow(Graphics g1, int x1, int y1, int x2, int y2,) {
//x1 and y1 are coordinates of circle or rectangle
//x2 and y2 are coordinates of circle or rectangle, to this point is directed the arrow
Graphics2D g = (Graphics2D) g1.create();
double dx=x2-x1;
double dy=y2-y1;
double angle = Math.atan2(dy, dx);
int len = (int) Math.sqrt(dx*dx + dy*dy);
AffineTransform at = AffineTransform.getTranslateInstance(x1, y1);
at.concatenate(AffineTransform.getRotateInstance(angle));
g.transform(at);
g.drawLine(0,0,len,0);
g.fillPolygon(new int[] {len, len-ARR_SIZE, len-ARR_SIZE, len},
new int[] {0, -ARR_SIZE, ARR_SIZE, 0}, 4);
}
このコードの間の矢印を描きたい(この写真で私が真ん中http://imageshack.us/photo/my-images/341/arrk.jpg/でポイントを接続されています)。あなたはこのようにstgを達成する方法を知っていますか? (http://imageshack.us/photo/my-images/833/arr2u.jpg/)私の考えは、長さを短くして新しい座標を計算することでしたが、私はそれで少し苦労しています。
//私はこの方法でこの関数を呼び出す:
drawArrow(g,temp.x+radius/2,temp.y+radius/2,temp2.x+width/2,temp2.y+height/2);