Article View: comp.lang.pascal.delphi.misc
Article #726Re: Buffon's Needles
From: Dr John Stockton
Date: Mon, 28 Jun 1999 00:00
Date: Mon, 28 Jun 1999 00:00
88 lines
4678 bytes
4678 bytes
JRS: In article <7l61qb$u9u$1@nnrp1.deja.com> of Sun, 27 Jun 1999
20:33:15 in news:comp.lang.pascal.delphi.misc, David C. Ullrich
<ullrich@math.okstate.edu> wrote:
>In article <3zADx9AXVWd3EwJU@merlyn.demon.co.uk>,
> Dr John Stockton <jrs@merlyn.demon.co.uk> wrote:
>> JRS: In article <7l357k$4m6$1@nnrp1.deja.com> of Sat, 26 Jun 1999
>> 18:13:14 in news:comp.lang.pascal.delphi.misc, David C. Ullrich
>> <ullrich@math.okstate.edu> wrote:
>> > I have no idea what a "subset-capability" is, but modulo
>> >that of course there is. Set one endpoint P1 of the needle to a
>> >random point in a large square. Then set the other endpoint
>> >to another random point. Reject the second endpoint until you
>> >get one with say 0.5 < |P1 - P2| < 2. Then rescale it so
>> >|P1 - P2| = 1. There's your random needle, no trig and hence
>> >no Pi required.
>> >
>> > ("rescale": say P2 := P1 + (P2 - P1)/|P2 - P1| . No
>> >angles, just a square root.)
>>
>> ISTM, seemingly confirmed by test, that your method does not give a
>> uniform distribution of angles.
>
> If so then you're trying something other than what I suggested.
>Did you read all of it or just a few sentences?
Yes; but I took |P1 - P2| as the absolute value of the difference in
each (X, Y) direction.
> Psuedocode (note these are all real variables, converting to
>integers too soon would be bad):
>
>//"Set [...] P1 [...] to a random
>//point in a large square":
>
> N:= LargeNumber;
> P1.X:= N*random;
> P1.Y:= N*random;
This chooses a point at random within a large square - then another.
>//"Then set the other endpoint
>//to another random point. Reject the second endpoint until you
>//get one with say 0.5 < |P1 - P2| < 2":
>
> repeat
> X:= 1 - 2*random;
> Y:= 1 - 2*random;
> until 0.25 < X*X + Y*Y < 4;
>//the actual numbers 0.25 and 4 don't matter
and select those within a circular relative annulus, so to speak.
>//"rescale" as suggested:
>
> r:= sqrt(X*X + Y*Y);
> P2.X:= P1.X + X/r;
> P2.Y:= P1.Y + Y/r;
No need to rescale just to get angles, of course; that was for getting
needles.
> If you don't get a uniform distribution of angles from
>lemme know and I'll make an actual compilable version (if the
>RNG is worse than I thought it won't work, of course. But I
>didn't think the RNG was _that_ bad.)
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).
BUT one is then selecting just a fraction Pi/4 of the points as within
the circle, and comment matching my original comment on Method 2 applies
(typo in that : for Pi/2 read Pi/4) to both of our versions -- as a part
of the whole Buffon, one is doing work substantially equivalent to an
evaluation of Pi in relation to needle angle, before adding scatter of
needle centre position.
It's still a good Web page - but one difference between real Buffonian /
Euclidean life and a computer is that real life has a precision-grade
intrinsic absolute standard of angle, the Turn of 2 Pi radians, whereas
the computer must either have a number or an algorithm supplied.
--
� 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.
Technical Details
Message-ID:
<j+NWi+AgBrd3EwbC@merlyn.demon.co.uk>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>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: Dr John Stockton <jrs@merlyn.demon.co.uk> Subject: Re: Buffon's Needles Date: 1999/06/28 Message-ID: <j+NWi+AgBrd3EwbC@merlyn.demon.co.uk> X-Deja-AN: 494674233 Content-Transfer-Encoding: 8bit X-NNTP-Posting-Host: merlyn.demon.co.uk:158.152.233.145 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> Content-Type: text/plain;charset=iso-8859-1 X-Complaints-To: abuse@demon.net X-Trace: news.demon.co.uk 930552715 nnrp-01:21871 NO-IDENT merlyn.demon.co.uk:158.152.233.145 Organization: Home, Surrey, UK MIME-Version: 1.0 Newsgroups: comp.lang.pascal.delphi.misc,alt.comp.borland-delphi,de.comp.lang.pascal.delphi,fr.comp.lang.pascal