Article View: comp.lang.pascal.delphi.misc
Article #730Re: Buffon's Needles
From: David C. Ullrich
Date: Mon, 28 Jun 1999 00:00
Date: Mon, 28 Jun 1999 00:00
99 lines
5141 bytes
5141 bytes
In article <7+KQSfA9R7d3EwYX@merlyn.demon.co.uk>,
causing a bit of confusion by replying to himself,
Dr John Stockton <jrs@merlyn.demon.co.uk> wrote:
> JRS: In article <j+NWi+AgBrd3EwbC@merlyn.demon.co.uk> of Mon, 28 Jun
> 1999 00:14:40 in news:comp.lang.pascal.delphi.misc, Dr John Stockton
> <jrs@merlyn.demon.co.uk> wrote:
> > ...
> >Yes, *that* should work - actually, ISTM that one could make P1 =
(0,0),
> >randomly generate P2 = (X,Y) within a square around that, accept
those
> >P2 within the inscribed circle and not too near the centre, and use
> >ATAN2(Y, X).
> > ...
>
> If one randomly generates TWO points within a square, repeating until
> they are neither too near or too distant, then (except in the limit as
> "too far" tends to zero, or the square tends to infinite) the slope of
> the line joining the first to the second IS NOT as if drawn randomly
> from a uniform distribution covering all directions. In those limits,
> the proportion of points accepted tends to zero, which is inefficient.
Of course you don't mean that the _slope_ of the line should
have a uniform distribution (no, that's not quite what you said).
No, this IS NOT as if that - did anyone say it was?
> If one randomly generates ONE point within a square, repeating until
the
> centre is neither too near or too distant, then the slope of the line
> joining the centre to the point IS as if drawn randomly from a uniform
> distribution covering all directions - too distant is greater than
half
> the side of the square.
That's exactly right - the "too distant is greater than
half the side of the square" is the content of the correction
I posted this morning to yesterday's post.
> Test program for square Abs(X)<1, Abs(Y)<1; BP7, ATAN2 from Terje
> Mathisen, note "(*..*)" comment :
>
> function atan2(y : extended; x : extended): Extended ; Assembler;
> asm fld [y] ; fld [x] ; fpatan end ;
>
> var R2, X1, X2, Y1, Y2 : extended ;
> A : array [-24..24] of longint ;
> J, K, L : longint ;
> const JM = 30000000 ;
>
> begin Writeln('---') ; FillChar(A, SizeOf(A), 0) ; J := 0 ;
> repeat
> X1 := 2*random-1 ; Y1 := 2*random-1 ; (* use this line *)
> X1 := 0 ; Y1 := 0 ; (* or this one *)
> X2 := 2*random-1 ; Y2 := 2*random-1 ;
> R2 := Sqr(X1-X2) + Sqr(Y1-Y2) ;
> if (R2<1.0) and (R2>0.0001) then begin
> K := Round(7.321 * Atan2(Y1-Y2, X1-X2)) ;
> Inc(A[K]) ; Inc(J) end ;
> until J=JM ;
> K := 0 ;
> for J := Low(A) to High(A) do if A[J]>K then K := A[J] ;
> for J := Low(A) to High(A) do Writeln(J*180/23:0:3,
> '*':Round(A[J]*(60/K))) ;
> Write(^G) ; Readln end.
>
> As it also works compiled with D3 "DCC32 -cc", that ATAN2 must do in
D3.
>
> Do let us know if an error can be seen in the above program, or if
with
> two random points it does not test what you intended,
Who _is_ this addressed to? (And whoever it is what _did_
he intend to test? I have a hard time seeing what the "Write(^G)"
does. Also I seem to be missing your point. Unless your point is
that you don't get a uniform distribution of angles with the
line "X1 := 2*random-1 ; Y1 := 2*random-1 ;". In which case I'm
missing your point - nobody said you would.)
My impression is that through all of this you've been
insisting that a machine needs to already know the value of
Pi, either explicitly or implicitly, to be able to perform
the Buffon thing, making it circular. It's not at all clear
to me whether you're still insisting on this or not.
> on varying the
> constant sides of the R2 comparisons. 7.231 and 60 merely scale for
> display.
>
> --
> � John Stockton, Surrey, UK. jrs@merlyn.demon.co.uk /
JR.Stockton@physics.org �
> Web <URL: http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms,
& links.
>
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
Technical Details
Message-ID:
<7l8lv1$rn9$1@nnrp1.deja.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7ks8ls$mgk$1@bgtnsc03.worldnet.att.net> <Im0c0MABmjc3Ew2K@merlyn.demon.co.uk> <zZIi7jAzW8c3EwDD@merlyn.demon.co.uk> <7l357k$4m6$1@nnrp1.deja.com> <3zADx9AXVWd3EwJU@merlyn.demon.co.uk> <7l61qb$u9u$1@nnrp1.deja.com> <j+NWi+AgBrd3EwbC@merlyn.demon.co.uk> <7+KQSfA9R7d3EwYX@merlyn.demon.co.uk>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 10a726,d24982a2aa52a35f X-Google-Attributes: gid10a726,public X-Google-Thread: 10a7f1,d24982a2aa52a35f X-Google-Attributes: gid10a7f1,public X-Google-Thread: 105ac8,d24982a2aa52a35f X-Google-Attributes: gid105ac8,public X-Google-Thread: 10baee,d24982a2aa52a35f X-Google-Attributes: gid10baee,public From: David C. Ullrich <ullrich@math.okstate.edu> Subject: Re: Buffon's Needles Date: 1999/06/28 Message-ID: <7l8lv1$rn9$1@nnrp1.deja.com> X-Deja-AN: 494874528 References: <7ks8ls$mgk$1@bgtnsc03.worldnet.att.net> <Im0c0MABmjc3Ew2K@merlyn.demon.co.uk> <zZIi7jAzW8c3EwDD@merlyn.demon.co.uk> <7l357k$4m6$1@nnrp1.deja.com> <3zADx9AXVWd3EwJU@merlyn.demon.co.uk> <7l61qb$u9u$1@nnrp1.deja.com> <j+NWi+AgBrd3EwbC@merlyn.demon.co.uk> <7+KQSfA9R7d3EwYX@merlyn.demon.co.uk> X-Http-Proxy: 1.0 x21.deja.com:80 (Squid/1.1.22) for client 139.78.112.79 Organization: Deja.com - Share what you know. Learn what you don't. X-Article-Creation-Date: Mon Jun 28 20:29:37 1999 GMT Newsgroups: comp.lang.pascal.delphi.misc,alt.comp.borland-delphi,de.comp.lang.pascal.delphi,fr.comp.lang.pascal X-Http-User-Agent: Mozilla/4.5 [en] (Win95; U)