RhinoScript101 by David Rutten

Page 41

6.2 Points and Vectors In RhinoScript, coordinates are defined as arrays of three numbers. Element 0 corresponds with x, element 1 with y and element 2 with z. This notation is used for both points and vectors. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

Sub PointSpiral() Dim arrPoint(2) Dim t, pi pi = Rhino.Pi()

Rhino Viewport

Point = Array(-1.84, 4.59, 4.95) Point = Array(-1.27, 4.81, 4.98) Point = Array(-0.66, 4.96, 5.00)

'Call Rhino.EnableRedraw(False) For t = -5 To 5 Step 0.025 arrPoint(0) = t * Sin(5*t) arrPoint(1) = t * Cos(5*t) arrPoint(2) = t Call Rhino.Print(Rhino.Pt2Str(arrPoint, 3)) Call Rhino.AddPoint(arrPoint) Next 'Call Rhino.EnableRedraw(True) End Sub

The variable arrPoint is declared as a fixed size array on line 2 and the elements are assigned different values on lines 9 to 11 inside the body of the loop. On line 13 the array is converted to a String using the RhinoScript method Rhino.Pt2Str(). Pt2Str and Str2Pt (abbreviations for PointToString and StringToPoint respectively) can be used to convert points into Strings and vice versa. The regular VBScript function CStr() for casting variables into Strings will not work on arrays and cannot be used. The additional benefit of Pt2Str is that it takes optional formatting arguments. Vectors are a new concept in RhinoScript for Rhino4. Those of you who are familiar with the essentials of geometrical mathematics will have no problems with this concept... in fact you probably all are familiar with the essentials of geometrical mathematics or you wouldn't be learning how to program a 3D CAD platform.

Rhino Viewport

(3.0, 2.0, 2.5) 2.5 t 3.0

2.0 (3.0, 2.0, 2.5)

Vectors are indistinguishable from points. That is, they are 2.5 -3.0 both arrays of three doubles so there's absolutely no way of -4.0 2.0 3.0 telling whether a certain array represents a point or a vector. There is a practical difference though; points are absolute, -3.5 vectors are relative. When we treat an array of three doubles (-3.0, -4.0,-3.5) as a point it represents a certain coordinate in space, when we treat it as a vector it represents a certain direction. You see, a vector is an arrow in space which always starts at the world origin (0.0, 0.0, 0.0) and ends at the specified coordinate. The picture on the right shows two vector definitions; a purple and a blue one. The blue one happens to have all positive components while the purple one has only negative components. Both vectors have a different direction and a different length. When I say vectors are relative, I mean that they only indicate the difference between the start and end points of the arrow, i.e. vectors are not actual geometrical entities, they are only information. The blue vector could represent the tangent direction of the black curve at parameter {t}. If we also know the point value of the curve at parameter {t}, we know what the tangent of the curve looks like; we know where in space the tangent belongs. The vector itself does not contain this information; the orange and the blue vector are identical in every respect. The addition of vector definitions in RhinoScript is accompanied by a whole group of point/vector related methods which perform the basic operations of 'vector mathematics'. Addition, subtraction, multiplication, dot and cross products and so on and so forth. The table on the following page is meant as a reference table, do not waste your time memorizing it.

37


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.