Solved

How to find coordinates of intersection of a line and a circle

Posted on 2004-10-14
9
5,793 Views
Last Modified: 2008-01-09
Hello experts,

I have a circle plotted in x,y coordinates.  The center is at (14,5) with a radius of 5.

I have a point (*) at (16,6).  I need a formula to determine the x,y coordinates where
a line intersects the circle (at ? below) if drawn from the center of the circle through the point *.

y
|                    
|             .
|         .      ?.
|               *    
|       .     @     .
|
|         .       .
|             .
|
+-------------------------x

The coordinates I gave are just an example, I need a formula to solve any center, radius and * point.

BTW: This is not a homework problem. If I had paid more attention in geometry though I would
proabably know how to do this.   This is not really a Java problem but I didn't know the
best forum to post it in.
0
Comment
Question by:kselvia
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 92

Assisted Solution

by:objects
objects earned 250 total points
ID: 12314433
0
 
LVL 12

Author Comment

by:kselvia
ID: 12314848
I saw that (and had actually already looked at it) and the answer is probably there someplace but I need it spelled out.

Given the data I have:  The center point, another point inside the circle, where will a line drawn from the center throug the point cross the circle.
0
 
LVL 92

Expert Comment

by:objects
ID: 12315881
the equation is given on that page, which part is giving you problems?
0
 
LVL 12

Author Comment

by:kselvia
ID: 12315895
The part where I find the equation on the page.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 92

Expert Comment

by:objects
ID: 12315980
"gives the points of intersection as ..."
http://mathworld.wolfram.com/c1img3452.gif
0
 
LVL 37

Accepted Solution

by:
zzynx earned 250 total points
ID: 12316528
x1 = 14, y1 = 5
x2 = 16, y2 = 6

dx = 2
dy = 1
dr =  2.236

D = 14*6-16*5 = 4
0
 
LVL 12

Author Comment

by:kselvia
ID: 12317526
Yes I understand now. Thank you both very much.
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 12317590
Something like this?

class Circle
{

...
/**
 * Find the intersection of this circle with the line defined by point p1 & p2
public Point Intersect(Point p1, Point p2)
{
   int dx=p2a.x-p1.x;
   int dy=p2.y-p1.y;
   int dr=Math.sqrt(dx*dx+dy*dy);
   int D=p1.x*p2.y-p2.x*p1.y;
   int discriminant=this.radius*this.radius*dr*dr-D*D;
   if (discriminant<0)
      return null;  //No intersection;
   else if (discriminant==0)
      ;//Tangant line there is only ONE intersection
    else if (discriminant>0)
      ;//The line intersects at TWO points

   //Compute intersection for ONE point (to compute intersection at OTHER point change + to a -)
   int x=(D*dy+Math.sgn(dy)*dx*Math.sqrt(discriminant))/(dr*dr);
   int y=(-D*dx+Math.abs(dy)*Math.sqrt(discriminant))/(dr*dr);
   return new Point(x,y);
}
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12317614
Thanks for accepting
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Application launch issue with Apache Tomcat 5 19
starter POM and spring-boot-starter,  spring-boot-web 2 40
eclipse java  build path 6 43
servlet doXXX methods 3 34
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now