The distance to the line doesn't solve the problem. We are interested only in intersections with the line-segment. The line-segment extended may intersect the circle even if the segment itself is far away.
Henry Rich On 10/6/2010 5:59 PM, Marshall Lochbaum wrote: > You could find the area of triangle CSE and divide by half the length of > line SE for the distance between the center and the line. Unfortunately I > don't see a formula for the area of a triangle in n dimensions without > invoking Heron's Formula (which is a terrible idea since we are working with > vectors). > As a starting point, the area of a triangle given by a shape 3 2 list of 2d > vectors is > [: -:@| -/ .*@:(,.&1) > > Something involving linear algebra is probably also possible. > > Marshall > > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Henry Rich > Sent: Wednesday, October 06, 2010 4:54 PM > To: Programming forum > Subject: [Jprogramming] Puzzle: line-circle/sphere intersection > > Given circle/sphere with center C and radius R, and a line-segment with > startpoint S and endpoint E, write the J code to tell whether the > line-segment intersects the circle/sphere. > > R is an atom, the rest are lists with 2 or 3 atoms. > > This problem arises in collision detection for games and simulators, or if > you are trying to see whether a path intersects a round obstacle. > > I found a solution whose brevity surprised me. > > Henry Rich > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
