Solve system of two equations in Android / java
<p>I have two equations (Distance and slope of a line formula) </p>

<p>d = sqrt( (x2 - x1)^2 + (y2 - y1)^2 )<br>
m = (y2 - y1) / (x2 - x1) </p>

<p>Known: d, m, x1, y1<br>
Unknown: x2, y2</p>

<p>The problem is the distance equation isn't linear...</p>

<p>Is there a way to code this in java (using Android compatible libraries) to solve? I tried doing simple guessing but it is too slow. </p>

<p>Thanks</p>

<p><strong>EDIT: Code for triangle</strong> </p>

<pre><code>        Point p1 = new Point();
        Point p2 = new Point();
        projection.toPixels(gp1, p1);
        projection.toPixels(gp2, p2);

        Point p3 = new Point();
        double slope = (p2.y - p1.y) / (p2.x - p1.x);
        double x = 0;
        if (p2.y - p1.y &gt;= 0 &amp;&amp; p2.x - p1.x &gt;= 0) {
            x = - Math.sqrt(600 / (1 + slope*slope)) + p2.x;
        } else if (p2.y - p1.y &gt;= 0 &amp;&amp; p2.x - p1.x &lt; 0) {
            x = Math.sqrt(600 / (1 + slope*slope)) + p2.x;
        } else if (p2.y - p1.y &lt; 0 &amp;&amp; p2.x - p1.x &gt;= 0) {
            x = - Math.sqrt(600 / (1 + slope*slope)) + p2.x;
        } else if (p2.y - p1.y &lt; 0 &amp;&amp; p2.x - p1.x &lt; 0) {
            x = Math.sqrt(600 / (1 + slope*slope)) + p2.x;
        }
        double y = -slope*p2.x + slope*x + p2.y;

        p3.set((int) x, (int) y);

        double inverseSlope = 0;
        if (slope == 0) {
            inverseSlope = Double.MAX_VALUE;
        } else {
            inverseSlope = -1 / slope;
        }

        x = -Math.sqrt(300 / (1 + inverseSlope*inverseSlope)) + p3.x;
        y = -Math.sqrt(300 / (1 + inverseSlope*inverseSlope))*inverseSlope + p3.y;

        Point p4 = new Point();
        p4.set((int) x, (int) y);

        x = Math.sqrt(300 / (1 + inverseSlope*inverseSlope)) + p3.x;
        y = Math.sqrt(300 / (1 + inverseSlope*inverseSlope))*inverseSlope + p3.y;
        Point p5 = new Point();
        p5.set((int)x, (int) y);
        Path path = new Path();
        path.moveTo(p2.x, p2.y);
        path.lineTo(p4.x, p4.y);
        path.moveTo(p4.x, p4.y);
        path.lineTo(p5.x, p5.y);
        path.moveTo(p5.x, p5.y);
        path.lineTo(p2.x, p2.y);
        path.moveTo(p2.x, p2.y);
        canvas.drawPath(path, mPaint);
</code></pre>

<p>It appears it is being caused by slope is always an integer so when it is &lt; 1 it is 0 which is not good...</p>
