finding 3 rd point if 2 points and and 2 distances are given
hi guys,
i got a problem while solving a geometry problem. problem description is as follows.
i have 2 points p1(x1, y1), p2(x2, y2), and i have to find the a point p3 which is d1 distance from p1, and d2 distance form p2.
here i have to get 2 points for point p3(x3, y3) because i dont know which direction it is.
how to solve this can anybody help me please.
regards,
vemula kiran kumar.
Message was edited by:
kirankumarvemula
# 1
http://mathworld.wolfram.com/Circle-CircleIntersection.html
# 2
hi, thanks for ur reply.
Actually i am not comfortable with coordinate geometry.
but the example u given is about the circle.
my problem is when in a square or polygon, consider p1(x1,y1), p2(x2,y2), p3(x3,y3),p4(x4,y4) are points of that square/polygon, if p1, p2, p4 points, and distance from p2 to p3 as d1, p4 to p3 as d2 is given how to get the point p3.
i tried by taking distance formula like
sqr(d1) = root(sqr(x3-x2)+sqr(y3-y2))
sqr(d2) = root(sqr(x4-x3)+sqr(y4-y3))
and solving them i can get p3(x3, y3). but if i dont know the direction of the point p3(x3, y3) which is at d1 distance from p2, and d2 distance from p4.
as per my knowledge for this i have to get 2 points for p3.
please help me regarding this.
# 3
> hi, thanks for ur reply.
> Actually i am not comfortable with coordinate
> geometry.
Then you need to brush it up.
> but the example u given is about the circle.
Yes, and in your original post you only had 2 starting points, two distances from those points and wanted to find the 3rd point (possibilibly two different 3rd points). The distances you talked about are the radii, and the starting points are the centers of your circles.
# 4
> my problem is when in a square or polygon, consider
> p1(x1,y1), p2(x2,y2), p3(x3,y3),p4(x4,y4) are points
> of that square/polygon, if p1, p2, p4 points, and
> distance from p2 to p3 as d1, p4 to p3 as d2 is given
> how to get the point p3.
> tried by taking distance formula like
> sqr(d1) = root(sqr(x3-x2)+sqr(y3-y2))
> sqr(d2) = root(sqr(x4-x3)+sqr(y4-y3))
What happened to p1?
Note that the link I posted only calculates the x value from the center of one of your circles towards the other center. So if your circles' centers do not have the same y-value, you will need to do some more work!
# 5
thaks again.
what u said is correct. our circles' centers do not have the same y-value.
point p1 is one of the coordinate of the polygon or square. and consider for now it is not necessary for our problem. (for your understanding i mentioned).
can we solve this like finding intersection points of 2 circles ? for example,
a circle c1 with center p2(x2, y2) and radious d1, and
2nd circle c2 with centerp4(x4, y4) and radious d2, both circle intersect each other, then intersction point is p3(x3,y3).
regards,
kiran vemula.
# 6
> thaks again.
> what u said is correct. our circles' centers do not
> have the same y-value.
1 - translate one of the circles so that their centers are alligned (through the y-axis);
2 - calculate the x- and y-point(s) of the intersection of the circles, if any (see the link I posted);
3 - translate the point back to it's original position as well as the discovered insterection point(s).
# 7
hi,
i tried to solve as u said.
mean while i tried in some other manner. please can u tellme whether this is correct way or not.
please see my 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-*/
public double getA(){
return this.a;
}
private void setA(double x1){
this.a = x1;
}
public double getB(){
return this.b;
}
private void setB(double y1){
this.b = y1;
}
public double getR1(){
return this.r1;
}
private void setR1(double d1){
this.r1 = d1;
}
/*-Given Point 2(x2, y2) distance d2-*/
public double getP(){
return this.p;
}
private void setP(double x2){
this.p = x2;
}
public double getQ(){
return this.q;
}
private void setQ(double y2){
this.q = y2;
}
public double getR2(){
return this.r2;
}
private void setR2(double d2){
this.r2 = d2;
}
/*-New Point (X1, Y1) -*/
public double getX1(){
return this.p;
}
private void setX1(double newx1){
this.X1 = newx1;
}
public double getY1(){
return this.Y1;
}
private void setY1(double newy1){
this.Y1 = newy1;
}
/*-New Point (X2, Y2) -*/
public double getX2(){
return this.X2;
}
private void setX2(double newx2){
this.X2 = newx2;
}
public double getY2(){
return this.Y2;
}
private void 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^
*
*/
public void 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;
System.out.println("*******************");
System.out.println(_y1);
System.out.println(_y2);
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)
*/
public double 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 Tested Yet");
return areaoftri;
}
/*
* This method calculate the squre of distance between
* the two points of the circle centers
*
*/
public double 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*/
private double a;
private double b;
private double r1;
/* Given Point 2 (x2, y2) with distance d2*/
private double p;
private double q;
private double r2;
/* Calculated Point 1 */
private double X1;
private double Y1;
/* Calculated Point 2 */
private double X2;
private double Y2;
}
# 8
> hi,
> i tried to solve as u said.
> mean while i tried in some other manner. please can u
> tellme whether this is correct way or not.
Errr, shouldn't that be your job? I mean, if I tell you "yes, everything is a-ok!", do you just take it for granted? I hope not!
Test your code with some circles with varying solutions. ANd check them by hand.
There are four cases to consider:
- no solution possible*;
- exactly one solution;
- two solutions;
- infinite number of solutions.
Post back if you have a specific question. Also, when posting code, please use code-tags (http://forum.java.sun.com/help.jspa?sec=formatting) it makes it so much easier to read.
Good luck.
* Of course if no solution exists in Euclidian space, one can always find Complex solutions! I'm disregarding the Complex plane here.
# 9
thankyou for ur reply.
i try to find out this by taking a graph sheet, drawing 2 circles by using compas, and by taking those values and substituting them in my code.:). that is working fine.
Actually my project is GIS based. no -ve points are used as GIS reference to a place, city or piece of land except for highest point like hills or top of multi store buildings.
I am just confused about whether it is correct or wrong. thats why i posted my code.
once again thanks for ur reply.
# 10
> thankyou for ur reply.
> i try to find out this by taking a graph sheet,
> drawing 2 circles by using compas, and by taking
> those values and substituting them in my code.:).
> that is working fine.
> ...
Ok, so this is the output of your program:
-9.0, 1.0, 7.0, 5.0, -5.0, 18.0 --> Real values
-9.0, 1.0, 7.0, 5.0, -5.0, 18.0 -->OK Test Passed.
squre distance is >232.0 -->OK Test Passed.
Area of Triangle is >52.215299482048366 > Not OK not Tested Yet
-9.0, 1.0, 7.0, 5.0, -5.0, 18.0 -->OK Test Passed.
squre distance is >232.0 -->OK Test Passed.
Area of Triangle is >52.215299482048366 > Not OK not Tested Yet
*******************
-4.745812006454113
7.857880971971355
In the main program-x1>5.0
In the main program-y1>-4.745812006454113
In the main program-x2>-7.596622440583705
In the main program-y2>7.857880971971355
You're trying to find the intersection points of the two circles C1 and C2 where C1
has it's center point at (-9, 1) and has a radius of 7, whereas C2's center lies at
(5, -5) and has a radius of 18.
If the above is correct (and I'm not mistaken!), your solution is that the circles
intersect at P1 = (5.0, -4.7) and P2 = (-7.6, 7.9), all rounded to one decimal after
the comma. P2 is correct, but P1 isn't.
Here's how I got my answer:
First calculate the distance, 'd', between the center-points of the two circles:d = √(|-9 - 5| + |1 - -5|)
= 15.23
Now we calculate 'd1' (see http://mathworld.wolfram.com/images/eps-gif/CircleCircleIntersection_1000.gif)d1 = (r1^2 - r2^2 + d^2) / 2*d
= (7^2 - 18^2 + 15.23^2) / 2*15.23
= (49 - 324 + 231.95) / 30.46
= -43.05 / 30.46
= -1.41
Now we solve 'h', which is 1/2*'a' ('a' in the image from the link I posted)h = √(r1^2 - a^2)
= √(7^2 - -1.41^2)
= √(49 - 1.99)
= 6.86
To find point P3(x3,y3) which is the intersection of line 'd' and 'a' (see
the image again) we use the following formula:x3 = x1 + (d1 * (x2 - x1)) / d
= -9 + (-1.41 * (5 - -9)) / 15.23
= -10.29
y3 = y1 + (d1 * (y2 - y1)) / d
= 1 + (-1.41 * (-5 - 1)) / 15.23
= 1.55
Last but not least, calculate the points P4_i and P4_ii which are the intersection
points of the two circles:x4_i = x3 + (h * (y2 - y1)) / d
= -10.29 + (6.86 * (-5 - 1)) / 15.23
= -12.99
y4_i = y3 - (h * (x2 - x1)) / d
= 1.55 - (6.86 * (5 - -9)) / 15.23
= -4.75
x4_ii = x3 - (h * (y2 - y1)) / d
= -10.29 - (6.86 * (-5 - 1)) / 15.23
= -7.59
y4_ii = y3 + (h * (x2 - x1)) / d
= 1.55 + (6.86 * (5 - -9)) / 15.23
= 7.86
So, as you can see, I find intersection points (-12.99, -4.75) and (-7.59, 7.86).
And if I draw both circles on a piece of paper, my solution seems to be correct.
Message was edited by:
prometheuzz
Note that I did not look at your code, I only ran it once and looked at the output. But you have quite some lines! The operations neccesairy to find the intersections as I did above can be done in a few lines of code.
# 11
you said you are getting answer like.
> (-12.99, -4.75) and (-7.59, 7.86).
yes. that is the correct answer.
i did a mistake while setting the _x1 value in method.
public double getX1(){
return this.p;
}
thats why i am getting values like
(5.0,-4.745812006454113)(-7.596622440583705,7.857880971971355)
in return statement i did a mistake.
public double getX1(){
return this.X1;
}
this will be the correct code. It will give the correct answer
same as you get. If i round the point values i am getting the same
result as you get.
once again thankyou very much for participating in this discussion.
# 12
> ...
> this will be the correct code. It will give the correct answer
> same as you get. If i round the point values i am
> getting the same result as you get.
> once again thankyou very much for participating in
> this discussion.
Good to hear you solved your problem!
And you're welcome.