Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h3>Steps</h3> <p>Here are a few steps in order to move your rectangle along a circle's rim <strong>when the user taps and holds</strong> to the side of the circle:<br> <strong>1.</strong> Obtain direction desired.<br> <strong>2.</strong> Obtain angle from current x and y coordinates.<br> <strong>3.</strong> Add direction (+1 if counterclockwise, -1 if clockwise) to angle.<br> <strong>4.</strong> Calculate new x and y coordinates.<br> <strong>5.</strong> Update/display rectangle. </p> <h3>Details</h3> <p><strong>1.</strong> In pseudocode, <code>direction = sign(Rectangle1.x - UsersFingerPosition.x)</code>. Here sign is a function returning -1 if the number was negative, 0 if it is 0, and 1 if it is positive. Note that <code>sign(0)</code> will only result when the user is on the exact x and y of your rectangle's location. In that case, the rectangle would not move (which should be good). In Java, the sign function is <code>Math.signum()</code>.</p> <p><strong>2.</strong> To obtain the current angle use the following java code:</p> <pre><code>double angle = Math.toDegrees(Math.atan2(Circle.y-Rectangle1.y, Rectangle1.x-Circle.x)); </code></pre> <p>Note the order of <code>Circle.y-Rectangle.y</code> and <code>Rectangle.x...Circle.x</code>. This is a result of the coordinate (0, 0) being in the top left corner instead of the center of the screen. </p> <p><strong>3.</strong> Simple enough, just add direction to angle. If desired, do something like</p> <pre><code>angle += direction*2; //So it will move more quickly </code></pre> <p><strong>4.</strong> To get the new x and y coordinates of your rectangle, use the trigonometric functions sine and cosine:</p> <pre><code>Rectangle1.x = Math.cos(Math.toRadians(angle))*Circle.radius + Circle.x - Rectangle1.width; Rectangle1.y = Math.sin(Math.toRadians(angle))*Circle.radius + Circle.y - Rectangle1.height; </code></pre> <p>(where Circle.x and Circle.y are the coordinates of the center of your circle and Circle.radius is naturally it's radius).</p> <p><strong>5.</strong> This one you'll have to take care of (or have already) :)!</p> <p>Hope this helps you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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