Finding 3rd point if 2points and 2 distance are known.

hi friends,

I got a problem to find out the unknown point in a polygon with 5 points. when 2 points let A(a,b) and B(p,q) and distance r1 from A to unknown point E(X1, Y1), and distance r2 from B to E are given I have to find point E.

I try to solve this by considering as 2 circles, 1st circle with A as center, and radii as r1, and 2nd circle with B as center and r2 as radii.

The real proble is whether the method i followed is correct or not i dont know. any interested person please check my code and, can tell me about the mistakes i am doing, whther the method i followed wrong or not, or is there any easy method to solve this.

basically my project is a GIS related web application, here it is the manipulated necessary code.

/*

* CirclesIntersectionPoints.java

*

* Created on March 15, 2007, 4:25 PM

*

* Vemula KiranKumar,

* Associate ID - 1997.

* GeoSpace Integrated Solutions,

* Hyderabad.

*

*/

package com.org.Demarcation.importcoord;

/**

*

* @author Vemula KiranKumar.

*/

import java.lang.Math;

/*class CalculatePoints1 {

public static void main(String[] args) {

CirclesIntersectionPoints newPoints = new CirclesIntersectionPoints(-9, 1, 7, 5, -5, 18);

System.out.println("In the main program-x1>"+newPoints.getX1());

System.out.println("In the main program-y1>"+newPoints.getY1());

System.out.println("In the main program-x2>"+newPoints.getX2());

System.out.println("In the main program-y2>"+newPoints.getY2());

}

}*/

/*

*This class is used to find the intersection points of two circles

*Let Circle1 have a center point A(a,b), and Circle 2 have a center point B(p,q)

* and radious of circle 1 is r1, radious of circle 2 is r2,

* intersection points of circle 1 and circle 2 are E(X1, Y1) and (X2, Y2) that have to calculated by this program.

* procedure: -

* K = (1/4)squreroot(((r1+r2)^-d^)(d^-(r1-r2)^))

*d^ = (x2-x1)^ + (y2-y1)^

*

* K is the area of the triangle formed by the centers of the two circles and one of their points of intersection;

* d is the distance between the circles centers;

*r1, r2 are the circles' radii; (x1,y1) and (x2,y2) are the circles' centers

* The two solutions, then, are

*x = (1/2)(x2+x1) + (1/2)(x2-x1)(r1^-r2^)/d^ ?2(y2-y1)K/d^

*y = (1/2)(y2+y1) + (1/2)(y2-y1)(r1^-r2^)/d^ ?-2(x2-x1)K/d^

*/

