Circle Triangle Picking

Author

Eric W. Weisstein
April 13, 2008

This notebook downloaded from http://mathworld.wolfram.com/notebooks/ComputationalGeometry/CircleTrianglePicking.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/CircleTrianglePicking.html.

©2008 Wolfram Research, Inc. except for portions noted otherwise

Initialization

Area[t1_,t2_]:=2Abs[Sin[t1/2]Sin[t2/2]Sin[(t1-t2)/2]]

Numerical

rnd=With[{n=10^6},Transpose[{RandomReal[{0,π},n],RandomReal[{0,2π},n]}]];//Timing

areas=Area@@@rnd;//Timing

Through[{Mean,Variance}[areas]]

Through[{Min,Max}[areas]]

<<BarCharts`

BarChart[BinCounts[areas,.02],BarEdges->None,BarSpacing->-.2]

Triangle Encloses Center

<<ComputationalGeometry`

EnclosesCenterQ[x1_,x2_]:=Length[ConvexHull[{{0,0},{1,0},Through[{Cos,Sin}[x1]],Through[{Cos,Sin}[x2]]}]]===3

With[{l=Take[rnd,10^5]},
Count[EnclosesCenterQ@@@l,True]/Length[l]
]//N//Timing

With[{l=Take[rnd,All]},
Count[EnclosesCenterQ@@@l,True]/Length[l]
]//N//Timing

Moments

Simplify[D[2Sin[(Subscript[θ, 1])/2]Sin[(Subscript[θ, 2])/2]Sin[((Subscript[θ, 1])-(Subscript[θ, 2]))/2],(Subscript[θ, 1]),(Subscript[θ, 2])]]

Normalization

Integrate[1,{(Subscript[θ, 1]),0,Pi},{(Subscript[θ, 2]),0,2Pi}]

Mean

N[3/(2Pi)]

Numerical

(1/(2(π^2)))NIntegrate[Area[(Subscript[θ, 1]),(Subscript[θ, 2])],{(Subscript[θ, 1]),0,Pi},{(Subscript[θ, 2]),0,2Pi}]

v4.2

(1/(2(π^2)))Integrate[Area[(Subscript[θ, 1]),(Subscript[θ, 2])],{(Subscript[θ, 1]),0,Pi},{(Subscript[θ, 2]),0,2Pi}]//Timing

v5

(1/(2(π^2)))Integrate[A[(Subscript[θ, 1]),(Subscript[θ, 2])],{(Subscript[θ, 1]),0,Pi},{(Subscript[θ, 2]),0,2Pi}]//Timing

...wrong...

v5.1.1

(1/(2(π^2)))Integrate[A[(Subscript[θ, 1]),(Subscript[θ, 2])],{(Subscript[θ, 1]),0,Pi},{(Subscript[θ, 2]),0,2Pi}]//Timing

...wrong...

v5.2

(1/(2(π^2)))Integrate[A[(Subscript[θ, 1]),(Subscript[θ, 2])],{(Subscript[θ, 1]),0,Pi},{(Subscript[θ, 2]),0,2Pi}]//Timing

...wrong...

v6

(1/(2(π^2)))Integrate[Area[(Subscript[θ, 1]),(Subscript[θ, 2])],{(Subscript[θ, 1]),0,Pi},{(Subscript[θ, 2]),0,2Pi}]//Timing

...wrong...

V6.1

(1/(2(π^2)))Integrate[Area[(Subscript[θ, 1]),(Subscript[θ, 2])],{(Subscript[θ, 1]),0,Pi},{(Subscript[θ, 2]),0,2Pi}]//Timing

...wrong...

(1/(2(π^2)))Integrate[Area[(Subscript[θ, 1]),(Subscript[θ, 2])],{(Subscript[θ, 2]),0,2Pi},{(Subscript[θ, 1]),0,Pi}]//Timing

(1/(2(π^2)))Integrate[Area[(Subscript[θ, 1]),(Subscript[θ, 2])],{(Subscript[θ, 1]),0,Pi},{(Subscript[θ, 2]),0,2Pi},GenerateConditions->True]//Timing

(1/(2(π^2)))Integrate[Area[(Subscript[θ, 1]),(Subscript[θ, 2])],{(Subscript[θ, 2]),0,2Pi},{(Subscript[θ, 1]),0,Pi},GenerateConditions->True]//Timing

$Version

General Moments

