?ReadList

nuvola=ReadList["/Users/falco/Desktop/didattica/curve e superfici 2013bis/disegni.xyz",Number,RecordLists->True];

nuvola

nuvola[[1]]

Length[nuvola]

nuvola1=Map[Drop[#,-3]&,nuvola];

nuvola1[[1]]

Take[nuvola1,10]

Graphics3D[Point[nuvola1],Axes->True]

Length[nuvola1]

Map[Min,Transpose[nuvola1]]

Map[Max,Transpose[nuvola1]]

Graphics3D[Point[nuvola1],Axes->True]

nuvola2=Select[nuvola1,#[[3]]<3&];

Length[nuvola1]

Length[nuvola2]

Graphics3D[{PointSize[.001],Point[nuvola2]},Axes->True]

Map[Max,Transpose[nuvola1]]

Map[Min,Transpose[nuvola2]]

Map[Max,Transpose[nuvola2]]

Manipulate[Graphics3D[{PointSize[.001],Point[Select[nuvola1,zmin<#[[3]]<zmax&]]},Axes->True,ImageSize->600],{{zmin,1.7},-1,11},{{zmax,2.1},-1,11}]

cupola=Select[nuvola1,1.66<#[[3]]<2.1&];

Graphics3D[{PointSize[.001],Point[cupola]},Axes->True,ImageSize->600]

semicupola=Select[nuvola1,And[1.66<#[[3]]<2.1,#[[2]]>-.1]&];

Graphics3D[{PointSize[.001],Point[semicupola]},Axes->True,ImageSize->800]

sezione=Select[nuvola1,And[1.66<#[[3]]<2.1,-.1<#[[2]]<-.09]&];

Length[sezione]

Graphics3D[{PointSize[.003],Point[sezione]},Axes->True,ImageSize->500,ViewPoint->Front]

sezionepiana=Map[{#[[1]],#[[3]]}&,sezione];

sezionepiana[[1]]

Graphics[{PointSize[.003],Point[sezionepiana]},Axes->True,ImageSize->300]

sfera[u_,v_]:={Cos[v]Cos[u],Cos[v]Sin[u],Sin[v]}

Show[{
ParametricPlot3D[sfera[u,v],{u,0,2Pi},{v,0,Pi/2},Mesh->None],ParametricPlot3D[Table[sfera[u,v]/.v->vk,{vk,0,Pi/2,Pi/6}],{u,0,2Pi},PlotStyle->{Red,Thick}],
ParametricPlot3D[Table[sfera[u,v]/.u->uk,{uk,0,2Pi,Pi/6}],{v,0,Pi/2},PlotStyle->{Red,Thick}]
}]

r*{Cos[v]Cos[u],Cos[v]Sin[u],Sin[v]}

sfera[x0_,y0_,z0_,r_][u_,v_]:={x0,y0,z0}+r*{Cos[v]Cos[u],Cos[v]Sin[u],Sin[v]}

ellissoide[x0_,y0_,z0_,a_,b_,c_][u_,v_]:={x0,y0,z0}+{a*Cos[v]Cos[u],b*Cos[v]Sin[u],c*Sin[v]}

Manipulate[Show[{Graphics3D[{PointSize[.001],Point[cupola]},Axes->True,ImageSize->200],ParametricPlot3D[ellissoide[x0,y0,z0,r,r,c][u,v],{u,0,2Pi},{v,0,Pi/2},Mesh->None]}],{{x0,-0.0542},-1,3},{{y0,-0.1601},-1,3},{{z0,1.66},-1,3},{{r,0.493},0.01,2},{{c,0.493},0.01,2}]

ellissoide[-0.04,-0.155,1.66,0.49,0.49,0.4][u,v]

ellissoide[-0.04,-0.155,1.66,0.49,0.49,0.4][u,v][[2]]==-.1

Solve[ellissoide[-0.04,-0.155,1.66,0.49,0.49,0.4][u,v][[2]]==-.1,v]

Show[{Graphics3D[{PointSize[.001],Point[cupola]},Axes->True,ImageSize->200],ParametricPlot3D[ellissoide[-0.04,-0.155,1.66,0.49,0.49,0.4][u,v],{u,0,2Pi},{v,0,Pi/2},Mesh->None],ParametricPlot3D[ellissoide[-0.04,-0.155,1.66,0.49,0.49,0.4][u,v]/.v->ArcCos[0.11224489795918367 Csc[u]],{u,0,2Pi},Mesh->None,PlotStyle->{Red,Thick}]}]

curva[t_]=Drop[ellissoide[-0.04,-0.155,1.66,0.49,0.49,0.4][t,v]/.v->ArcCos[0.11224489795918367 Csc[t]],{2}]

Show[{Graphics[{PointSize[.003],Point[sezionepiana]},Axes->True,ImageSize->300],ParametricPlot[curva[t],{t,0,2Pi},Mesh->None,PlotStyle->{Red,Thick}]}]

ellissoide[-0.04,-0.155,1.66,0.49,0.49,0.4][u,v]/.v->ArcCos[0.11224489795918367 Csc[u]]

v->ArcCos[0.11224489795918367` Csc[u]]

Manipulate[Show[{Graphics3D[{PointSize[.001],Point[cupola]},Axes->True,ImageSize->200],ParametricPlot3D[sfera[x0,y0,z0,r][u,v],{u,0,2Pi},{v,0,Pi/2},Mesh->None]}],{{x0,-0.0542},-1,3},{{y0,-0.1601},-1,3},{{z0,1.66},-1,3},{{r,0.493},0.01,2}]

?Mean

Map[Min,Transpose[cupola]]

Map[Mean,Transpose[cupola]]

dist[P1_,P2_]:=Norm[P1-P2]

dist[{0,0,0},{1,1,1}]

cupola[[1]]

dist[cupola[[1]],sfera[0,-.16,1.66,0.52][u,v]]

?Minimize

cupola[[1]]

Minimize[dist[cupola[[1]],sfera[0,-.16,1.66,0.52][u,v]],{u,v}][[1]]

Take[cupola,10]

Total[Map[Minimize[dist[#,sfera[0,-.16,1.66,0.52][u,v]],{u,v}][[1]]&,Take[cupola,10]]]/10

Length[cupola]

?RandomChoice

Map[Minimize[dist[#,sfera[0,-.16,1.66,0.52][u,v]],{u,v}][[1]]&,Take[cupola,100]]

Total[Map[Minimize[dist[#,sfera[0,-.16,1.66,0.52][u,v]],{u,v}][[1]]&,Take[cupola,10]]]/10

Total[%28]/100

Map[Minimize[dist[#,sfera[0,-.16,1.66,0.52][u,v]],{u,v}][[1]]&,RandomChoice[cupola,100]]

Total[%]/100

Total[Map[Minimize[dist[#,sfera[0,-.16,1.66,0.52][u,v]],{u,v}][[1]]&,Take[cupola,100]]]/100

Total[Map[Minimize[dist[#,sfera[0,-.16,1.66,0.52][u,v]],{u,v}][[1]]&,RandomChoice[cupola,100]]]/100

Total[Map[Minimize[dist[#,sfera[-0.0542,-0.1601,1.66,0.493][u,v]],{u,v}][[1]]&,RandomChoice[cupola,100]]]/100

Total[Map[Minimize[dist[#,sfera[0,-0.1601,1.66,0.493][u,v]],{u,v}][[1]]&,RandomChoice[cupola,100]]]/100

Total[Map[Minimize[dist[#,sfera[0.05,-0.1601,1.66,0.493][u,v]],{u,v}][[1]]&,RandomChoice[cupola,100]]]/100

Show[{Graphics3D[{PointSize[.001],Point[cupola]},Axes->True,ImageSize->600],ParametricPlot3D[sfera[x0,y0,z0,r][u,v],{u,0,2Pi},{v,0,Pi/2},Mesh->None]}],{{x0,-0.0542},-1,3},{{y0,-0.1601},-1,3},{{z0,1.66},-1,3},{{r,0.493},0.01,2}]