# NURBS and Polynomial Basis Functions

Discussion in 'Software' started by Tim B, Aug 16, 2004.

1. Joined: Jan 2003
Posts: 1,438
Likes: 59, Points: 0, Legacy Rep: 841
Location: Southern England

### Tim BSenior Member

I wonder if someone could help me. I am interested in deriving my own accurate NURBS curves and surfaces. I have found reference to the main NURBS equation, that being...

C(u)=(SUM(i=0,n){w_i * P_i * N(u)_i,k})/(SUM(i=0,n){w_i * N(u)_i,k})

where: w_i - is the ith weight
P_i - is the ith control point
N_i,k - is the basis function

k is the order of the curve (n-1?)
n is the number of knots
u is the position along the curve

Unfortunately, I have only found complicated recursive functions for the basis function, and being an engineering programmer I avoid recursion if at all possible. My question is then, is there a non-recursive (or simple) basis function for a NURBS curve.

Incidentally, the basis function for the bernstein polynomials is easy, and the sort of thing I'm looking for.

Cheers,

Tim B.

2. Joined: Mar 2003
Posts: 397
Likes: 18, Points: 18, Legacy Rep: 206
Location: Perth, Western Australia

### Andrew MasonSenior Member

Go on, take a walk on the wild side, try some recursion.

3. Joined: Dec 2003
Posts: 55
Likes: 2, Points: 0, Legacy Rep: 40
Location: Pensacola, FL

### redcoopersMember

Hi, I've been working with the same problem, but for a different purpose.

Most people use Bezier or NURBS to construct a surface (ie, a hull). I, however, do not want a complete surface, but need a way to interpolate locally for each point. For me, Bernstein polynomials are a very good way of doing this because the value is the identity at the endpoints (without messing with knots). Furthermore, they're extremely quick.

Before I move my code to C++, I make some trials in MATLAB. I've attached three m-files of what I use for Bezier Curves. If you don't know MATLAB, it's not hard to read. It's basically pseudocode...

If you need more references I suggest mathworld.wolfram.com. Very good.

-Jon

#### Attached Files:

• ###### Bez.zip
File size:
1.1 KB
Views:
577
4. Joined: Jan 2003
Posts: 1,438
Likes: 59, Points: 0, Legacy Rep: 841
Location: Southern England

### Tim BSenior Member

Thanks, I'll give the recursive formula a shot, I was trying to err away from it as it involves messy programming, but hey ho, it's a computer, so it can cope.

Cheers, I'll let you know how I get on,

Tim B.

5. Joined: Jan 2003
Posts: 1,438
Likes: 59, Points: 0, Legacy Rep: 841
Location: Southern England

### Tim BSenior Member

Well, evidently I have been barking up the wrong tree for some time now with this problem, but there is hope for all who would like to develope their own code as there are downloads (in C) for B-splines and NURBS available from...

http://www.nar-associates.com/nurbs/c_code.html

having converted the NURBS code into more readable BBC Basic, I am about to start attempting to develope surfaces, then I will try to refine the algorithm for the basis functions.

I am willing to distribute the Basic V code via e-mail on demand.

Cheers,

Tim B.

Tim@MarineDesign.tk

6. Joined: Oct 2003
Posts: 83
Likes: 1, Points: 0, Legacy Rep: 60
Location: Middleburg, FL

### TheFisherJunior Member

I'll code it for you.

Tim,

I am a software professional and I will do the code for you (for free) if you need it.

7. Joined: Jan 2003
Posts: 1,438
Likes: 59, Points: 0, Legacy Rep: 841
Location: Southern England

### Tim BSenior Member

The Fisher,

Thanks, that is a very kind offer, but the fun part of the challenge is writing it and getting it to work myself. I am currently consolidating the B-spline surfaces by writing a basic hull design system for the RISC-OS (tm) system. Whilst not widely useable, I hope it will lay a lot of the ground-work and principles for a conversion into Fortran (either 77 or 90) and thus to a platform-independant hull design package.

This is not the only use, though, it should be obvious that having defined a surface one can find any point on that surface, and also find the normal vector at that point. Knowing the surface and a normal vector we can begin to build grids for CFD. See my website for more details on this subject.

So, thanks for the offer, and perhaps when I need the GUI and want to box it up, I'll contact you, but it is imperative that I work through the maths using my own routines.

Many thanks,

Tim B.

8. Joined: Mar 2003
Posts: 397
Likes: 18, Points: 18, Legacy Rep: 206
Location: Perth, Western Australia

### Andrew MasonSenior Member

Tim

If you look at the two user polls at the top of this forum you will see the following systems -

Bearboat
BioDesign
Carene
Carlson Design Hull Designer
Hull Form
SDN
HullCAO
Autoship
DefCar
Fastship
Maxsurf
MultiSurf
Naval Designer
Prolines
ProSurf
Rhino
SeaSolution

TRIBON (initial design module)
FORAN
SARC
Paramarine
Wolfson Shipshape
Circe/MAAT

Plus there are the general purpose CAD systems with good surface modelling capabilities -
CATIA
Solidworks
Solidedge
ProEngineer
etc.etc.

There are also a whole lot of less well known systems that have niche markets or can't get a commercial foothold.

Can I politely suggest that the world doesn't really need another hull design system at the moment.

