What is the target field in fromAngle() in PVector?

Hi! I was looking at the fromAngle documentation and saw this: .fromAngle(angle, target)

What is target here? Does that mean I can do this

PVector p;
PVector.fromAngle(90, p);

Will this mean the new vector is in p?

Is this the same as doing

PVector p = PVector.fromAngle(90);
1 Like

PVector methods with an optional target parameter signature allow us to pass an already existing PVector object so the method use that rather than internally instantiating a new PVector.


so it sets the passed in vector to the new one?

So say I have a loop where the vector is updating. would it be good to do this for instance

PVector p = new PVector(1,1);
for (a = 0; a < 360; a ++){
   PVector.fromAngle(a, p);
  // do do something with p

So is this updating the p vector?

1 Like

Yes, the PVector p receives the result of fromAngle() and no additional PVector is created.

I tried something and that seems to be what it is doing. Thank you!