Jump to content

  • Log In with Google      Sign In   
  • Create Account

quasar3d

Member Since 01 Dec 2001
Offline Last Active Dec 03 2014 10:44 AM

#5188546 point & Octahedron relationship

Posted by quasar3d on 22 October 2014 - 10:39 AM

If it's a regular octahedron, just take the absolute value of each coordinate, add them, and see if the resulting value is less than a certain threshold (ie. the size of your octahedron). If so, then your point lies inside it, otherwise not.




#5173371 Quaternion angle with itself > 0.001

Posted by quasar3d on 13 August 2014 - 10:58 AM

Hey guys,

I'm in the process of working out my math library, and so I was testing out a function that returns the angle between two quaternions..

{ return 2.0f * acos( Abs( Dot4( qa, qb ) ) ); }

 

.. but for some reason, I'm either getting a lot of floating point error in the result, or I'm not checking for a situation that I should be. While testing a quaternion (which was generated by a random axis+angle rotation and appears to be very close to normalized)..

{ x=0.0172970667 y=-0.0245058369 z=0.0205858145, w=-0.999337912    }

.. with itself, I'm getting a result angle of 0.00138106791 (or almost 0.1 degrees)..

 

I'm just wondering if this is acceptable error when working with float variables? And is there anything I can do to improve this issue other than switching to double type or something else as drastic?

 

edit note: After testing some more, the highest "error angle" I've been able to generate (through random axis-angles) is 0.001953125. And that was getting the angle (from itself) of a quaternion generated by the axis @ angle: { -0.833756,0.551120,-0.033417 @ 2.960138559341 } (quaternion result: { -0.830327,0.548853,-0.033279,0.090603 } )

 

Thank you

 

The reason why the error gets so big, is that the inverse cosine function is very steep around 1. This has the effect that the (even exact) inverse cosine of a dot product which is only a tiny bit off, will give a pretty big angle difference.

 

For example, the cosine of 0.1 degree is 0.99999847691, and so if your dot product would give 0.99999847691 (which is a pretty good approximation of 1), the angle you get will be around 0.1

 

I bet that the reason why, after renormalizing your quaternions, you did get the correct result, was that this gave a dot product of exactly 1, but I don't think this will work for all quaternions. There will certainly be normalized quaternions, which give a dot product with themselves not exactly equal to 1.

 

The good news is that it's only this bad when you're computing the angle between quaternions which are almost parallel. For quaternions which are not nearly parallel, the result will be more accurate.




#5114256 Quaternions and matrices

Posted by quasar3d on 04 December 2013 - 02:44 AM

Another important reason is of course that you usually combine the translation, rotation, and any other transformations into a single matrix which you use to transform your points. So indeed, it's usual to use quaternions while animating, but once you have determined the transformation for a mesh, you create a matrix, and use that matrix to transform its vertices.




#5113366 Homogenous coordinates

Posted by quasar3d on 30 November 2013 - 05:11 PM

An easy way to get a hang of 3D homogeneous coordinates (which consist of 4 coordinates) is to see them as a higher dimension analogue to fractions.
 
- A fraction $a/b$ represents a number on the 1D real axis, but really consists of 2 "coordinates", ie. (a,b). In a similar way, the 3D vector (x/w,y/w,z/w) corresponds to the 4D homogeneous vector (x,y,z,w).
- Just as with fractions, multiplying all components by the same value doesn't change its value, ie. a/b = (sa)/(sb), or in coordinate form (a,b) = (sa,sb), for some scalar s. Similarly, since (x/w,y/w,z/w) = ((sx)/(sw),(sy)/(sw),(sz)/(sw)), the homogeneous vectors (x,y,z,w) and (sx,sy,sz,sw) are considered the same vector. 
 
And then it just so happens that many operations on 3D vectors can be done much more elegantly on their homogeneous representation, most importantly, transformations like translation and projection become representable by just a matrix. Since for a 4x4 matrix a 4D vector and a scalar s, A(sx) = s(Ax), multiplying a homogeneous vector by a matrix is well defined, ie. if two vectors are equivalent (they represent the same 3D point, even while their 4D representation may be different), they will still be equivalent after they're multiplied with a matrix.



#5041813 Cross Product of Many Vectors

