Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would start this one with pure mathematics!</p> <p>Assuming, that both ImageView1 and ImageView2 have no cropping (e.g. the lines in the pictures are the diagonal of the ImageView), you could use the width and the height of both pic's to express both lines in formulas. Here's an example. NOTE: I use the Android coordinate system -> point (0,0) is top left corner with y incrementing to the bottom!!!</p> <p><a href="http://i.stack.imgur.com/R0vKe.png" rel="nofollow">Click here for graphical representation</a></p> <p>Line1</p> <pre>y = h1/w1(x - a1) + b1</pre> <p>Line2</p> <pre>y = -h2/w2(x - a2) + b1 + h2</pre> <p>Now we want the point where line1 = line2, so we get</p> <pre>h1/w1(x - a1) + b1 = -h2/w2(x - a2) + b1 + h2</pre> <p>If you re-write the equation you'll get:</p> <pre>x = (w1*w2*(b2 + h2 - b1) + h1*w2*a1 + h2*w1*a2) / (h1*w2 + h2*w1);</pre> <p>Once you know the x-coordinate, you can use that to find the y-coordinate... Below is some code:</p> <pre><code> private void check() { // Setup variables for shorter notation int w1 = mImg1.getWidth(); int h1 = mImg1.getHeight(); int a1 = mImg1.getLeft(); int b1 = mImg1.getTop(); int w2 = mImg2.getWidth(); int h2 = mImg2.getHeight(); int a2 = mImg2.getLeft(); int b2 = mImg2.getTop(); int x = 0; if(h1*w2 + h2*w1 == 0) { // Return to avoid division by zero return; } else { // Calculate the x-value using the re-written formula x = (w1*w2*(b2 + h2 - b1) + h1*w2*a1 + h2*w1*a2) / (h1*w2 + h2*w1); } // Now use the x-value to calculate the y-value int y = h1 / w1 * (x - a1) + b1; Log.d("Output", "x: " + x + " y:" + y); } </code></pre> <p>NOTE: You might want to set your ImageViews to android:width="wrap_content" and android:height="wrap_content". Otherwise, the images are fixed to the size you enter! I've tested it with an ImageView with a circle background. If you use the calculated x-y coordinates, it draws the ball right at the intersection! Good luck</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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