Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
PVector vec1 = new PVector(1,2);
PVector vec2 = new PVector(3,4);
 
// read out components of vec1 
println(vec1.x);
println(vec1.y);
println(vec1.z);
 
println(vec1);
println(vec2);
 
// set new components of vector
vec1.set(10,20);
println(vec1);
 
// vector addition when creating a new vector
println("-- Vec Add --");
PVector resVec = PVector.add(vec1,vec2);
println(resVec);
 
// adding a vector to an existing vector  
vec1.add(vec2);
println(vec1);
 
// vector subtraction  
println("-- Vec Sub --");
resVec = PVector.sub(vec1,vec2);
println(resVec);
 
vec1.sub(vec2);
println(vec1);
 
// vector multiplication   
println("-- Vec Mult --");
resVec = PVector.mult(vec1,2);
println(resVec);
 
vec1.mult(2);
println(vec1);
 
// find vector magnitude    
println("-- Vec Length --");
println(vec1.mag());
 
// find angle between two vectors    
println("-- Vec Angle Between --");
println(degrees(PVector.angleBetween(vec1, vec2)));
 
// normalise a vector    
println("-- Vec NormalizeNormalise --");
vec1.normalize();
println(vec1);
println(vec1.mag());