Posted by quasar3d on 11 March 2013 - 06:21 AM

This is exactly what least squares solves.




#5017425 Calculating the required rotation.

Posted by quasar3d on 04 January 2013 - 07:34 AM

There's indeed a most natural rotation. It's the one that leaves vectors perpendicular to the plane of A and B invariant.

To derive such a matrix, note that any composition of 2 (or any even number of) reflections is a rotation. With this, you can easily construct a matrix that satisfies your requirements.

Let S_1 be the matrix that reflects A to -A, and let S_2 be the matrix that reflects A + B to -(A + B). The composition S_2 S_1 is then your rotation matrix.

In vectors, reflecting a vector x in a normal vector n is

{eqn} x' = x - 2 n (n \cdot x) {/eqn}

or in matrix notation, where vectors are column vectors

{eqn}
x' = x - n (n^T x)
= (I - n n^T) x
{/eqn}

so your reflection matrix is then {eqn} I - n n^T {/eqn} so your rotation matrix, which rotates a to b

{eqn} R = (I - \frac{(a + b) (a + b)^T}{|a + b|^2)(I + \frac{a a^T}{|a|^2}) {/eqn}

EDIT: Can't get latex to work


#4896536 Math challenge (no particular purpose, prize = a -50% coupon on steam)

Posted by quasar3d on 22 December 2011 - 09:03 AM

Will be nice for my christmas holiday, but I have a suspicion it's an NP problem, so probably won't be very easy.


#4887303 find rectangle around points on plane

Posted by quasar3d on 24 November 2011 - 10:46 AM

The matrix you create is the matrix that maps the xz plane with z = 0 to your original plane (the inverse of the matrix you eventually transform your vertices with). The rotation part of this matrix yields a plane through the origin, parallel to portalPlane. Then to let it map to portalPlane, you have to shift this plane by -portalPlane.w into the direction of its normal. This means that you can simply set the last column of planeMatrix to normal * -portalPlane.w. There's no need to transform this by the rotation part of your matrix, as you are doing now.

Also, right now you do the transpose after you add the translation part, even though you do use the last column instead of the last row for it. To fix this, either add the rotation to the last row, or do the transpose before you add the translation.


#4886910 Fourier transform on image - problem with sharpening filter

Posted by quasar3d on 23 November 2011 - 10:04 AM

And still she's beautiful:)


#4886590 find rectangle around points on plane

Posted by quasar3d on 22 November 2011 - 09:38 AM

Yes, Kryzon gave an explanation how to switch betwen these two spaces.


Kryzon gave an explanation how to switch a space which has the plane with the points aligned on the x,y plane. This doesn't turn the bounding rect into an axis aligned one though.


#4879457 Create a sphere that intersects another at right angles

Posted by quasar3d on 01 November 2011 - 05:27 PM

If the tangent lines make an angle of 90 degrees, than so do the vectors from the centers of the circles to the points where they intersect. Using this it should be pretty easy to solve.


#4870894 Fixed Point vs. Fractional Integers

Posted by quasar3d on 09 October 2011 - 04:44 PM

Aren't these two just the same?


#4851730 LookAt matrix

Posted by quasar3d on 20 August 2011 - 03:28 PM

your matrix takes the camera axes to world space axes, but you actually want to convert from world to camera space, so you have to invert your matrix, which, since your matrix is orthonormal, is just its transpose (the rotation part that is).


#4838001 Converting a polygon into the least number of triangles possible?

Posted by quasar3d on 20 July 2011 - 09:49 AM

http://www.cs.princeton.edu/~chazelle/pubs/polygon-triang.pdf ;)


#4817652 Gödelization - help needed.

Posted by quasar3d on 30 May 2011 - 02:38 PM

You probably know (and as luca-deltadesco explained) that any integer can be factored into a unique prime factorization, and Gödelization is a trick that uses this fact to encode a whole sequence of numbers into a single integer by taking the product of the first prime raised to the power of the first element of your sequence, the second prime raised to the power of the second element, and so on. This gives you a single integer that encodes your whole sequence.

for example, the sequence of the first 4 squares (1,4,9,16) can be encoded as

2^1 * 3^4 * 5^9 * 7^16 = 10515106938037816406250




PARTNERS