Integrate[A[(Subscript[θ, 1]),(Subscript[θ, 2])]^n,{(Subscript[θ, 1]),0,Pi},{(Subscript[θ, 2]),0,2Pi}]/2/(π^2)

(1/(2(π^2)))Table[NIntegrate[A[(Subscript[θ, 1]),(Subscript[θ, 2])]^n,{(Subscript[θ, 1]),0,Pi},{(Subscript[θ, 2]),0,2Pi},Method->QuasiMonteCarlo,MaxPoints->10^6],{n,0,6}]//Timing

v4.2

(1/(2(π^2)))Table[Integrate[A[(Subscript[θ, 1]),(Subscript[θ, 2])]^n,{(Subscript[θ, 1]),0,Pi},{(Subscript[θ, 2]),0,2Pi}],{n,0,6}]

N[%%]

...wrong for n=3, 5, ....

v5.0.1

(1/(2(π^2)))Table[Integrate[A[(Subscript[θ, 1]),(Subscript[θ, 2])]^n,{(Subscript[θ, 1]),0,Pi},{(Subscript[θ, 2]),0,2Pi}],{n,0,5}]//Timing

N[Rest[%]]

wrong for n=1

v5.1

(1/(2(π^2)))Table[Integrate[A[(Subscript[θ, 1]),(Subscript[θ, 2])]^n,{(Subscript[θ, 1]),0,Pi},{(Subscript[θ, 2]),0,2Pi}],{n,0,5}]//Timing

N[Last[%]]

wrong for n=1

(1/(2(π^2)))Table[Integrate[A[(Subscript[θ, 1]),(Subscript[θ, 2])]^n,{(Subscript[θ, 1]),0,Pi},{(Subscript[θ, 2]),0,(Subscript[θ, 1])2,Pi}],{n,0,5}]//Timing

Do[Print[(1/(2(π^2)))Integrate[A[(Subscript[θ, 1]),(Subscript[θ, 2])]^n,{(Subscript[θ, 1]),0,Pi},{(Subscript[θ, 2]),0,(Subscript[θ, 1]),2Pi}]//Timing],{n,0,5}]

v6

(1/(2(π^2)))Table[Integrate[A[(Subscript[θ, 1]),(Subscript[θ, 2])]^n,{(Subscript[θ, 1]),0,Pi},{(Subscript[θ, 2]),0,2Pi}],{n,0,5}]//Timing

N[Rest[%]]

wrong for n=1

(1/(2(π^2)))Table[Integrate[A[(Subscript[θ, 1]),(Subscript[θ, 2])]^n,{(Subscript[θ, 1]),0,Pi},{(Subscript[θ, 2]),0,(Subscript[θ, 1])2,Pi}],{n,0,5}]//Timing

Do[Print[(1/(2(π^2)))Integrate[A[(Subscript[θ, 1]),(Subscript[θ, 2])]^n,{(Subscript[θ, 1]),0,Pi},{(Subscript[θ, 2]),0,(Subscript[θ, 1]),2Pi}]//Timing],{n,0,5}]

List

m={1,(3/(2π)),(3/8),(35/(32 π)),(45/128),(3003/(2560 π)),105/256,415701/(286720*Pi),17325/32768,5311735/(2752512*Pi),189189/262144}

Timing[nm=(1/(2(π^2)))Table[NIntegrate[A[(Subscript[θ, 1]),(Subscript[θ, 2])]^n,{(Subscript[θ, 1]),0,Pi},{(Subscript[θ, 2]),0,2Pi},Method->QuasiMonteCarlo,MaxPoints->10^6],{n,0,10}]]

m-nm//Chop

eo=Transpose[Partition[m,2]]

Through[{Numerator,Denominator}[eo[[1]]]]

Through[{Numerator,Denominator}[Pi eo[[2]]]]

Variance

Simplify[((3/(2 π)))^2-(3/8)]

Together[%]

-(3/8) (-1+(6/(π^2)))//N

Cannot CAD

Simplify`PiecewiseIntegrate;
PiecewiseDump`$ShowIntegrals=True;

Integrate[Abs[Area[Evaluate[Triangle[{{x1,y1},{x2,y2},{x3,y3}}]]]]Boole[x1^2+y1^2==1&&x2^2+y2^2==1&&x3^2+y3^2==1],{x1,-∞,∞},{y1,-∞,∞},{x2,-∞,∞},{y2,-∞,∞},{x3,-∞,∞},{y3,-∞,∞}]//Timing

Area[Evaluate[Triangle[{{x1,y1},{x2,y2},{x3,y3}}]]]