Let us consider the case where S is the origin and E is a unit vector. The general problem can be reduced to that case. The segment SE intersects the sphere with center C and radius R provided
(*: R) = *: length (t*E) - C for some number t with (0 <: t) *. (t <: 1) . Using (V o V) = *: length V where o is +/ . * we arrive at ( 0 <: D =: (*: R) + (*: C o E) - (C o C) ) *. ( t e. (C o E) (+ , -) %: D ) *. ( (0 <: t) *. (t <: 1) ) as the condition for segment ES to intersect the sphere. --Kip Murray On 10/6/2010 3:53 PM, Henry Rich wrote: > 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
