0

メソッドを使用して円弧を描きたい:.Canvas.drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter, Paint paint)

円と円の中心点と半径に 2 つの点があります。

楕円形の四角形に正確に何を設定する必要があり、startAngleとsweepAngleを計算する方法は?

以下のコードを試しました:

m_radiusRect.set(x1, Math.min(y1, y2), x2, Math.max(y1,y2));
float startAngle = (float)((Math.toDegrees( Math.atan2(x1 - 360.0, 360.0 - y1) ) + 360.0) % 360.0);
float sweepAngle = (float)((Math.toDegrees( Math.atan2(x2 - 360.0, 360.0 - y2) ) + 360.0) % 360.0) - startAngle;

canvas.drawArc(m_radiusRect, startAngle, sweepAngle, false, m_paint);
4

1 に答える 1

0

この回答を見て、中心からの点の角度を見つけてください。

それに基づいて、x1 と x2 の 2 つの角度を見つけると、a1 と a2 と表示されます。

それから、

sweepAngle = a2 - a1;
startAngle = a1;

編集済み

リンクで指定された式は、中心を考慮していないため機能していないようです。

ここで中心は (cx, cy)

float startAngle = (int) ((float) Math.toDegrees( Math.atan2(x1 - cx, y1 - cy)));
         float sweepAngle = (int) ((float) Math.toDegrees( Math.atan2(x2 - cx, y2 - cy))) - startAngle;

         Rect rect = new Rect();

         rect.left = (int) (cx - radius);
         rect.top = (int) (cy - radius);
         rect.right = (int) (cx + radius);
         rect.bottom = (int) (cy + radius);
于 2013-04-15T11:40:11.730 に答える