Skip to content

Control points getters and setters

Onur Rauf Bingol edited this page Jul 10, 2018 · 1 revision

It might look confusing when you check the control points and weights getters and setters in the NURBS module. Although the documentation and the examples repository have details on how they are used and stored in the classes, I would like to summarize these details on this wiki page.

Difference between BSpline and NURBS modules

During the development of NURBS-Python, the main reference book was The NURBS Book by Piegl and Tiller. On the book, B-Spline shapes use control points, referenced as P and NURBS shapes use weighted control points, referenced as Pw. NURBS curves uses a 1-dimensional array of Pw and NURBS surfaces use a 2-dimensional array of Pw arranged in order Pw[u][v] where first dimension corresponds to u-direction and second dimension corresponds to v-direction. ctrlpts_size_u and ctrlpts_size_v properties control the 2-dimensional array size where they correspond to len(Pw) and len(Pw[0]), accordingly.

For instance:

Pw = [[[1, 2, 1], [3, 4, 1], [5, 6, 1], [7, 8, 1]], 
      [[1, 2, 1], [3, 4, 1], [5, 6, 1], [7, 8, 1]]]
len(Pw)  # equal to 2
len(Pw[0])  # equal to 4

How points are represented in NURBS-Python

In NURBS-Python, all points are a list of floating point numbers. For instance; [1, 2, 0.5] might have two different meanings depending on where it is used:

  1. If it is Pw, then it represents a 2-dimensional point with P = [2, 4] and W = [0.5]
  2. If it is P, then it represents a 3-dimensional point with P = [1, 2, 0.5]

Getters and Setters

ctrlpts2d

In BSPpline.Surface class, this property sets/gets P and in NURBS.Surface class, this property sets/gets Pw. Both of them are 2-dimensional array of points.

ctrlpts

This property sets/gets 1- dimensional array of unweighted control points in all classes. The weights are automatically generated as an array of 1s or updated with the existing ones in NURBS.Curve and NURBS.Surface classes.

weights

This property is only available in NURBS module. As the name implies, it gets/sets the weights vector. You should set the control points (unweighted ones are good too), before setting the weights.

ctrlptsw

This property is only available in NURBS module. It gets/sets Pw but it accepts 1-dimensional array of points.