3

Ellipse2D.Double のコンストラクターで指定されている左上隅ではなく、中心点に基づいて楕円を描画するための解決策を見つけようとしています。写真に見られるように、楕円は同じ中心点と縮尺を持っているはずですが、それは何とか可能ですか?

ここに画像の説明を入力

よろしくお願いします。

4

1 に答える 1

6

If (x,y) is the center you want to use and you can only specify the upper left corner, then use the following:

private Ellipse2D getEllipseFromCenter(double x, double y, double width, double height)
{
    double newX = x - width / 2.0;
    double newY = y - height / 2.0;

    Ellipse2D ellipse = new Ellipse2D.Double(newX, newY, width, height);

    return ellipse;
}

If called with the center point and the width and height, this will "transform" your center point to the upper left corner and create an Ellipse2D which is located just as you want it to be.

于 2012-08-21T09:55:39.137 に答える