class CirclesIntersectionPoints{

/* Default Constructor */

public CirclesIntersectionPoints(){

this.a=0;

this.b=0;

this.r1=0;

this.p=0;

this.q=0;

this.r2=0;

this.X1=0;

this.Y1=0;

this.X2=0;

this.Y2=0;

}

/* Parameterised constructor*/

public CirclesIntersectionPoints(double x1,double y1,double d1,double x2,double y2,double d2){

setA(x1);

setB(y1);

setR1(d1);

setP(x2);

setQ(y2);

setR2(d2);

System.out.println(this.a+", "+this.b+", "+this.r1+", "+this.p+", "+this.q+", "+this.r2 +" --> Real values ");

try{

interSectionPoints();// finding the intersection points.

}catch (Exception ex){

ex.printStackTrace();

}// finding the intersection points.

}

/*-Given Point 1(x1, y1) distance d1-*/

publicdouble getA(){

return this.a;

}

privatevoid setA(double x1){

this.a = x1;

}

publicdouble getB(){

return this.b;

}

privatevoid setB(double y1){

this.b = y1;

}

publicdouble getR1(){

return this.r1;

}

privatevoid setR1(double d1){

this.r1 = d1;

}

/*-Given Point 2(x2, y2) distance d2-*/

publicdouble getP(){

return this.p;

}

privatevoid setP(double x2){

this.p = x2;

}

publicdouble getQ(){

return this.q;

}

privatevoid setQ(double y2){

this.q = y2;

}

publicdouble getR2(){

return this.r2;

}

privatevoid setR2(double d2){

this.r2 = d2;

}

/*-New Point (X1, Y1) -*/

publicdouble getX1(){

return this.p;

}

privatevoid setX1(double newx1){

this.X1 = newx1;

}

publicdouble getY1(){

return this.Y1;

}

privatevoid setY1(double newy1){

this.Y1 = newy1;

}

/*-New Point (X2, Y2) -*/

publicdouble getX2(){

return this.X2;

}

privatevoid setX2(double newx2){

this.X2 = newx2;

}

publicdouble getY2(){

return this.Y2;

}

privatevoid setY2(double newy2){

this.Y2 = newy2;

}

/*-end of the getter setter -*/

/*

* finding the Intersection points.

* x = (1/2)(x2+x1) + (1/2)(x2-x1)(r1^-r2^)/d^ ?2(y2-y1)K/d^

* y = (1/2)(y2+y1) + (1/2)(y2-y1)(r1^-r2^)/d^ ?-2(x2-x1)K/d^

*

*/

publicvoid interSectionPoints(){

double aa = 0, bb = 0, rr1 = 0, pp = 0, qq = 0, rr2 = 0, sqrdistance = 0, areaoftri = 0;

double partx1 = 0, partx2 = 0, partx3 = 0;

double party1 = 0, party2 = 0, party3 = 0;

double _x1 = 0, _x2 = 0, _y1 = 0, _y2 = 0;

aa = getA();

bb = getB();

rr1 = getR1();

pp = getP();

qq = getQ();

rr2 = getR2();

sqrdistance = sqrdistBetweenCenters();// getting the distance between the centers of circles.

areaoftri = areaofTriangle();// getting the area of triangle.

/*

* Now Calculate the partx1, partx2, partx3 for XX1, XX2 coordnates,

* and Calculate the party1, party2, party3 for YY1, YY2 coordnates.

* _x1 = partx1 + partx2 + partx3

* _x2 = partx1 + partx2 - partx3

* _y1 = party1 + party2 + party3

* _y2 = party1 + party2 - party3

*/

sqrdistance = sqrdistBetweenCenters();

areaoftri = areaofTriangle();

/*

* finding the X coordinates.

*/

partx1 = (pp + aa) / 2;

partx2 = ((pp - aa) * ( (Math.pow(rr1,2) ) - (Math.pow(rr2,2)) ))/ (2 * sqrdistance);

partx3 = (2 * (qq - bb) * areaoftri) / sqrdistance;

_x1 = partx1 + partx2 + partx3;

_x2 = partx1 + partx2 - partx3;

/*

* Setting the x coordinates

*/

setX1(_x1);

setX2(_x2);

/*

* finding the Y coordinates.

*/

party1 = (qq + bb) / 2;

party2 = ((qq - bb) * ( (Math.pow(rr1,2) ) - (Math.pow(rr2,2)) ))/ (2 * sqrdistance);;

party3 = -(2 * (pp - aa) * areaoftri) / sqrdistance;

_y1 = party1 + party2 + party3;

_y2 = party1 + party2 - party3;

/*

* Setting the y coordinates

*/

setY1(_y1);

setY2(_y2);

}

/*

* This method will calculate the K, area of the triangle ABE.

* K = (1/4)squreroot(((r1+r2)^-d^)(d^-(r1-r2)^))

* where d is the distance between the two centers.

* (a, b) --> center of circle 1, with radii r1(given distance d1)

* (p, q) --> center of circle 2, with radii r2(given distance d2)

*/

publicdouble areaofTriangle(){

double areaoftri = 0;

double part1 = 0;

double part2 = 0;

double sqrdistance = 0;//distance between

double aa,bb,rr1,pp,qq,rr2;

aa = getA();

bb = getB();

rr1 = getR1();

pp = getP();

qq = getQ();

rr2 = getR2();

System.out.println(aa+", "+bb+", "+rr1+", "+pp+", "+qq+", "+rr2+"-->OK Test Passed.");

/*

* getting the square of distance between

* centers of 2 circles.

*/

sqrdistance= sqrdistBetweenCenters();

System.out.println("squre distance is >"+sqrdistance+"-->OK Test Passed.");

/*

* calculating part1, part 2 and subsitute in formula

* K = (1/4)squreroot((part1)*(part2))

*/

part1 = Math.pow((rr1 + rr2),2)- sqrdistance;

part2 = sqrdistance - Math.pow((rr1 - rr2),2);

areaoftri = (Math.sqrt(part1*part2))/4;

System.out.println("Area of Triangle is >"+areaoftri+"> Not OK! Not Yet Tested! ");

return areaoftri;

}

/*

* This method calculate the squre of distance between

* the two points of the circle centers

*

*/

publicdouble sqrdistBetweenCenters(){

double sqrdistance = 0;

double aa = 0, bb = 0, pp = 0, qq = 0;

aa = getA();

bb = getB();

pp = getP();

qq = getQ();

sqrdistance = (Math.pow((pp-aa),2)) + (Math.pow((qq-bb),2));

return sqrdistance;// OK. Test Passed.(kiran)

}

protected String kirankumarVemula;

/* Given Point 1(x1, y1) with distance d1*/

privatedouble a;

privatedouble b;

privatedouble r1;

/* Given Point 2 (x2, y2) with distance d2*/

privatedouble p;

privatedouble q;

privatedouble r2;

/* Calculated Point 1 */

privatedouble X1;

privatedouble Y1;

/* Calculated Point 2 */

privatedouble X2;

privatedouble Y2;

}

[15734 byte] By [kirankumarvemulaa] at [2007-11-26 21:44:29]
# 1

People who might want to answer the OP might first check if their answer is not already given in this thread:

http://forum.java.sun.com/thread.jspa?threadID=5147440

@OP: when crossposting, please post a link to your original thread. People might take the time to respond to you while that same answer has already been given in your other thread.

prometheuzza at 2007-7-10 3:32:19 > top of Java-index,Security,Cryptography...