Quadratic Interpolation of Quaternions (SQUAD) - animation

I have four keyframes in an animation, f0, f1, f2, f3, and I am trying to interpolate a rotation of a frame f located sometime between f1 and f2 at t = (f-f1)/(f2-f1).
My question is, can I do a quadratic interpolation between the keyframes to find the rotation? I want to use all four keyframes. I also would like it to be C1 continuous across keyframes.
I have looked into SQUAD and Catmull-Rom Splines, but I'm still a little hesitant to implement them because I'm not sure what exactly the formulas should look like. SQUAD tells how to interpolate between a series of rotations, I am unsure about how to apply it to just four. Thanks in advance!

Unfortunately, quaternions don't live in a linear space, so interpolation between them is a bit tricky, as you found out already.
I assume you want to use a weighted average, in the same way you would compute a curve in 3D space.
First of all, an exact spherical interpolation (SLERP) of more than two quaternions is not defined. This is because their combinations is described using multiplication, and their multiplication is non-commutative (apart from other reasons). So you will have to make use of an approximate solution, as every other animation software :-)
SQUAD (aka Shoemake's Quaternion curves) are one possibility, or even fancier (and more accurate) optimization-based generalized quaternion interpolation. However, in practice I always made use of NLERP (normalized linear interpolation, described for example here), which gives good results if the interpolated quaternions are reasonably close (difference of about 60 to 90 degrees is still fine) while being very simple and fast. A nice simple article with 3D vector examples that shows the difference between these is here.
Personally, I always go back to Geometric Tools' Quaternion Algebra and Calculus notes, which have an extremely concise description of both theoretical and practical aspects of quaternions in CG.
And don't forget about antipodality, by far the most common problem when implementing quaternion interpolation :)

Related

Why is it difficult to use Quaternions for the LBS(Linear Blend Skinning) formula?

Why would be difficult to use quaternions for the LBS(Linear Blend Skinning) formula?:
See picture:
Linear Blend Skinning Formula
P': Point transformed
P: Point
wi: matrix of weights
wi(P): weight of point P in entry i
Ti: Transform at i
I couldn't really find an answer, I thought that maybe because a transform matrix can store 4x4 values rather than quaternions which can only represent a rotation in 4 values then we wouldn't have a way to represent both a translation and rotation for any bone using a quaternion but I'm not too sure.
You are absolutely right. The fact that quaternions can only represent rotations (and scalings) makes them unusable for this task. There are extensions to quaternions (dual quaternions) that circumvent this restriction. And then, blending linearly works pretty well.
Also, keep in mind how to transform a point with a quaternion - you have two multiplications instead of one. Therefore, you would usually first blend the quaternions and then transform the point. Although blending the transformed points can be done as well, this makes little sense as it is computational heavier and has the same problems as simple LBS.
Whether or not the question aims at something more is still open.

What is the most performant way to do ray-tracing with a surface whose formula is known?

Ray-tracing with meshes of triangles has widely known solutions and a plenty of resources. There is a related problem which involves ray-tracing for surfaces with known parametric formulas, such as:
S(u,v) = (cos(u), sin(u), v)
Which represents an unit cylinder aligned to the Z axis. My question is: what is the most efficient way to apply ray tracing to that kind of surface? An obvious solution would be to generate approximate meshes from the formulas and then applying the ray tracing, but my question is if there is a best suited solution for this particular case - specifically by applying some kind of on-demand polynomial solver.
When you mention polynomial solver, this sounds like you'd base things on the implicit algebraic description of the surface. So in your situation, you would get rid of the trigonometric functions using the tangent half-angle substitution:
((1-u^2)/(1+u^2), 2*u/(1+u^2), v)
Then you'd turn this into a set of polynomial equations in x,y,z:
(1-u^2)/(1+u^2) - x = 0
2*u/(1+u^2) - y = 0
v - z = 0
You could eliminate u and v from these equations, e.g. using resultants.
You'd end up with
x^2 + y^2 - 1 == 0
which comes at no surprise, since that's your cylinder. But the approach above would work for other parametrized surfaces as well. Then you could take your ray of light and, assuming the origin is the camera lens, write a point on that ray as λd where d is the direction of the ray. Plug that point into the equation, solve for λ, find the smallest positive solution and you've got your point where the ray intersects the surface. Furthermore, compute the gradient of the implicit equation at that point and you've got the surface normal as well.
I don't know how far this approach is actually used in practice. Afair most ray tracers are mesh-based for most operations except the most simple of geometric primitives, but this might be outdated information. It would certainly sound a worthwhile approach if you want to avoid CPU-heavy mesh creation and replace it by GPU-heavy high-quality computations of the actual surface.
There are tools, like Surfer and its descendants, which have visualizing algebraic surfaces described by implicit equations as their sole purpose. They tend to do a lot of fancy stuff, particularly to deal well with singularities like very thin spikes protruding from such a surface. I've used this tool myself e.g. to illustrate this answer. Surfer doesn't have a complex reflection and lighting model, though, so it only does ray casting.

What "boundary conditions" can make a rectangle "look" like a circle?

I am solving a fourth order non-linear partial differential equation in time and space (t, x) on a square domain with periodic or free boundary conditions with MATHEMATICA.
WITHOUT using conformal mapping, what boundary conditions at the edge or corner could I use to make the square domain "seem" like a circular domain for my non-linear partial differential equation which is cartesian?
The options I would NOT like to use are:
Conformal mapping
changing my equation to polar/cylindrical coordinates?
This is something I am pursuing purely out of interest just in case someone screams bloody murder if misconstrued as a homework problem! :P
That question was asked on the time people found out that the world was spherical. They wanted to make rectangular maps of the surface of the world...
It is not possible.
The reason why is not possible is because the sphere has an intrinsic curvature, while the cube/parallelepiped has not. It can be shown that for two elements with different intrinsic curvatures, their surfaces cannot be mapped while either keeping constant infinitesimal distances, either the distance between two points is given by the euclidean distance.
The easiest way to understand this problem is to pick some rectangular piece of paper and try to make a sphere of it without locally stretch it or compress it (you can fold). You can't. On the other hand, you can make a cylinder surface, because the cylinder has also no intrinsic curvature.
In maps, normally people use one of the two options:
approximate the local surface of the sphere by a tangent plane and make a rectangle out of it. (a local map of some region)
make world maps but implement some curved lines everywhere identifying that the measuring distances must be made according to those lines.
This is also the main reason why when traveling from Europe to North America the airplanes seems to make a curve always trying to pass near canada. If we measured the distance from the rectangular map, we see that they should go on a strait line to minimize the distance. However, because we are mapping two different intrinsic curvatures, the real distance must be measured in a different way (and not via a strait line).
For 2D (in fact for nD) the same reasoning applies.

Continuous Physics Engine's Collision Detection Techniques

I'm working on a purely continuous physics engine, and I need to choose algorithms for broad and narrow phase collision detection. "Purely continuous" means I never do intersection tests, but instead want to find ways to catch every collision before it happens, and put each into "planned collisions" stack that is ordered by TOI.
Broad Phase
The only continuous broad-phase method I can think of is encasing each body in a circle and testing if each circle will ever overlap another. This seems horribly inefficient however, and lacks any culling.
I have no idea what continuous analogs might exist for today's discrete collision culling methods such as quad-trees either. How might I go about preventing inappropriate and pointless broad test's such as a discrete engine does?
Narrow Phase
I've managed to adapt the narrow SAT to a continuous check rather than discrete, but I'm sure there's other better algorithms out there in papers or sites you guys might have come across.
What various fast or accurate algorithm's do you suggest I use and what are the advantages / disatvantages of each?
Final Note:
I say techniques and not algorithms because I have not yet decided on how I will store different polygons which might be concave, convex, round, or even have holes. I plan to make a decision on this based on what the algorithm requires (for instance if I choose an algorithm that breaks down a polygon into triangles or convex shapes I will simply store the polygon data in this form).
You said circles, so I'm assuming you have 2D objects. You could extend your 2D object (or their bounding shapes) into 3D by adding a time dimension, and then you can use the normal techniques for checking for static collisions among a set of 3D objects.
For example, if you have a circle in (x, y) moving to the right (+x) with constant velocity, then, when you extend that with a time dimension, you have a diagonal cylinder in (x, y, t). By doing intersections between these 3D objects (just treat time as z), you can see if two objects will ever intersect. If point P is a point of intersection, then you know the time of that intersection simply by looking at P.t.
This generalizes into higher dimensions, too, though the math gets hard (for me anyway).
The collision detection might be tricky if objects have complex paths. For example, if your circle is influenced by gravity, then the extruded space-time object is a parabolic sphere sweep rather than a simple cylinder. You could pad the bounding objects a bit and use linear approximations over shorter periods of time and iterate, but I'm not sure if that violates what you mean by continuous.
I am going to assume you want things like gravity or other conservative forces in your simulation. If that's the case the trajectories of your objects are most likely not going to be lines, in which case, just like Adrian pointed out, the math will be somewhat harder. I can't think of a way to avoid checking all possible combinations of curves for collisions, but you can calculate the minimum distance between two curves rather easily, as long as both are solutions to linear systems (or, in general, if you have a closed form solution for the curves). If you know that x1(t) = f(t) and x2(t) = g(t) then what you'll want to
do is calculate the distance ||x1(t) - x2(t)|| and set its derivative to zero. This should be an expression that depends on f(t), g(t) and their derivatives and will give you a time tmin (or maybe a few possible ones) at which you then evaluate the distance and check to see if it is greater or smaller than r1+r2 --- the sum of the radii of the two bounding circles. If it is smaller, then you have a potential collision at that time so you run the narrow phase algorithm.

Quaternions and Transform Matrices

Tell me if I am wrong.
I'm starting using quaternions. Using a rotation matrix 4 x 4 (as used in OpenGL), I can compute model view matrix multiplying the current model view with a rotation matrix. The rotation matrix is derived from the quaternion.
The quaternion is a direction vector (even not normalized) and a rotation angle. Resulted rotation is dependent on the direction vector module and the w quaternion component.
But why I should use quaternions instead of Euler axis/angle notation? The latter is simpler to visualize and to manage...
All information that I found could be synthetized with this beatifull article:
http://en.wikipedia.org/wiki/Rotation_representation
Why it is better to use quaternions is explained in the article.
More compact than the DCM representation and less susceptible to round-off errors
The quaternion elements vary continuously over the unit sphere in R4, (denoted by S3) as the orientation changes, avoiding discontinuous jumps (inherent to three-dimensional parameterizations), this is often referred to as gimbal lock.
Expression of the DCM in terms of quaternion parameters involves no trigonometric functions
It is simple to combine two individual rotations represented as quaternions using a quaternion product
Unlike Euler angles, quaternions don't suffer from gimbal lock.
I disagree that quaternions are easier to visualize, but the main reason for using them is that it's easy to concatenate rotations without "matrix creep".
Quaternions are generally used for calculative simplicity - it's a lot easier (and faster) to do things like composing transformations when using quaternions. To quote the Wikipedia page you linked,
Combining two successive rotations,
each represented by an Euler axis and
angle, is not straightforward, and in
fact does not satisfy the law of
vector addition, which shows that
finite rotations are not really
vectors at all. It is best to employ
the direction cosine matrix (DCM), or
tensor, or quaternion notation,
calculate the product, and then
convert back to Euler axis and angle.
They also do not suffer from a problem common to axis/angle form, gimbal lock.
Quaternions are easier to visualize, manage and create in scenarios where you want to rotate about a particular axis that can be easily calculated. Determining a single rotation angle is much easier than decomposing a rotation into multiple angles.
Corrections to the OP: the vector represents the axis of rotation, not a direction, and the rotation component is the cosine of the half-angle, not the angle itself.
As mentioned, quaternions don't suffer from gimble lock.
For a given rotation, there is exactly one normalized quaternion representation.
There can be several seemingly unrelated axis/angle values that result in the same rotation.
Quaternion rotations can be easily combined.
It is extraordinarily complex to calculate an axis/angle notation that is the cumulation of two other axis/angle rotations.
Floating point numbers have a higher degree of accuracy when representing values between 0.0 and 1.0.
The short answer is that axis/angle notation can initially seem like the most reasonable representation, but in practice quaternions alleviate many problems that axis/angle notation presents.

Resources