Re: Is there somebody familiar with nurbs or b-Spline? [message #55539 is a reply to message #55537] |
Mon, 27 August 2007 08:05   |
Vince Hradil
Messages: 574 Registered: December 1999
|
Senior Member |
|
|
On Aug 27, 4:19 am, airy.ji...@gmail.com wrote:
> In fact,I'm still trying to read the DXF file into IDL.The Spline in
> the DXF is construct with nurbs line.The IDL have a
> method :Spline_P,but it can't reconstruct completely the same
> shape.Who can tell me how to use the nurbs create the Spline.I know
> it's complex and hard to describe,so ,if there are some source code
> can be showed it would be perfect.
> Thanks!
This function worked for me:
First I get all the controlpts for the spline. Then, in my function
ncp=# of control points, the controlpts are (in my case) 2 X ncp.
nsegs is the number of line segments per controlpt that I want to make
my spline into (4L is usually enough for me). The returned value is
the 2 X (nsegs*ncp) line segments needed to dray a polyline.
Hope this helps.
function eval_spline, ncp, controlpts, nsegs
tarray = findgen(nsegs)/(nsegs)
np = (ncp-1)/3
sval = fltarr(2,nsegs*np+1)
for i=0l, np-1 do begin
p0 = controlpts[*,3*i]
p1 = controlpts[*,3*i+1]
p2 = controlpts[*,3*i+2]
p3 = controlpts[*,3*i+3]
sval[*,nsegs*i] = p0
for j=1l, nsegs-1 do begin
t = tarray[j]
vert = p0*(1-t)*(1-t)*(1-t) + p1*3.0*t*(1-t)*(1-t) +
p2*3.0*t*t*(1-t) + p3*t*t*t
sval[*,nsegs*i+j] = vert
endfor
endfor
sval[*,nsegs*np] = controlpts[*,ncp-1]
return, sval
end
|
|
|