我正在嘗試創建類似「Big Wheel」的價格。有點兒像這樣:在Android上獲得弧形或橢圓形點數
我已經得到了左側的橢圓形,右弧頂部和底部的帖子進行。我迷失在哪裏是如何創造內在的道路而不訴諸一堆複雜的數學。我想,如果我能以某種方式獲得我形狀上的點數,我可以很容易地通過這種方式製作我的線條。然而,我沒有找到任何東西在Android SDK中給我這個。
有沒有什麼辦法可以在Android中獲取繪製對象的點?如果沒有,是否有更簡單的解決方案,我沒有看到?
在此先感謝!
編輯#1:
下面我後採取了重擊在數學和我似乎無法得到它的工作:(
這是我到目前爲止有:
float a = (leftOval.bottom - leftOval.top)/2;
float b = (leftOval.right - leftOval.left)/2;
float x1 = (float) getXForOval(a, b, top + 50);
float y1 = top + 50;
float x2 = x1 + 50;
float y2 = y1;
Log.d("coords", "compute: " + getXForOval(a, b, top + 50) + "");
Log.d("coords", "leftOval.top: " + leftOval.top + "");
Log.d("coords", "leftOval.bottom: " + leftOval.bottom + "");
Log.d("coords", "leftOval.right: " + leftOval.right + "");
Log.d("coords", "leftOval.left: " + leftOval.left + "");
Log.d("coords", "a: " + a + "");
Log.d("coords", "b: " + b + "");
Log.d("coords", "x1: " + x1 + "");
Log.d("coords", "y1: " + y1 + "");
Log.d("coords", "x2: " + x2 + "");
Log.d("coords", "y2: " + y2 + "");
canvas.drawLine(x1, y1, x2, y2, paint);
private double getXForOval(float a, float b, float y) {
// sqrt (a^2 * (1 - y^2/b^2))
// @formatter:off
return Math.sqrt(
Math.abs(
Math.pow(a, 2) * ( 1 -
(Math.pow(y, 2)/Math.pow(b, 2))
)
)
);
// @formatter:on
}
但X值是走出來的方法大。我在做什麼錯?
08-27 18:16:56.574: DEBUG/coords(2785): compute: 2743.647207641682
08-27 18:16:56.584: DEBUG/coords(2785): leftOval.top: 180.0
08-27 18:16:56.584: DEBUG/coords(2785): leftOval.bottom: 780.0
08-27 18:16:56.584: DEBUG/coords(2785): leftOval.right: 185.0
08-27 18:16:56.584: DEBUG/coords(2785): leftOval.left: 135.0
08-27 18:16:56.584: DEBUG/coords(2785): a: 300.0
08-27 18:16:56.584: DEBUG/coords(2785): b: 25.0
08-27 18:16:56.584: DEBUG/coords(2785): x1: 2743.6472
08-27 18:16:56.584: DEBUG/coords(2785): y1: 230.0
08-27 18:16:56.584: DEBUG/coords(2785): x2: 2793.6472
08-27 18:16:56.584: DEBUG/coords(2785): y2: 230.0
Android用矩形繪製橢圓,這是否意味着a是矩形的高度,b是寬度? +1 – javamonkey79
@ javamonkey一半高度和一半寬度。 – IronMensan
我嘗試了你的建議,我必須錯過一些東西... – javamonkey79