exercise.01_points in motion


Exercise: Points in Motion


Make sure you understand the section on 1-D Arrays, iteration and points. This exercise will help you think how to go about calculating the coordinates of each points in ways that describe interesting shapes. According to wikipedia, for instance, the set of points on a circle can be defined parametrically with the following equations:

and the circumference itself is defined by
Where 'a' and 'b' are the X and Y coordinates of the circle's center. With this in mind we can tell RhinoScript to plot a circle using the following code.

Dim radius : radius = 10.0
Dim x, y, z, theta
For theta = 0 to Rhino.Pi()*2 Step 0.1
    x = cos(theta)*radius
    y = sin(theta)*radius
    z = 0
    Rhino.AddPoint array(x,y,z)
Next

This block of code features a couple of new things; first, we are using the Rhino.Pi() method, which returns a constant value for Pi. Second, the For loop declaration includes a 'Step', which defines the increments of the variable theta in each loop. If the concept of methods confuses you it may be useful to revise the Functions section. The code above plots something like:



 If we change the value of Z in the for loop we may start plotting interesting drawings in 3-D space. The following image shows two sets of points spiraling up in the Z axis.



The following code plots two sets of points spiraling up. Notice how the information of the points is stored in two arrays (points1 and points 2). This is important since these "addresses" are the arguments taken by the Rhino.AddCurve method. For a review of the concept of functions check here.

Dim radius : radius = 10.0
Dim x, y, z, theta
ReDim points1(62)
ReDim points2(62)
Dim thispoint1, thispoint2
For theta = 0 To Rhino.Pi()*2 Step 0.1
 'Rhino.Print (theta*10)
 x = Cos(theta)*radius
 y = Sin(theta)*radius
 z = theta*4
 points1(theta*10) = Array(x,y,z)
Next
radius = 2.0
For theta = 0 To Rhino.Pi()*2 Step 0.1
 x = Cos(theta)*radius
 y = Sin(theta)*radius
 z = theta*4
 points2(theta*10) = Array(x,y,z)
Next
Dim i
For i = 0 To 62
 If IsArray(points1(i)) Then
  Rhino.Print "Is Array"
 Else
  Rhino.Print "Not Array"
 End If
 Rhino.AddPoint points1(i)
 Rhino.AddPoint points2(i)
 Rhino.AddCurve array( points1(i), points2(i) )
Next

Problem 1

 
Make sure you understand the code above, take some time and change the variables. What would you need to change in order to make the two spiraling sets of points to be "out of phase"? Can the points be connected differently? What happens if you use a trigonometric function for the Z coordinate? What happens if instead of iterating to Rhino.Pi()*2 you do so to Rhino.Pi()*4? Modify the code and experiment with different parameter values.

Problem 2


Take a mathematically-defined geometric shape (different from the circle) and implement it in RhinoScript using the control flow and data structure we have used so far: For Loops and Arrays. Use the references as sources of material and inspiration. Use only points and lines. If you need a reference for logical operators and mathematical notation check here.

Other Materials and References

Mathematical Alchemy
Here you will find scripts for describing this and other geometric shapes.


Archimedean Spirals
http://en.wiki.mcneel.com/default.aspx/McNeel/RsArchimedeanSpiral.html


Categories

Configure Widgets