zang
June 16, 2021, 5:48pm
1
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.
glv
June 16, 2021, 7:50pm
2
Hello,
Look here and you will find the answer:
https://processing.org/tutorials/pvector/
https://processing.org/tutorials/transform2d/
https://processing.org/reference/PVector.html
https://processing.org/reference/draw_.html
https://processing.org/reference/rotate_.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/
Example:
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:
void setup() {
}
void draw() {
float angle = frameCount*(TAU/60); //TAU rad/sec = TWO_PI rad/sec = 360 deg/sec
println(angle, degrees(angle));
}
:)
1 Like
zang
June 17, 2021, 10:31am
3
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.
glv
June 17, 2021, 10:40am
4
Hello,
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
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
There are many examples on the Internet of such conversions and examples for these devices.
:)
1 Like
zang
June 17, 2021, 10:50am
5
you are so so so nice guy
In my opinion you can also use normal way:
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)
here is an example
// 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();
}