Recently I've been looking at Povray, pyprocessing, and cfdg (version 3.0) as tools for creating digital images. I have branched two separate blogs where I mainly explore jruby + processing and processing.py

Tuesday, 6 January 2009

PVector class

PVector is a potentially useful class for storing 2d and 3d vector data (John Wilson, Ben aka lazydog, and I have all put it to good use), however it seems that I am not the only one that found the original official documentation confusing, see a recent discussion at http://processing.org/discourse/yabb_beta/YaBB.cgi?
(author cbit) I tried to put in a link to the actual discourse but for some reason it failed!!!.

Update 11th March 2009 Dan Shiffman the creator of the PVector class explains its use more clearly in his excellent tutorial, see one of my later blogs, furthermore he has promised to update the processing reference documentation. Darrel has agreed that PVector is worthy of inclusion in the book, and John Wilson has volunteered to write the introduction!!!


PVector was only added in REV 0149, ie on 15 October 2008, so its quite a new addition

Here is just a little example of my exploration (using netbeans ide) of the PVector class. Here I've used it to calculate polar coordinates from Cartesian coordinates (no need for spreadsheet), but it really comes into its own for animations.

   1:public class VectorTest extends PApplet {
2:
3:PVector v1, v2;
4:float a1, r1;
5:
6:
7:public void setup() {
8:
9: v1 = new PVector(0, 1);
10: v2 = new PVector(0, -1);
11: a1 = PVector.angleBetween(v1, v2);
12:
13: assert (a1 == PApplet.PI);
14: System.out.println("theta = " + a1 + " radius = " + v1.mag() );
15: v1.add(v2);
16: assert(v1.mag() == 0.0f);
17: System.out.println(v1);
18:}
19:
20:Output:
21:
22:theta = 3.1415927 radius = 1.0
23:[ 0.0, 0.0, 0.0 ]

No comments:

Post a Comment

Followers

Blog Archive

About Me

My photo
Pembrokeshire, United Kingdom
I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2