Cube Line Picking—Face and Interior

Author

Eric W. Weisstein
May 24, 2009

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

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

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

Monte Carlo

pts=Norm/@Table[{RandomReal[],RandomReal[],0}-RandomReal[{0,1},{3}],{(10^6)}];//Timing

Mean[pts]

{Histogram[pts],Histogram[pts,{.02}],Histogram[pts,{.05}]}

pts=Norm/@Table[{RandomReal[],RandomReal[],0}-RandomReal[{0,1},{3}],{(10^7)}];//Timing

{Histogram[pts],Histogram[pts,{.02}],Histogram[pts,{.05}]}

Pieces

With[{u=3},4Integrate[(Sqrt[u-((Sec[θ])^2)]),{θ,ArcCos[(((u-1))^(-1/2))],(π/4)}]]

With[{u=2},4Integrate[(Sqrt[u-((Sec[θ])^2)]),{θ,ArcCos[(((u-1))^(-1/2))],(π/4)}]]

Limit[pn[x],x->(Sqrt[2]),Direction->1]//FullSimplify//Expand//Quiet

2(Sqrt[2])With[{u=2},{-(5/3)-u+2(Sqrt[u-2])+u(Sqrt[u-2])-(1/3)(((u-2))^(3/2))+2(ArcSin[(((u-1))^(-1/2))]-ArcCos[(((u-1))^(-1/2))])+2(u-1)(ArcSin[(((u-1))^(-1/2))]-ArcCos[(((u-1))^(-1/2))]),-4Integrate[(Sqrt[u-((Sec[θ])^2)]),{θ,ArcCos[(((u-1))^(-1/2))],(π/4)}]}]//FullSimplify//Total//Expand

(Subscript[ρ, 2])

-4Integrate[u-((Sec[θ])^2),{θ,0,ArcCos[(u^(-1/2))]},Assumptions->1<u<(Sqrt[2])]

-4Integrate[(Sqrt[u-((Sec[θ])^2)]),{θ,0,ArcCos[(u^(-1/2))]},Assumptions->1<u<(Sqrt[2])]

i=-4Integrate[(Sqrt[u-((Sec[θ])^2)]),θ,Assumptions->1<u<(Sqrt[2])]

FullSimplify[i,1<u<(Sqrt[2])&&0<θ<ArcCos[(u^(-1/2))]]

i=(4 (Sqrt[2]) (-(Sqrt[u]) ArcSin[(Sqrt[(u/(-1+u))]) Sin[θ]]+ArcTan[(((Sqrt[2]) Sin[θ])/(Sqrt[-2+u+u Cos[2 θ]]))]) Cos[θ] (Sqrt[u-((Sec[θ])^2)]))/((Sqrt[-2+u+u Cos[2 θ]]))

Limit[i,θ->0]

i/.θ->ArcCos[(1/(Sqrt[u]))]

Limit[i,θ->ArcCos[(1/(Sqrt[u]))]]

FullSimplify[%,1<u<(Sqrt[2])]

(-2 π (1+(Sqrt[u]))+4π)//Simplify

h[u_?NumericQ]:=-4NIntegrate[(Sqrt[u-((Sec[θ])^2)]),{θ,0,ArcCos[(u^(-1/2))]}]

Plot[-2 π (1+(Sqrt[u]))+4π,{u,1,(Sqrt[2])}]

Plot[h[u],{u,1,(Sqrt[2])}]

Simplify[(-2 π (1+(Sqrt[u]))+4π)]

Plot[h[u]-(-2 π (1+(Sqrt[u]))+4π),{u,1,(Sqrt[2])}]

(Subscript[ρ, 3])

-4Integrate[(Sqrt[u-((Sec[θ])^2)]),{θ,ArcCos[(((u-1))^(-1/2))],(π/4)},Assumptions->(Sqrt[2])<u<(Sqrt[3])]

(∫_((cos^(-1))((1/(Sqrt[u-1]))))^(π/4))(Sqrt[u-(sec^2)(θ)])\[DifferentialD]θ==2 (tan^(-1))((Sqrt[u-2]))+(Sqrt[u]) ((csc^(-1))((Sqrt[2-(2/u)]))-(tan^(-1))((Sqrt[(u-2) u])))-(π/2)

