Thread: Quaternions
View Single Post
  #8  
Old 06-17-2008, 10:13 AM
roman_suvorov roman_suvorov is offline
Member
 
Join Date: May 2008
Location: Kingston, ON, Canada
Posts: 25
Question

Quote:
Originally Posted by farshizzo View Post
Now you're dealing with non-normalized quaternions, so all bets are off.
Do you then know by any chance what course of action does Vizard take if you try to set an object's quaternion to [x,y,z,w] such that x^2+y^2+z^2+w^2 > 1?
For example, add this function definition to my previous code:
Code:
# Normalizes the passed quaternion (which is assumed to have the form
# [x,y,z,w]) so that the vector [x,y,z,w] has unit length.
# Note: normalization is done in place (i.e., the correct way
# of calling this function is 'normalizeQuat(q1)' rather than 'q1 = normalizeQuat(q2)'.
def normalizeQuat (quat):
	i = 0
	normFactor = 0
	while (i < len(quat)):
		normFactor += quat[i]**2
		i += 1
	normFactor = normFactor**0.5

	i = 0
	while (i < len(quat)):
		quat[i] /= normFactor
		i += 1
Now if you normalize quat [0,1,0,-1] we get the same MainView orientation as with the unnormalized quaternion. Is this behavior expected? Does a function similar to my 'normalizeQuat' get called in Vizard behind the scenes if you try to set an object's quaternion to an unnormalized one?
Quote:
Originally Posted by farshizzo View Post
In general, you don't need to deal with quaternions at such a low level. You can use Vizards matrix routines to deal with rotation transformations.
Unfortunately, seems like I do. This little script is just a way to fill in the gaps I have in my understanding of quaternions.
Reply With Quote