Search the Q&A Archives

# can you help me with an algorithm that determines if a given...

<< Back to: sci.math FAQ: How to compute Pi?

 Question by sait_pietro Submitted on 12/8/2003 Related FAQ: sci.math FAQ: How to compute Pi? Rating: Rate this question: N/A Worst Weak OK Good Great can you help me with an algorithm that determines if a given line (p1,p2) intetrcepts a circle (center,radius)

 Answer by okp Submitted on 3/25/2004 Rating: Not yet rated Rate this answer: N/A Worst Weak OK Good Great Lets P1=(x1,y1)      P2=(x2,y2) center=(x0,y0) radius=r The line (p1,p2) intercepts the circle (x0,y0,r) iff (  (x1-x2)*(y1-y0)-(y1-y2)*(x1-x0)  )^2  <  (  (x1-x2)^2+(y1-y2)^2  ) * r^2 or in a compact form    dx=x1-x2    cx=x1-x0    dy=y1-y2    cy=y1-y0   ( dx*cy-dy*cx )^2  <  ( dx^2+dy^2 ) * r^2 It can be probed to steps if 1.- Translation the origin to the center of the circle. 2.- write the line in normal form     x*Cos(a)+y*Sin(a)=d if the distance of the line to the new origin (now the center) is less/equal to the radius then the line intercepts/is tangent to the circle.

Your answer will be published for anyone to see and rate.  Your answer will not be displayed immediately.  If you'd like to get expert points and benefit from positive ratings, please create a new account or login into an existing account below.

FAQS.ORG reserves the right to edit your answer as to improve its clarity.  By submitting your answer you authorize FAQS.ORG to publish your answer on the WWW without any restrictions. You agree to hold harmless and indemnify FAQS.ORG against any claims, costs, or damages resulting from publishing your answer.

FAQS.ORG makes no guarantees as to the accuracy of the posts. Each post is the personal opinion of the poster. These posts are not intended to substitute for medical, tax, legal, investment, accounting, or other professional advice. FAQS.ORG does not endorse any opinion or any product or service mentioned mentioned in these posts.

<< Back to: sci.math FAQ: How to compute Pi?