Note that there are some explanatory texts on larger screens.

plurals
  1. POget points on an arc or oval in Android
    text
    copied!<p>I'm trying to create something like the "Big Wheel" off of the price is right. Kinda like this:</p> <p><img src="https://i.stack.imgur.com/5JeN4.png" alt="big wheel"></p> <p>I've got the left oval, the right arc and the top and bottom posts done. Where I am lost at is how to create the inner lines without resorting to a bunch of complicated math. I figure that if I can get the points on my shapes somehow I can fairly easily make my lines this way. However, I am not finding anything in the Android SDK that gives me this. </p> <p>Is there any way to get the points of drawn objects in Android? If not, is there a simpler solution that I'm not seeing?</p> <p>Thanks in advance!</p> <p><strong>EDIT #1:</strong></p> <p>With the post below I took a whack at the math and I can't seem to get it to work :(</p> <p>This is what I have so far:</p> <pre><code> 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 } </code></pre> <p>But the X value is coming out way large. What am I doing wrong?</p> <pre><code>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 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload