Since the word 'intersect' is used, I assume you mean the boundary of the
circle/sphere (and not the area), so that a line segment which is completely
inside is not intersecting. One point at the boundary means intersecting, I
assume. 
So the segment is not intersecting if and only if it is completely inside or
completely outside the circle/sphere.


If the line segment is given by the endpoints A and B, the pseudo code is
rather straightforward:

((A-E)<R)*.((B-E)<R) -...@+. ((A-E)>R)*.((B-E)>R) 

so ones gets

D=: +&.*:/"1 (A,:B)-"1 E

(D<R) -...@+.&(*./) D>R

(untested)


R.E. Boss
 

> -----Oorspronkelijk bericht-----
> Van: [email protected] [mailto:programming-
> [email protected]] Namens Henry Rich
> Verzonden: woensdag 6 oktober 2010 22:54
> Aan: Programming forum
> Onderwerp: [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

Reply via email to