Plot[#[u],{u,0,3},PlotRange->All]&/@{(Subscript[ρ, 1]),(Subscript[ρ, 2]),(Subscript[ρ, 3])}

Closed Form

(∫_(ArcCos[(1/(Sqrt[u-1]))])^(π/4))(Sqrt[u-((Sec[θ])^2)])\[DifferentialD]θ==-(2 ArcTan[(Sqrt[u-2])])+(Sqrt[u]) (ArcCsc[(Sqrt[2-(2/u)])]-ArcTan[(Sqrt[(u-2) u])])+(π/2)

(Subscript[ρ, 1])[u_]:=π(Sqrt[u])-π u+(2/3)(u^(3/2))
(Subscript[ρ, 2])[u_]:=-(1/3)+(1+π)u-2(Sqrt[u-1])-2u(Sqrt[u-1])+(2/3)(((u-1))^(3/2))-2u(ArcSin[(u^(-1/2))]-ArcCos[(u^(-1/2))])-2 π (-1+(Sqrt[u]))
(*
(Subscript[ρ, 3])[u_]:=-(5/3)-u+2(Sqrt[u-2])+u(Sqrt[u-2])-(1/3)(((u-2))^(3/2))+2(ArcSin[(((u-1))^(-1/2))]-ArcCos[(((u-1))^(-1/2))])+2(u-1)(ArcSin[(((u-1))^(-1/2))]-ArcCos[(((u-1))^(-1/2))])-4NIntegrate[(Sqrt[u-((Sec[θ])^2)]),{θ,ArcCos[(((u-1))^(-1/2))],(π/4)}]
*)
(Subscript[ρ, 3])[u_]:=-(5/3)-u+2(Sqrt[u-2])+u(Sqrt[u-2])-(1/3)(((u-2))^(3/2))+2(ArcSin[(((u-1))^(-1/2))]-ArcCos[(((u-1))^(-1/2))])+2(u-1)(ArcSin[(((u-1))^(-1/2))]-ArcCos[(((u-1))^(-1/2))])-4(-(π/2)+2 ArcTan[(Sqrt[-2+u])]+(Sqrt[u]) (ArcCsc[(Sqrt[2-(2/u)])]-ArcTan[(Sqrt[(-2+u) u])]))
(Subscript[ρ, 3])[u_]:=(1/3) (-5+8 (Sqrt[-2+u])-3 u+2 (Sqrt[-2+u]) u+3 π (2+u))-4 (Sqrt[u]) ArcCsc[(Sqrt[2-(2/u)])]-4 (2+u) ArcTan[(Sqrt[-2+u])]+4 (Sqrt[u]) ArcTan[(Sqrt[(-2+u) u])]
px[u_]:=Piecewise[{
{(Subscript[ρ, 1])[u],0<u<1},
{(Subscript[ρ, 2])[u],1<u<2},
{(Subscript[ρ, 3])[u],2<u<3}
}]
p[u_]:=2u px[(u^2)]

PDF

p[u]//TraditionalForm

FullSimplify[p[l],0<l<(Sqrt[3])]//TraditionalForm

FullSimplify[(Subscript[ρ, 3])[u],(Sqrt[2])<u<(Sqrt[3])]

(1/3) (-5+6 π+8 (Sqrt[-2+u])+2 (Sqrt[-2+u]) u-3 u (1+π-4 (π/2-ArcTan[(Sqrt[u-2])]))-24 ArcTan[(Sqrt[-2+u])]+12 (Sqrt[u]) (-ArcCsc[(Sqrt[2-(2/u)])]+ArcTan[(Sqrt[(-2+u) u])]))//FullSimplify

Plot[ArcCsc[(Sqrt[u-1])]-(π/2-ArcTan[(Sqrt[u-2])]),{u,2,3}]

FullSimplify[Integrate[p[v],{v,0,u},Assumptions->0<u<(Sqrt[3])],0<u<(Sqrt[3])]

d[u_]:=Piecewise[{{(1/30)*u^3*(5*Pi*(4 - 3*u) + 8*u^2), u <= 1}, 
   {(1/30)*(3 + 24*Sqrt[-1 + u^2] - 5*Pi*(3 + 4*u^2*(-3 + 2*u)) + 
      u^4*(15 - 16*Sqrt[-1 + u^2]) - 2*u^2*(5 + 34*Sqrt[-1 + u^2]) + 
      60*u^4*ArcSec[u]), Inequality[1, Less, u, LessEqual, Sqrt[2]]}}, 
  (1/30)*(27 - 105*Pi + 10*(-5 + 6*Pi)*u^2 - 15*(1 + Pi)*u^4 + 
    12*Sqrt[-2 + u^2] + 68*u^2*Sqrt[-2 + u^2] + 8*u^4*Sqrt[-2 + u^2] - 
    80*u^3*ArcCsc[Sqrt[2 - 2/u^2]] + 60*(-1 + u^4)*
     ArcCsc[Sqrt[-1 + u^2]] - 120*ArcTan[(-2 + u)/Sqrt[-2 + u^2]] + 
    120*ArcTan[(2 + u)/Sqrt[-2 + u^2]] + 
    80*(-3*(-1 + u^2)*ArcTan[Sqrt[-2 + u^2]] + 
      u^3*ArcTan[u*Sqrt[-2 + u^2]]))]

MakeBoxes[cdf[x_],TraditionalForm]:=RowBox[{"D","(",MakeBoxes[x,TraditionalForm],")"}]

GraphicsGrid[{{Plot[p[u],{u,0,(Sqrt[3])},PlotStyle->{Red},Exclusions->None,AxesLabel->{l,P[l]}],
Plot[d[u],{u,0,(Sqrt[3])},PlotStyle->{Red},Exclusions->None,AxesLabel->{l,cdf[l]//TraditionalForm}]}},ImageSize->400,Spacings->-30]

Moments

Integrate[p[u],{u,0,(Sqrt[3])}]

p/@{0,(Sqrt[3])}

All

Integrate[(u^n) p[u],{u,0,(Sqrt[3])},Assumptions->n>0]//Timing

Odd

Table[Integrate[(u^(2n-1)) p[u],{u,0,(Sqrt[3])}],{n,5}]//FullSimplify//Together//Column//TraditionalForm

N[Last[%]]

Even

Table[Integrate[(u^(2n)) p[u],{u,0,(Sqrt[3])}],{n,0,5}]//Timing