What would be useful is a good meshing solution for the different CFD packages, I would encourage you to do more with this project. Ideally it would read a trimmed NURBS surfaces from an IGES file so that it would be compatible with most of the packages listed above.

By the way, forget FORTRAN if you want to do a truly portable piece of software with a decent GUI. I would stick to Java or C++ only. Similarly if you want to do a platform independent program, start on Linux, otherwise do it on Windows. Do not start developing on a non-mainstream OS with a non-mainstream language (and FORTRAN is non-mainstream for commercial cross platform development), you will regret it later on when you have a huge amount of code to revise/rewrite to get your software working on another system.

regards

Andrew

9. Joined: Jan 2003
Posts: 1,438
Likes: 59, Points: 0, Legacy Rep: 841
Location: Southern England

### Tim BSenior Member

Oh dear, Andrew, I am only too well aware of the commercial packages available to solve this problem. I can only assume that you haven't read the 'research' page on my website, or you would have got the jist of what I am trying to do in terms of grid generation.

I feel that you have mis-understood the purpose of writing the main hull-design system. The reason is purely to consolidate the B-spline (and later NURBS) surfaces into something that is at least reasonably useable. I think you would agree that there is an element of convenience about using you're own code (product or developement) because you know that it is easy to dip into and change as nescessary.

The OS:
To be honest I couldn't care less, I just happen to be very used to RISC-OS and fluent in its BBC Basic (just a bit faster to program)

Cheers anyway,

Tim B.

10. Joined: Jan 2003
Posts: 1,438
Likes: 59, Points: 0, Legacy Rep: 841
Location: Southern England

### Tim BSenior Member

Well at last I have a screen-shot of this, so everyone can see what I've been up to for the last few weeks. It is still only in it's elementary stages, but promises to be quite useful, if only for my own purposes.

#### Attached Files:

• ###### PICTURE.JPG
File size:
127 KB
Views:
1,347
11. Joined: Jul 2005
Posts: 7
Likes: 0, Points: 0, Legacy Rep: 10
Location: UK

### suhoiJunior Member

Hi guys,

Is it possible with Matlab to build a surface based on 2 NURBS? I've used a CAD package for that, but the script runs for a while.
I need to extract the points on the surface (conducted by 2, 3 or even 4 NURBS as bounds, to form a closed profile) equally spaced on the both main axes.
In CAD packages, one can just sweep a NURBS along the other and get the surface, which is going to be intersected by 2 sets of orthogonal planes to each NURBS to get some certain x-y grid points.

I'd appreciate any help.

Suhoi

12. Joined: Jan 2003
Posts: 1,438
Likes: 59, Points: 0, Legacy Rep: 841
Location: Southern England

### Tim BSenior Member

Yes, it is possible, but it's not quite as simple as the CAD packages would make it look. I'd strongly suggest that you start with B-Splines (Which are well published and easy to calculate) then when you understand how to generate surfaces, replace the B-spline routines with NURBS routines. Do you have access to (or know) any languages other than Matlab? as Matlab is unlikely to be that fast.

Cheers,

Tim B.

13. Joined: Jul 2005
Posts: 7
Likes: 0, Points: 0, Legacy Rep: 10
Location: UK

### suhoiJunior Member

nurbs

Tim,

I do some MDO involving structural optimisations using matlab and some FEAs. It is handy, but I can look into another software anytime. Matlab is quite good in mathematical stuff, and has B-spline capabilities. The scripts using CAD packages are handy, but time consuming. I am anytime in the position of learning new things related to my work, but what you suggested me is not quite the straightforward way to do it. That's why I appealed to fora, maybe there's already someone creating a surface through 2-3-4 nurbs and can share his know-how with us. I'm pretty sure it's quite an easy task, and as long as you have the surface, and its equation of course, you can do whatever you want with it. But it's a long journey, and CAD scripts seem to be the only alternative at the moment.

I'd appreciate any further effort in helping me out. Regards,

Suhoi

14. Joined: Mar 2003
Posts: 397
Likes: 18, Points: 18, Legacy Rep: 206
Location: Perth, Western Australia

### Andrew MasonSenior Member

These cases are quite straightforward, but you are not really creating true tensor product NURBS surfaces.

In the first case you can just sweep one curve along another by offsetting the co-ordinates of the first curve by the x,y,z values of the second curve.

In the second case where you have 3 or 4 boundary curves, you can do this by using a Coons patch, the mathematics for which are fairly simple. It's basically a weighted blend of the four boundary curves. You should be able to find the maths fairly easily by doing a google search.

have a look at http://www.integratedsoft.com/Papers/research/nurbs/ for more explanation.

15. Joined: Jul 2005
Posts: 7
Likes: 0, Points: 0, Legacy Rep: 10
Location: UK

### suhoiJunior Member

The specific examples for intergrated software are not that helpful.
Theoretical construction of my model is quite simple. The question was how can we use the software's capability and features in order to get the job done. I hope someone can share some of his experiences with regard to this issue, or codes, or at least how long does it take to run ...maybe it's not worth doing that at all. I even did that sot of mesh using GAMBIT....it was about the same amount of time.
I'd appreciate any further help.

Regards,

Suhoi

Forum posts represent the experience, opinion, and view of individual users. Boat Design Net does not necessarily endorse nor share the view of each individual post.
When making potentially dangerous or financial decisions, always employ and consult appropriate professionals. Your circumstances or experience may be different.