Re: Distance Between a B-Spline Surface & Point
- To: mathgroup at smc.vnet.net
- Subject: [mg132247] Re: Distance Between a B-Spline Surface & Point
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Wed, 22 Jan 2014 03:32:26 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-outx@smc.vnet.net
- Delivered-to: mathgroup-newsendx@smc.vnet.net
- References: <20140121080248.A720969E5@smc.vnet.net>
cpts={ {{1,1,-0.574058},{1,2,0.390267},{1,3,0.616214}, {1,4,-0.115722},{1,5,0.436663}}, {{2,1,0.809682},{2,2,-0.741927},{2,3,-0.865916}, {2,4,-0.0998629},{2,5,-0.241853}}, {{3,1,-0.196909},{3,2,0.796108},{3,3,-0.0602901}, {3,4,0.486659},{3,5,-0.0134192}}, {{4,1,0.657334},{4,2,-0.917066},{4,3,0.98301}, {4,4,-0.875938},{4,5,-0.030303}}, {{5,1,-0.549654},{5,2,0.786582},{5,3,-0.667232}, {5,4,0.568884},{5,5,0.554108}}}; f=BSplineFunction[cpts]; gx[u_?NumericQ,v_?NumericQ]:=f[u,v][[1]]; gy[u_?NumericQ,v_?NumericQ]:=f[u,v][[2]]; gz[u_?NumericQ,v_?NumericQ]:=f[u,v][[3]]; pt={2,3,4}; {dist,sol}=NMinimize[{Norm[pt-{x,y,z}], gx[u,v]==x,gy[u,v]==y,gz[u,v]==z, 0<=u<=1,0<=v<=1}, {x,y,z,u,v}] {4.13757,{x->2.24681,y->1.00001,z->0.386337,u->0.266016,v->8.48701*10^-7}} (Norm[pt-{x,y,z}]/.sol)==dist True f[u,v]/.sol {2.24681,1.00001,0.386337} surfPt={x,y,z}/.sol {2.24681,1.00001,0.386337} Show[ ParametricPlot3D[f[u,v],{u,0,1},{v,0,1}], Graphics3D[{ Thick,Line[{pt,surfPt}], Red,AbsolutePointSize[6],Point[{pt,surfPt}]}], PlotRange->All] Bob Hanlon On Tue, Jan 21, 2014 at 3:02 AM, Bill <WDWNORWALK at aol.com> wrote: > Hi: > > My objective: Find the Distance Between a B-Spline Surface and a Point, > {2,3,4}. > > (Note: The point {2,3,4}, is not on the B-spline surface.) > > > Below is the Mathematica 8.0.4. code I used to try and find the closest > point on the B-spline surface to the point {2,3,4}: > > > cpts={{{1,1,-0.574058},{1,2,0.390267},{1,3,0.616214},{1,4,-0.115722},{1= ,5,0.436663}},{{2,1,0.809682},{2,2,-0.741927},{2,3,-0.865916},{2,4,-0.09986= 29},{2,5,-0.241853}},{{3,1,-0.196909},{3,2,0.796108},{3,3,-0.0602901},{3,4,= 0.486659},{3,5,-0.0134192}},{{4,1,0.657334},{4,2,-0.917066},{4,3,0.98301},{= 4,4,-0.875938},{4,5,-0.030303}},{{5,1,-0.549654},{5,2,0.786582},{5,3,-0.667= 232},{5,4,0.568884},{5,5,0.554108}}}; > > f=BSplineFunction[cpts]; > > gx[u_?NumericQ,v_?NumericQ]:=f[u,v][[1]] > gy[u_?NumericQ,v_?NumericQ]:=f[u,v][[2]] > gz[u_?NumericQ,v_?NumericQ]:=f[u,v][[3]] > > NMinimize[{(x-2)^2 +(y-3)^2+(z-4)^2<=5 && x==gx && y==gy && > z==gz},{x,y,z,u,v}] > > Out(Error message.) > > > Questions: Can this be done using NMinimize? If so, how should this be > coded? If not, how can this be done using Mathematica. > > > Thanks again, > > Bill W. > >
- References:
- Distance Between a B-Spline Surface & Point
- From: Bill <WDWNORWALK@aol.com>
- Distance Between a B-Spline Surface & Point