Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2014

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Distance Between a B-Spline Surface & Point

  • To: mathgroup at smc.vnet.net
  • Subject: [mg132242] Re: Distance Between a B-Spline Surface & Point
  • From: Itai Seggev <itais at wolfram.com>
  • Date: Wed, 22 Jan 2014 03:30:46 -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>

On Tue, Jan 21, 2014 at 03:02:48AM -0500, Bill 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.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]]
> 
> 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.

You can't minimize a boolean-valued function (which is what you have)!.
Minimize the distance subject to separate constraints:

NMinimize[{(gx[u, v] - 2)^2 + (gy[u, v] - 3)^2 + (gz[u, v] - 4)^2, 
  0 <= u <= 1, 0 <= v <= 1}, {u, v}]

Out[67]= {2.76919, {u -> 0.670339, v -> 0.70555}}

In[68]:= f[u, v] /. Last[%]

Out[68]= {3.53079, 3.65139, 3.9603}

--
Itai Seggev
Mathematica Algorithms R&D
217-398-0700 



  • Prev by Date: Re: How to show 1+2+3+ ... = -1/12 using
  • Next by Date: Re: Distance Between a B-Spline Surface & Point
  • Previous by thread: Distance Between a B-Spline Surface & Point
  • Next by thread: Re: Distance Between a B-Spline Surface & Point