Alright. Take the projection of the center onto the line segment using %. . This is not allowed to be more than 0 or less than 1, so use (0>.1<.]) to take the endpoints if it is. Then find this point on the line again and see if it is inside the circle. C (R>:+/&.:*:)@:([- ]* 0>.1<.%.)&(-&S) E
Not tested yet, but I will update on that... Marshall -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Henry Rich Sent: Thursday, October 07, 2010 7:58 AM To: Programming forum Subject: Re: [Jprogramming] Puzzle: line-circle/sphere intersection I intend that a segment wholly inside the circle/sphere to be counted as intersecting. In other words, the circle/sphere is solid and we want to know if the segment touches any of it. Henry Rich On 10/7/2010 7:52 AM, R.E. Boss wrote: > That was bad reading from my side. > The formulas should be: > > ((S-C)<R)*.((E-C)<R) -...@+. ((S-C)>R)*.((E-C)>R) > > D=: +&.*:/"1 (S,:E)-"1 C > > (D<R) -...@+.&(*./) D>R > > Apart from that, the mathematics is not correct either. I will give it > another thought. > > > R.E. Boss > > >> -----Oorspronkelijk bericht----- >> Van: [email protected] [mailto:programming- >> [email protected]] Namens Bo Jacoby >> Verzonden: donderdag 7 oktober 2010 13:02 >> Aan: Programming forum >> Onderwerp: Re: [Jprogramming] Puzzle: line-circle/sphere intersection >> >> Hello Boss. >> >> I do not understand your notation. Henry wrote "startpoint S and >> endpoint E". You wrote "endpoints A and B", but you use E in your pseudo code. >> Please explain. >> >> It seems to me that you must compute the distances (s) from C to S, >> (e) from C to E and (p) from C to the closest point P, (the >> perihelion), and you must determine (b) if P is between S and E. >> Intersection occurs if (s<R and e>R) or (s>R and e<R) or (b and p<R and (s>R or e>R)). >> >> --- Den tors 7/10/10 skrev R.E. Boss<[email protected]>: >> >> Fra: R.E. Boss<[email protected]> >> Emne: Re: [Jprogramming] Puzzle: line-circle/sphere intersection >> Til: "'Programming forum'"<[email protected]> >> Dato: torsdag 7. oktober 2010 09.49 >> >> 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 >> >> >> --------------------------------------------------------------------- >> - 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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
