I guess this is more math than Processing per se but here goes…
The 2D plane exists in 3D space and can rotate in any direction about the origin (from gyro data).
How can I find the vector shown in blue that always points closest to world space “down” along the surface of the place?
IE if the plane was perfectly flat the vector would be [0,0,0] and if it was rotated 90 degrees like a wall, the vector would be [0,-1,0]
If I understand well, your plane constitutes the x and z-axis, and you want to rotate the y axis?
But then you’ll have to compare it to a reference direction, and I suppose I have to imagine it as if it were an axis perpendicular to the earth’s horizon. To calculate the vector then, I need the angle between the vertical and the rotated plane and use some math.
PVector x = new PVector(1, 0);
PVector y = new PVector(0, 1);
float angle = PVector.angleBetween(x, y);
println(degrees(angle)); // 90 degrees
I asked a similar question on stack exchange and got a good answer. Is this what you’re looking for?