# I want the PVector after rotate

**URL:** <https://discourse.processing.org/t/i-want-the-pvector-after-rotate/30744>\
**Category:** Coding Questions\
**Created:** [June 16, 2021, 5:48pm UTC](https://discourse.processing.org/t/i-want-the-pvector-after-rotate/30744 "2021-06-16T17:48:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![zang](https://avatars.discourse-cdn.com/v4/letter/z/bc8723/32.png) [@zang](https://discourse.processing.org/u/zang)\
**Post date:** [June 16, 2021, 5:48pm UTC](https://discourse.processing.org/t/i-want-the-pvector-after-rotate/30744/1 "2021-06-16T17:48:55Z")

</div>

```auto
PVector v = new PVector();

void setup() {

  size(800, 800, P3D);
}

void draw() {
  background(255);
  push();  
  
  translate(0,0,0);
  v = new PVector(1, 10, 1);
  rotateZ(frameCount);
  pop();
  println(v);
}

```

i want to know the value of pvector v after rotate but it seems like something wrong.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 16, 2021, 7:50pm UTC](https://discourse.processing.org/t/i-want-the-pvector-after-rotate/30744/2 "2021-06-16T19:50:00Z")

</div>

Hello,

Look here and you will find the answer:  
[https://processing.org/tutorials/pvector/](https://processing.org/tutorials/pvector/)  
[https://processing.org/tutorials/transform2d/](https://processing.org/tutorials/transform2d/)  
[https://processing.org/reference/PVector.html](https://processing.org/reference/PVector.html)  
[https://processing.org/reference/draw\_.html](https://processing.org/reference/draw_.html)  
[https://processing.org/reference/rotate\_.html](https://processing.org/reference/rotate_.html)  
[https://processing.org/reference/frameRate\_.html](https://processing.org/reference/frameRate_.html)

Angles are measured in radians so you are rotating frameCount \* 1 rad (around 57 deg.) every frame which is every 1/60 of a second.

In your case you are creating a new PVector each frame in draw() and rotating the co-ordinate system and repeating this 60 times a second.

There is a big difference between rotating a PVector and transforming the co-ordinate system which does not change the PVector!

The tutorial and references may help you.

Another nice resource:  
[https://natureofcode.com/book/chapter-1-vectors/](https://natureofcode.com/book/chapter-1-vectors/)

Example:

```auto
PVector v = new PVector();

// setup() runs only once!
void setup() 
  {
  v = new PVector(1, 10, 1);
  println(v);
  rotate(TAU/6);
  println(v);
  v.rotate(TAU/6);
  println(v);
  }

```

You can look up TAU in the references.

PVectors can be a challenge at first… work through the tutorials and examples.

Example of using frameCount to generate angles:

```auto
void setup() {
}

void draw() {
  float angle = frameCount*(TAU/60); //TAU rad/sec = TWO_PI rad/sec = 360 deg/sec
  println(angle, degrees(angle));
}

```

`:)`

---

<div class="post-metadata">

**Author:** ![zang](https://avatars.discourse-cdn.com/v4/letter/z/bc8723/32.png) [@zang](https://discourse.processing.org/u/zang)\
**Post date:** [June 17, 2021, 10:31am UTC](https://discourse.processing.org/t/i-want-the-pvector-after-rotate/30744/3 "2021-06-17T10:31:10Z")

</div>

thanks ， i use gyro to react with processing and it gives me a quaternion rotate,  
it will rotate the cube but i dont know the acurrat rotate angle .

it s so comlex ,so i wander if i could get position in a easier way .  
pvector.rotate(4 parameters);it wont work but still thanks a lot.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 17, 2021, 10:40am UTC](https://discourse.processing.org/t/i-want-the-pvector-after-rotate/30744/4 "2021-06-17T10:40:50Z")

</div>

Hello,

> [@zang](#):
>
> pvector.rotate(4 parameters);it wont work but still thanks a lot.

You need to go through the tutorials and references.

I did a project with the BNO055 and used quaternions:  
[https://discourse.processing.org/t/quaternions-and-euler-rotations-exploration/11262/1](https://discourse.processing.org/t/quaternions-and-euler-rotations-exploration/11262/1)

This took some time, energy, research, perseverance and enthusiasm to code and I finally got there.

_I am no longer sharing the code for this._

This was a useful resource for conversions:  
[https://www.euclideanspace.com/maths/geometry/rotations/conversions/index.htm](https://www.euclideanspace.com/maths/geometry/rotations/conversions/index.htm)

There are many examples on the Internet of such conversions and examples for these devices.

`:)`

---

<div class="post-metadata">

**Author:** ![zang](https://avatars.discourse-cdn.com/v4/letter/z/bc8723/32.png) [@zang](https://discourse.processing.org/u/zang)\
**Post date:** [June 17, 2021, 10:50am UTC](https://discourse.processing.org/t/i-want-the-pvector-after-rotate/30744/5 "2021-06-17T10:50:14Z")

</div>

you are so so so nice guy 🥰

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 17, 2021, 11:24am UTC](https://discourse.processing.org/t/i-want-the-pvector-after-rotate/30744/6 "2021-06-17T11:24:10Z")

</div>

In my opinion you can also use normal way:

```auto
translate 
rotateX
rotateY
rotateZ
translate
and then use modelX(),modelY(),modelZ() e.g. 
      PVector myPV = new PVector(modelX(0,0,0),modelY(0,0,0),modelZ(0,0,0) ); 

```

to get the resulting point (PVector)

(not tested)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 25, 2021, 10:55am UTC](https://discourse.processing.org/t/i-want-the-pvector-after-rotate/30744/7 "2021-06-25T10:55:24Z")

</div>

here is an example

```auto

// https://discourse.processing.org/t/i-want-the-pvector-after-rotate/30744

import peasy.*;

PeasyCam pCamera;

ArrayList<PVector> list = new ArrayList(); 

PVector v = new PVector();

PVector center, 
  myPV, myPV2;

void setup() {
  size(800, 800, P3D);

  center = new PVector(0, 0, 0);

  pCamera = new PeasyCam(this, 300);

  v = new PVector(40, 0, 0);

  // -------

  translateAndAddToList(v); 

  spherePV(v, 18);

  makeCircle(v); 

  rotateX(radians(90));
  makeCircle(v); 

  rotateY(radians(33));
  makeCircle(v); 

  // -------
}

void draw() {
  background(255);
  lights();

  spherePV(center, 4);

  for (PVector pv : list) {
    spherePV(pv, 9);
  }
}

//--------------------------------------------------------------------------------------

void makeCircle(PVector pv) {
  for (int i = 3; i<360; i+=17) { 
    pushMatrix();  

    rotateZ(radians(i));
    // spherePV(v, 9);

    translateAndAddToList(pv); 

    popMatrix();
  }//for
}
//--------------------------------------------------------------------------------------

void translateAndAddToList(PVector pv) {
  pushMatrix();  
  translatePV(pv); 
  PVector myPV = new PVector(modelX(0, 0, 0), modelY(0, 0, 0), modelZ(0, 0, 0) );
  list.add(myPV); 
  popMatrix();
}

void translatePV(PVector pv) {
  // one nice wrapper for build in translate-command
  translate(pv.x, pv.y, pv.z);
}

void spherePV(PVector pv, 
  float size1) {
  // one nice wrapper for build in sphere-command
  pushMatrix();
  noStroke(); 
  fill(255, 0, 0); 
  translate(pv.x, pv.y, pv.z);
  sphere(size1);
  popMatrix();
}

```
