のインテリジェントな使用により、目的をClass CubicCurve2D
達成できるはずです。CubicCurve2D クラスはShape
インターフェイスを実装します。(x, y)
このクラスは、座標空間の 3 次パラメトリック カーブ セグメントを表します。サブクラスは 3 次曲線と精度を指定CubicCurve2D.Float
します。CubicCurve2D.Double
float
double
このクラスでsetCurve(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2);
は、2 つの制御点を設定できます。(ctrlx1, ctrly1)
曲線開始の直前と曲線終了の直後に制御点を設定するとし(ctrlx2, ctrly2)
ます。曲線の角度を度の倍数に維持するために90
、次のように同様に制御点を計算できます (これは に対して計算されます90 deegree
)。
ctrlx1 = x1; // curve start x
ctrly1 = y2 - delta; // curve start y
ctrlx2 = x1 + delta; // curve end x
ctrly2 = y2; // curve end y
次の例では、私は仮定していdelta = 10
ます。

@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g.create();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
CubicCurve2D c = new CubicCurve2D.Double();
int x1 = 150, y1 = 150; //p1
int x2 = 350, y2 = 300;//p3
int ctrlx1, ctrly1, ctrlx2, ctrly2;
int delta = 10;
ctrlx1 = x1; // curve start x
ctrly1 = y2 - delta; // curve start y
ctrlx2 = x1 + delta; // curve end x
ctrly2 = y2;
g2d.drawRect(x1-50, y1-100, 100, 100);
c.setCurve(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2);
g2d.drawRect(x2, y2-50, 100, 100);
g2d.draw(c);
}