rotate a plane around a diagonal - graphics

I would like to rotate a plane, not around a single (X or Y) axis, but around the diagonal (45 degrees between X and Y). How do I calculate the Rx and Ry given the Rdiagonal?
(Rdiagonal is the amount of rotation I would like to achieve around the diagonal axis).
To clarify: just take a yellow PostIt and draw cross on it (a horizonal and a vertical line). These are the X and Y axes. Rotating around these axes is easy (assuming you can just specify Rx and Ry). But I would like to rotate around the diagonal axis. What are the Rx and Ry in that case?
I think it's something like Rx = Rdiagonal / sqrt(2). But I'm not sure.

This is probably more of a mathoverflow question, but I found some information here about rotation around an arbitrary axis. It provides the derivation for the translation and rotation matrices.

Your plane will most certainly given by some points (depending on the dimensionality). You can then use a rotation matrix to transform these points: new = R * old. Afterwards, construct your plane from these points.
To get the right rotation matrix, see the entry at wikipedia.

Related

In geometry nodes how can I align instances to both a curve and ground plane?

Given this simple setup:
Node Tree
Viewport Preview
How can I align the planes instances such that the y axis of each plane is parallel to the curve, and the x axis of the planes are parallel to the ground plane (x and Y axis)?
I've tried various combinations with "Align Eular to Vector" node, but as soon as the curve does not face a specific axis the planes get tilted and the alignment to ground plane is lost.
any suggestions?
So after some research I found a solution to my own question. I'm posting it in case anyone else needs to find this out.
Note that I'm not a mathematician and there might be a shorter solution (or specific nodes that I'm not aware of that can perform some of the steps). Also note that this is a solution for instances on a straight line which is what I was aiming for, I didn't test this setup on a curved line but my guess is that it will not work.
For that you'll need to perform step 3 for every point or something like that.
Ok here we go:
Generate instances on a line with the instance on point node.
Auto orient the instances on the z axis with the align Euler to vector node based on the normal of the line.
Calculate a vector between 2 points on the line (which point is not important since the line is straight but the order of the subtraction does!). To calculate the vector from point 1 to point 2 you'll have to subtract point 1 from point 2 (like so: point 2 - point 1).
Calculate the angle between the new vector and the vector of the ground plane [0,0,1]. to do that use this formula:
θ = arccosine ( dot product/ ( length(v1) * length(v2) ) ).
Calculate the complementary angle which is 90 degrees - θ
*** convert 90 to radians of course
rotate the instances on x axis by the result value.
Node Tree
Result
If there is a shorter/easier solution, let me know.

Why quaternion is defined by [vector,w] why not by [point,w]?

A quaternion rotation defines a point in 3d-space and rotation around the axis of that point.
I am trying to understand why quaternion rotation requires a vector and rotation, why not just a 3d point in space and rotation ?
eg : In the following picture a hand points to a point in 3d-space which can be rotated around its axis.
http://s29.postimg.org/ih79tirnr/quarternion.jpg
Thanks
Actually, the x, y and z components of a quaternion define a vector pointing in the direction of the axis of rotation. The w component defines the amount of the rotation along that axis. So, the x, y and z don't actually signify a point at all. As the amount of rotation changes, the length of the x, y, z vector will change but the vector always points in the same direction. It doesn't make sense, therefore, to consider this to be a point in space. It's merely a direction and a rotation around that axis.
I once defined a new class that included a quaternion to define the transformation of an object along with a vector to describe the translation of the object. The object could then represent a complete transformation in 3D space similar to a 3x4 transformation matrix.

2D Rotation Orientation

I'm trying to make sense of all the ways I can use the Rotation matrix (sorry for unreadability):
R(x) = [ cos(x) -sin(x) ; sin(x) cos(x) ]
There are two types of coordinate systems (CS) that you can have:
CS1 --> positive x-axis going right and positive y-axis going up which is apparently the standard orientation people use.
CS2 --> positive x-axis going right and positive y-axis going down.
What I'm confused with is the sign of angle x when plugged into R(x). Depending on the sign of the numerical, the angle either makes a counter-clockwise or clockwise rotation (on an arbitrary vector) but for which CS orientation and how would the other orientation behave?
Also, if you could explain a bit more than what wikipedia has on alibi and alias transformations, that would be great. Which would be best to think of rotations in? If I think in the alias approach, would I have to use the opposite sign for angle x.
This is what I'm referring to:
http://en.wikipedia.org/wiki/Rotation_matrix#Ambiguities
Thanks!
Would this be right...
Making use of R(x).
The vector undergoes a counter clockwise rotation of 'x' in CS1 (alibi). This relates to a clockwise rotation of CS1 of an angle 'x' (with the vector now having new coordinates). If x is negative then counter-clockwise becomes clockwise (alibi) and clockwise becomes counter-clockwise (alias)
If we were to use CS2...the above can be taken but with again swapping counter-clockwise with clockwise and vice versa.
In standard cartesian coordinates (what you've called "CS1") that matrix will cause a counter clockwise rotation to the vector (i.e. "alibi")
In the inverted Y axis case it'll be clockwise.

z-value of a projected 3d point

After a 3d point has been transformed by a perspective projection matrix, what do the Z coordinate stand for? Distance from the 'eye'? Distance from the near clip plane? None of this?
Edit
I've set up a matrix using the glFustrum definition found here.
Then, I transform a 3D point with that matrix.
I'm left with a 3D point where X and Y are the coordinates of the point on the near frustum face, and Z, supposedly a depth information that I have a hard time exploiting.
Thanks!
The transformed z (that you use as denominator for dividing x and y) is the distance from the eye in the perpendicular direction to the projection plane, scaled so that the projection plane is at distance 1.
It's been a while for me, but if you have the X and Y coordinates on the frustrum, does not the Z control the layer order?

How to optimally plot parametric continuous curve?

Let's say we have a parametric curve, for example a circle:
x = r * cos(t)
y = r * sin(t)
We want to plot the curve on the screen in a way that:
every pixel is painted just once (the optimal part)
there is a painted pixel for each (x, y) that lies on the curve (the continuous part)
If we just plot (x, y) for each t in [t1, t2], these conditions will not be met.
I am searching for a general solution for any parametric curve.
A general solution that 100% satisfies your criteria does not exist.
So we have to compromize.
Usually this is tackled by starting with a stepsize (usually a parameter to your routine), this stepsize can be subdivided triggered by a heuristic e.g.:
subdivide when the distance covered by a segment is larger than a given distance (e.g. one pixel)
subdivide when the curve direction changes too much
Or a combination of these.
Usually some limit to subdivision is also given to avoid taking forever.
Many systems that offer parametric plotting start with some changeable default setting for the heuristic params and step size. The user can adapt these if the curve is not "nice" enough or if it takes too long.
The problem is that there are always pathological curves that will defeat your method of drawing making it miss details or taking overly long.
Check out Bézier splines.

Resources