Tutorial Grasshopper
Tutorial Grasshopper
Tutorial Grasshopper
Essential Mathematics for Computational Design, second edition by Robert McNeel & Associates is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.
ii
Preface
Essential Mathematics for Computational Design introduces design professionals to foundation mathematical concepts that are necessary for effective development of computational methods for 3D modeling and computer graphics. This is not meant to be a complete and comprehensive resource, but rather an overview of the basic and most commonly used concepts. The material is directed towards designers who have little or no background in mathematics beyond high school. All concepts are explained visually using Grasshopper (GH), the generative modeling environment for Rhinoceros (Rhino). For more information, go to www.rhino3d.com and www.grasshopper3d.com. The content is divided into three parts. The first discusses vector math including vector representation, vector operation, and line and plane equations. The second part reviews matrix operations and transformations. The third part includes a general review of parametric curves with special focus on NURBS curves and the concepts of continuity and curvature. It also quickly reviews NURBS surfaces and polysurfaces. I would like to acknowledge the excellent and thorough technical review of Dr. Greg Arden of Robert McNeel and Associates. His valuable comments were instrumental to produce this second edition. I would also like to acknowledge Ms. Margaret Becker of Robert McNeel and Associates for reviewing the technical writing and formatting the document. Finally, Id like to point out that the material in this book is based partly on a workshop I held at the University of Texas at Arlington for the Tex-Fab event February, 2010. Rajaa Issa Robert McNeel & Associates
iii
Table of Contents
1 Vector Mathematics ......................................................................................................... 1 Vector representation......................................................................................................... 1 Vector operations............................................................................................................... 3 Vector equation of line ..................................................................................................... 13 Vector equation of a plane ............................................................................................... 14 2 Matrices and Transformations ...................................................................................... 16 Introduction...................................................................................................................... 16 Matrix multiplication ......................................................................................................... 16 Affine transformations ...................................................................................................... 17 3 Parametric Curves and Surfaces .................................................................................. 22 Introduction...................................................................................................................... 22 Cubic polynomial curves .................................................................................................. 22 Geometric continuity ........................................................................................................ 25 Curvature......................................................................................................................... 26 Algorithms for evaluating parametric curves ..................................................................... 28 NURBS curves................................................................................................................. 31 Characteristics of NURBS curves..................................................................................... 33 NURBS surfaces.............................................................................................................. 36 Characteristics of NURBS surfaces.................................................................................. 37 Polysurfaces .................................................................................................................... 39 References .......................................................................................................................... 42
iv
1 Vector Mathematics
Vector representation
Vectors indicate a quantity that has "direction" and "magnitude" such as velocity or force. Vectors in 2D coordinate systems are represented with two real numbers in the form: v = <a1, a2> Similarly, in 3-D coordinate system, vectors are represented by three real numbers and would look like: v = <a1, a2, a3> We will use a lower case bold letters to represent vectors. Also vector components are enclosed by angle brackets. Points will use upper case letters. Points coordinates will always be enclosed by round brackets. Using a coordinate system and any set of anchor points in that system, we can represent or visualize these vectors using a line-segment representation. We usually put an arrowhead to show the direction of vectors. For example, if we have a vector that has a direction parallel to the x-axis of a given 3-D coordinate system and a magnitude equal to 5.18 units, then we can write the vector as follows: v = <5.18, 0, 0> To represent that vector, we need an anchor point in the coordinate system. For example, all of the red line segments in the following figure are equal representations of the same vector.
Figure (1): Vector representation in the 3D coordinate system. 1: Grasshopper unit x-axis component. 2: Grasshopper number slider component. 3: Grasshopper point components that is set to reference multiple points in Rhino (in this case referencing v1, v2, v3 and v4). 4: Grasshopper vector display component
Given a 3-D vector v = < a1, a2, a3 >, all vector components a1, a2, a3 are real numbers. Also ALL line segments from a point A(x,y,z) to point B(x+a1, y+a2, z+a3) are EQUIVALENT representation of vector v. So, how do we define the end points of a line segment that represent a given vector? Let us define an anchor point (P0) using Grasshopper x,y,z point component: P0 = (1,2,3)
And a vector using Grasshopper xyz vector component that takes as an input three real numbers: v = <2,2,2> The tip point (P1) of the vector is calculated by adding the corresponding components from anchor point and vector v: P1 = (1+2, 2+2, 3+2) = (3,4,5) The following definition displays this vector using the Grasshopper vector display component, and marks the end of the displayed vector that expectantly coincides with point P1:
Figure (2): Relationship between a vector, vector anchor point and the point coinciding with vector tip location
Position vector
There is one special vector representation that uses the origin P0 (0,0,0) as the vector anchor point. The position vector v = <a1,a2,a3> is represented with a line segment between two points P0 and P1 so that: P0 = (0,0,0) P1 = (a1,a2,a3) A position vector for a given vector v= < a1, a2, a3 > is a special line segment representation from the origin_point(0,0,0) to point (a1, a2, a3). It is very important not to confuse vectors with points that have equivalent components. They are two very different concepts. In the following Grasshopper definition, point P1 coordinates are equal to vector components.
Vector operations
Vector addition
We add vectors by adding corresponding components. That is, if we have two vectors, a and b, the sum a+b is a vector that is calculated as follows: a = <a1, a2, a3> b = <b1, b2, b3> a+b = <a1+b1, a2+b2, a3+b3> For example, if we have a<1, 2, 0> and b<4, 1, 4> the sum a+b=<5, 3, 4> is shown in the following:
The following Grasshopper definition shows how to create the a+b vector by adding corresponding components of the two input vectors a and b.
The resulting vector is the same as that resulting from using Grasshopper's built-in addition component:
Add two vectors by adding their corresponding components. Vector addition is also useful for finding the average direction of multiple vectors. In this case, we usually use same-length vectors. Here is an example that shows the difference between using same-length vectors and different-length vectors on the resulting vector addition:
Input vectors are not likely to be same length. In order to find average direction, you need to use the unit vector of input vectors. As we will see later, a unit vector is a vector of that has a magnitude equal to one. Here is an example that solves adding vectors of different lengths to find average directions in Grasshopper.
Figure (7): Use unit vectors to find average direction of two or more vectors
Vector length
We will use |a| to notate the length of a given vector a. The magnitude or length of a vector a = <a1, a2, a3> is calculated by |a| = sqrt(a12 + a22 +a32) Here is an example of calculating vector magnitude using Grasshopper function component:
Note that Grasshopper vector component has an output L that represents the vector magnitude. Using the same vector in the above example, youll notice that length is equal.
Unit vector
A unit vector is a vector with a magnitude equal to one unit. Unit vectors are commonly used to compare directions of vectors. A vector is called a unit vector when its length or magnitude is equal to one unit.
Vector properties
There are eight properties of vectors. If a, b and c are vectors and s and t are scalar, then: 1. a + b = b + a 2. a + 0 = a 3. s(a+b) = sa + sb 4. st(a) = s(ta) 5. a+(b + c) = (a+b) + c 6. a + (-a) = 0 7. (s + t)a = sa + ta 8. 1 * a = a
Figure (11): The dot product of two vectors as a sum of multiplying corresponding components
Grasshopper has a built-in vector dot product component as shown in the following illustration:
Figure (12): The dot product of two vectors using GH vector dot product component
When calculating the dot product of two unit vectors, the result is always between -1 and +1. The dot product of a vector with itself is that vectors length to the power of two: a.a = |a|2 Proof: If vector a = <a1, a2, a3> then from the definition of dot product of two vectors: a.a = a1*a1 + a2*a2 +a3*a3 or a.a = a12 + a22 +a32 Since we know that: |a| = sqrt(a12 + a22 +a32) Therefore, a.a = |a|2 Here is a Grasshopper sample to demonstrate this property comparing result using dot product component with multiplying the vector length by itself:
The dot product of two unit vectors equals the cosine of the angle between them Proof: From the law of cosines on triangle ABC |AB|2 = |CA|2 + |CB|2 - 2|CA||CB|cos() or: |a-b|2 = |a|2 + |b|2 - 2|a||b|cos() --- (1) |AB|2 is the same as |a-b|2, so we can say: |a-b|2 = {a-b) . (a-b) = a.a - a.b -b.a + b.b = |a|2 - 2a.b +|b|2 --- (2) from (1) & (2) |a|2 - 2a.b +|b|2 = |a|2 + |b|2 2|a||b|cos() then: 2a.b = 2|a||b|cos() or: cos() = a.b / (|a||b|) Vectors a and b are orthogonal if, and only if, a.b = 0. But what is the dot product of two unit vectors if they are parallel? In the most practical way, you can think of the dot product of two vectors to be the projection length of one vector on the other. Here is a demonstration of this concept using Grasshopper. In the first figure, we calculate the dot product of the x-axis unit vector with an input vector v. In the second figure, we project the end point of the position vector v onto a line along the x-axis and calculate the distance from origin to that projection point. Youll notice that the dot product and projection length are equal.
a x b = <a2*b3 a3*b2, a3*b1 - a1*b3, a1*b2 - a2*b1 > This is the Grasshopper definition for evaluating the cross product using these expressions and comparing it with the vector cross product built-in component. They both yield same result.
Figure (16): Calculating the cross product of two vectors using GH cross product component
The vector a x b is orthogonal to both a and b Theorem For any pair of 3d vectors a and b |a x b| = |a||b|sin(), Where is the angle included between the position vectors of a and b. Or if a and b are unit vectors, then the length of their cross product equals the sine of the angle between them. In other words: |a x b| = sin()
10
This is an example to calculate the length of the cross product of two vectors using GH built-in cross product component and compare it to the calculation using the equation mentioned above. As expected, they both yield same result.
Figure (17): Calculating the length of cross product vector using a function and also using GH built-in component for vectors cross product
In determining the cross product, the order of operands is important. For example: a = <1, 0, 0> b = <0, 1, 0> a x b = <0, 0, 1> b x a = <0, 0, -1> In Rhino's right-handed system, the direction of a X b is given by the right-hand rule (where a = index finger, b = middle finger, and result = thumb).
11
Here is the Grasshopper solution following the same steps. Note that in this case the dot product is greater than 0 which means the point is facing the front side of the surface. If the dot product were less than 0 then the point would be on the back.
Figure (18): Find point location relative to surface front and back faces
12
In the figure: L = line v = line direction vector P0 = line position point r = r0 + a --- (1) a = t * v --- (2) Therefore from 1 and 2: r = r0 + t*v --- (3) However, we can write (3) as follows: <x,y,z> = <x0,y0,z0> + <ta, tb, tc> <x,y,z> = <x0+ta, y0+tb, z0+tc> Therefore: x = x0 + ta y = y0 + tb z = z0 + tc Which is the same as: P = P0 + tv This is a Grasshopper definition to get any point on a line:
13
Example In the following figure, given points P0 and P1, find mid point P.
Notice that: a is the position vector for point P0 b is the position vector for point P1 v is the vector going from P0 to P1 From vector addition property: a + v = b, or v=b-a However, the line equation is: P = P0 + t*v, and since t=0.5 and v=b-a (from the above), then we can say: P = P0 + 0.5(b-a) Use the above equation to create a Grasshopper definition:
In general, you can find any point between P0 and P1 by changing the t value between 0 and 1.
14
= a given point on the plane = position vector to P0 = normal vector of the plane = arbitrary point on the plane = position vector to P
We know that the dot product of two orthogonal vectors equals 0, therefore: n . (r - r0) =0 Or we can say: <a,b,c> . <x-x0 , y-y0 , z-z0 > = 0 Solving the dot product gives the scalar equation of the plane: a(x-x0) + b(y-y0) + c(z-z0) = 0 Example How can we find the plane that goes through three points using the origin point and plane normal? In order to find a plane, we need an origin and a plane normal. We have an origin point, which can be any of our three points, so how do we find the normal? We know that the cross product of two vectors is a third vector normal to both of them. This would be the plane normal. Hence, this is how we may solve the question using Grasshopper:
15
Matrix multiplication
Matrix multiplication is used to apply transformation to geometry. A series of transformation matrices is first multiplied to get a final transformation matrix that is in turn used for transforming geometry. Matrix multiplication is one of the frequently used matrix operations, so it is useful to elaborate on. In order to multiply two matrices, they have to matching dimensions. In other words, the number of columns of the first matrix must equal the number of rows of the second matrix. The resulting matrix has size equal to the number of rows from the first matrix and the number of columns from the second matrix. For example, if we have two matrices, M1 and M2, with dimension equal to [2x4] and [4x5] respectively, then there resulting multiplication matrix M1.M2 would have a dimension equal to [2x5] as shown in the following:
16
1. Make sure they match. That is, given two matrices of size dim(M1)=[axb], dim( M2)=[cxd], b must be equal to c. 2. Find the sum of multiplying corresponding items from the first row of the left matrix with the first column of the right matrix to get the item at index(1,1) of the resulting matrix. 3. Repeat step 2 to get all items of the resulting matrix. For example the sum of multiplying third row of left matrix with second column of right matrix yields item at index (3,2) in the resulting matrix. One special matrix is the identity matrix. The main property of this matrix is that if it is multiplied by any other matrix, it does not change its values as in the following: 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 2 3 1 1 1*2+0*3+0*1+0*1 0*2+1*3+0*1+0*1 0*2+0*3+1*1+0*1 0*2+0*3+0*1+1*1 2 3 1 1
Affine transformations
In this section, we will cover a special, but very common, type or transformation called an affine transformation. When applied to geometry affine transformations have the property of preserving parallel line relationships, but not length or angles. Translation (move), rotation, scale, and shear are affine transformations.
We represent a 3d-point as a 4x1 column matrix with a 1 in the last row. This trick allows us to represent translation, and in fact any affine transformation, by matrix multiplication. The general format for a translation matrix is: 1 0 0 a1 0 1 0 a2 0 0 1 a3 0 0 0 1
17
For example, to move point P(2,3,1) by vector v<2,2,2>, the new point location is: P = P + v = (2+2, 3+2, 1+2) = (4, 5, 3) If we use the matrix form and multiply the translation matrix by the input point, then we get the new point location as in the following: 1 0 0 0 0 1 0 0 0 0 1 0 2 2 2 1 2 3 1 1 1*2+0*3+0*1+2*1 0*2+1*3+0*1+2*1 0*2+0*3+1*1+2*1 0*2+0*3+0*1+1*1 4 5 3 1
Rotation transformation
This example shows how to calculate rotation around z-axis and origin point using trigonometry, and then deduce the general matrix format for the rotation. Take a point on x,y plane P(x,y) and rotate it by angle(b). From the figure, we can say the following: x = d cos(a) ---(1) y = d sin(a) ---(2) x' = d cos(b+a) ---(3) y' = d sin(b+a) --- (4) Expanding 3 and 4 using trigonometric identities for the sine and cosine of the sum of angles: x' = d cos(a)cos(b) - d sin(a)sin(b) ---(5) y' = d cos(a)sin(b) + d sin(a)cos(b) ---(6) Using Eq 1 and 2: x' = x cos(b) - y sin(b) y' = x sin(b) + y cos(b) Using the homogenous coordinates, the rotation matrix around z-axis looks like: cos(b) -sin(b) 0 0 sin(b) cos(b) 0 0 0 0 1 0 0 0 0 1 The rotation matrix around x-axis by angle b: 1 0 0 0 0 cos(b) -sin(b) 0 0 sin(b) cos(b) 0 0 0 0 1 The rotation matrix around y-axis by angle b: cos(b) 0 sin(b) 0 0 1 0 0 -sin(b) 0 cos(b) 0 0 0 0 1
18
OpenNURBS, the Rhino geometry library (http://www.openNURBS.org), contains a class called OnXform that handles transformations. It stores a transformation matrix and performs matrix operations. The following is an example of how to rotate an object and examines OnXform matrix values to compare to the general format of the rotation matrix. You can use the same principle to examine other transformations.
Here is a Grasshopper definition for rotating geometry and output matrix values to compare with the general matrix format:
Scale transformation
We know that: P' = ScaleFactor(S) * P or: P'.x = Sx * P.x P'.y = Sy * P.y P'.z = Sz * P.z This is the matrix format for Sx 0 0 0 0 Sy 0 0 0 0 Sz 0 0 0 0 1 scale transformation.
19
Shear transformation
Shear in 3-D is measured along a pair of axes relative to the third axis. For example, a shear along a z-axis will not change geometry along that axis, but will alter x and y. 1- Shear in x and z, keeping the y-coordinate fixed:
20
21
For more details see: http://en.wikipedia.org/wiki/Parametric_equation For more details see: http://en.wikipedia.org/wiki/Cubic_Hermite_spline 4 For more details, see: http://en.wikipedia.org/wiki/B%C3%A9zier_curve
3
22
In most cases, curves are made out of multiple segments. This requires making what is called piecewise cubic curves. Here is an illustration of a piecewise Bezier curve that uses 10 storage points to create a three-segment curve. Note that although the final curve is joined, it does not look smooth.
Although Hermite curves use same amount of parameters as that is of Bezier (4 to define a curve), we have additional information of the tangent curve that can be shared with the next piece to create smoother looking curve with less storage as in the following figure:
In order to maintain even smoother and more continuous curves, there is a powerful curve representation called Non Uniform Rational B-Spline5 (NURBS). Segments share more control points to achieve even smoother curve with less storage as in the following:
23
NURBS curves and surfaces are the main mathematical representation used by Rhino to represent geometry. NURBS curves characteristics and components will be covered with some detail later in this chapter. But how does the parametric equation of a cubic polynomial curve look like? You will likely not need to use these equations in your work, but I thought it would be useful to include the generic form so that you have a reference of it. The parametric equation of a cubic polynomial curve segment: Q(t) = x(t) y(t) z(t) Takes the form: x(t) = axt3 + bxt2 + cxt + dx y(t) = ayt3 + byt2 + cyt + dy z(t) = azt3 + bzt2 + czt + dz We can rewrite the above Q(t) equation to be:: Q(t) = C. T Where T is: T = t3 t2 t 1 And C is the matrix of coefficients: C = ax bx c x dx a y b y cy d y a z b z cz d z We can quickly verify that we can get the original form of the curve equation using matrix multiplication: Q(t) = C. T = ax bx cx dx t3 = axt3 + bxt2 + cxt + dx = x(t) a y b y cy d y . t2 ayt3 + byt2 + cyt + dy = y(t) a z b z cz d z t3 azt3 + bzt2 + czt + dz = z(t) 1
24
Geometric continuity
Continuity is an important concept in 3-D modeling. Continuity is important for achieving visual smoothness and for obtaining smooth light and airflow. The following table shows various continuities and their definitions: G0 (Position continuous) G1 (Tangent continuous) G2 ( Curvature Continous) GN Two curve segments joined together Direction of tangent at joint point is the same for both curve segments Curvatures as well as tangents agree for both curve segments at the common endpoint The curves argree to higher order.
The following example compares curves continuities between curve a from one side and curves b, c, and d from the other. The GH script components calculate tangent vector of each curve at point P and the length of that vector. That is: A = Tangent vector at joint point L = the length of the vector
25
Note that: Curves A and B are G0 continuous (different tangent vector at joint) Curves A and C are G1 continuous (same tangent vector at joint) Curves A and D are G2 continuous (G1 and curvature agrees at the joint)
Curvature
Curvature is a widely used concept in modeling 3-D curves and surfaces. Curvature is defined as the change in inclination of a tangent to a curve over unit length of arc. For a circle or sphere, it is the reciprocal of the radius. At any point on a curve in the plane, the line best approximating the curve that passes through this point is the tangent line. We can also find the best approximating circle that passes through this point and is tangent to the curve. The reciprocal of the radius of this circle is the curvature of the curve at this point. The best approximating circle can lie either to the left or to the right of the curve. If we care about this, then we establish a convention, such as giving the curvature positive sign if the circle lies to the left and negative sign if the circle lies to the right of the curve. This is known as signed curvature. Curvature values of joined curves indicate continuity between these curves as in the following illustration.
For surfaces, normal curvature is one generalization of curvature to surfaces. Given a point on the surface and a direction lying in the tangent plane of the surface at that point, the normal section curvature is computed by intersecting the surface with the plane spanned by the point, the normal to the surface at that point, and the direction. The normal section curvature is the signed curvature of this curve at the point of interest. If we look at all directions in the tangent plane to the surface at our point, and we compute the normal curvature in all these directions, then there will be a maximum value and a minimum value.
Principal curvatures
The principal curvatures of a surface at a point are the minimum and maximum of the normal curvatures at that point. The principal curvatures are used to compute the Gaussian and mean curvatures of the surface.
26
Gaussian curvature The Gaussian curvature of a surface at a point is the product of the principal curvatures at that point. The tangent plane of any point with positive Gaussian curvature touches the surface locally at a single point, whereas the tangent plane of any point with negative Gaussian curvature cuts the surface
A: Positive curvature when surface is bowl-like B: Negative curvature when surface s saddle-like C: Zero curvature when surface is flat in at lease one direction (plane, cylinder, etc.) Mean curvature The mean curvature of a surface at a point is one half the sum of the principal curvatures at that point. Any point with zero mean curvature has negative or zero Gaussian curvature. Surfaces with zero mean curvature everywhere are minimal surfaces. Surfaces with constant mean curvature everywhere are often referred to as constant mean curvature (CMC) surfaces. Physical processes which can be modeled by CMC surfaces include the formation of soap bubbles, both free and attached to objects. A soap bubble, unlike a simple soap film, encloses a volume and exists in equilibrium where slightly greater pressure inside the bubble is balanced by the area-minimizing forces of the bubble itself. Minimal surfaces are the subset of CMC surfaces where the curvature is zero everywhere. Physical processes which can be modeled by minimal surfaces include the formation of soap films spanning fixed objects, such as wire loops. A soap film is not distorted by air pressure (which is equal on both sides) and is free to minimize its area. This contrasts with a soap bubble, which encloses a fixed quantity of air and has unequal pressures on its inside and outside. Mean curvature is useful for finding areas of abrupt change in the surface curvature.
27
This is the Grasshopper definition to evaluate a parameter on a Bzier curve using De Casteljau algorithm. Note that you can change t value between 0 and 1 to find points between the start and end of the Bzier curve.
28
De Boors algorithm details are found in http://en.wikipedia.org/wiki/De_Boor's_algorithm The general description of the algorithm and the example details are found in: http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/de-Boor.html
8
29
1. Calculate coefficients for the first iteration: Ac = (u u1) / ( u1+3 u1) = 0.8 Bc = (u u2) / ( u2+3 u2) = 0.53 Cc = (u u3) / ( u3+3 u3) = 0.2 2. Calculate points using coefficient data: A = 0.2P1 + 0.8P2 B = 0.47 P2 + 0.53 P3 C = 0.8 P3 + 0.2 P4 3. Calculate coefficients for the second iteration: Dc = (u u2) / (u2+3-1 u2) = 0.8 Ec = (u u3) / (u3+3-1 u3) = 0.3 4. Calculate points using coefficient data: D = 0.2A+ 0.8B E = 0.7B + 0.3C
5. Calculate the last coefficient Fc = (u u3)/ (u3+3-2 u3) = 0.6 6. Find the point on curve at u=0.4 parameter F= 0.4D + 0.6E
This is the Grasshopper definition to evaluate the u=0.4 parameter on a NURBS curve using DeBoors algorithm.
30
NURBS curves
NURBS is an accurate mathematical representation of curves and surfaces that is highly intuitive to edit. There are many books and references for those of you interested in an in-depth reading about NURBS (http://en.wikipedia.org/wiki/NURBS). A basic understanding of NURBS is necessary to help you use the NURBS modeler more effectively. Four attributes define a NURBS curve: degree, control points, knots, and evaluation rules:
Degree
Degree is a whole positive number. Rhino allows working with any degree starting with 1. Degree 5 is also common, but the degrees above 5 are not very useful in the real world. Following are a few examples of curves and their degree: Lines and polylines are degree 1 NURBS curves. Order = 2 (order = degree + 1)
Circles and ellipses are examples of degree 2 NURBS curves. They are also rational or nonuniform curves. Order = 3.
Control points
The control points of a NURBS curve is a list of at least (degree+1) points. The most common way to change the shape of a NURBS curve is through moving its control points. Control points have an associated number called a weight. With a few exceptions, weights are positive numbers. When a curves control points all have the same weight (usually 1), the curve is called non-rational. We will have an example showing how to change the weights of control points interactively in Grasshopper.
31
32
Degree = 3 Number of control points = 7 knot vector = (0,0,0,1,1,1,4,4,4) Note: Full knot multiplicity in the middle creates a kink and the curve is forced to go through the associated control point.
Evaluation rule
The evaluation rule uses a mathematical formula that takes a number and assigns a point. The formula involves the degree, control points, and knots. Using this formula, SDK functions can take a curve parameter and produce the corresponding point on that curve. A parameter is a number that lies within the curve domain. Domains are usually increasing and they consist of two numbers: minimum domain parameter (m_t(0)) that is usually the start of the curve and maximum (m_t(1)) at the end of the curve.
33
Degree 3 open curve. Both curve ends coninside with end control points.
Degree 3 closed (non-periodic) curve. Start and end point of the curve overlap a control point.
Moving the control point of a non-periodic curve causes a kink and the curve does not look smooth.
Degree 3 closed periodic curve. Note that curve end/start does not go through a control point. That point is called curve seam. In is noted in red in the figure.
Moving control points of a periodic curve does not affect curve smoothness or cause any kink.
34
Here is the periodic curve using same input (control points and curve degree):
Notice that the periodic curve turned the four input points into seven control points (4 + degree), while the clamped curve used only four control points. The knot vector of the periodic curve uses only simple knots, while the clamped curve start and end knots have full multiplicity. Here are some examples of degree 2 curves. As you may have guessed, the number of control points and knots of periodic curves change when degree changes.
35
Weights
Weights of control points in a uniform NURBS curve are set to 1, but this number can vary in rational NURBS curves. The following example shows how to modify weights of control points interactively in Grasshopper.
NURBS surfaces
You can think of NURBS surfaces as a grid of NURBS curves that go in two directions. The shape of a NURBS surface is defined by a number of control points and the degree of that surface in each one of the two directions (u- and v-directions).
36
NURBS surfaces can be trimmed or untrimmed. Trimmed surfaces use an underlying NURBS surface and closed curves to cut a specific shape of that surface. Each surface has one closed curve that defines the outer border (outer loop) and nonintersecting closed inner curves to define holes (Inner loops). A surface with an outer loop that is the same as that of its underlying NURBS surface and that has no holes is what we refer to as an untrimmed surface.
The surface on the left is untrimmed. The surface on the right is the same surface trimmed with an elliptical hole. Notice that the NURBS structure of the surface does not change when trimming.
37
Degree 1 surface in both u and v directions. All control points lay on the surface
Degree 3 u direction and degree 1 in v direction open surface. Note how surface corners coincide with corner control points.
Degree 3 u direction and degree 1 in v direction closed (non-periodic) surface. Note that there are control points that coincide with surface seam.
Moving control points of a closed (nonperiodic) surface causes a kink and the surface does not look smooth.
38
Degree 3 u direction and degree 1 in v direction periodic surface. Note that surface control points do not coincide with the surface seam.
Moving control points of a periodic surface does not affect surface smoothness or create any kink.
Polysurfaces
A polysurface consists of two or more (possibly trimmed) NURBS surfaces joined together. Each surface has its own parameterization and u-,v-directions that do not have to match. Polysurfaces and trimmed surfaces are represented using what is called boundary representation (brep for short). It basically describes surface, edge, and vertex geometry with trimming data and relationships among different parts. For example, the brep describes each face, its surrounding edges and trims, normal direction relative to the surface, relationship with neighboring faces and so on. Breps can also be called solids when they are closed or watertight. In the case of following box, it is made out of 6 untrimmed surfaces joined together:
Many polysurfaces are made out of joined trimmed surfaces. The top and bottom faces of the cylinder in the following example are trimmed out of planar surfaces.
39
We saw that editing NURBS curves a surfaces is very intuitive and can be done interactively by moving control points. However, editing polysurfaces and maintain joined edges of different faces is not as intuitive. There are tools that are provided by the 3D NURBS modelers to edit or deform polysurfaces directly, but it is also common to explode a polysurface to its component surfaces, edit those, and then joint back together. In that process, the user must maintain that edges align correctly within tolerance to be able to join successfully. Example Show the steps of create a round hole in a box.
Start with a box and a circle that marks the location and diameter of the hole.
40
Use projection circles to trim top and bottom faces of the box.
Join the trimmed surfaces and the hole wall all together.
41
References
Edward Angel, "Interactive Computer Graphics with OpenGL, Addison Wesley Longman, Inc., 2000. James D Foley, Steven K Feiner, John F Hughes, "Introduction to Computer Graphics" Addison-Wesley Publishing Company, Inc., 1997. James Stewart, "Calculus," Wadsworth, Inc, 1991. Kenneth Hoffman, Ray Kunze, Linear Algabra, Prentice-Hall, Inc., 1971 Rhinoceros help document, Robert McNeel and Associates, 2009.
42