quaternion "SpheriqueToQuat"

Started by
1 comment, last by jollyjeffers 16 years, 11 months ago
Hello everybody ! I'm drawing a sphere in C++/opengl using quaternion to turn around it. But i have difficulties to implement a correct function to transform sperical coordinate (latitude,longitude) to a quaternion First, i do not understand why i need an angle to convert latitude and longitude to a quaternion ( i thought it only was for the up vector ) I used the quaternion faq to make my function

void Quaternion::SpheriqueToQuat(const float latitude, const float longitude, const float angle)
{

double sin_a = sin(angle / 2);
double cos_a = cos(angle / 2);

double sin_lat = sin(latitude);
double cos_lat = cos(latitude);

double sin_long = sin(longitude);
double cos_long = cos(longitude);


this->w = float(cos_a);

this->x = float(sin_a * cos_lat * sin_long);
this->y = float(sin_a * sin_lat);
this->z = float(sin_a * sin_lat * cos_long);

Normalize();

return;
}


The result is really bad : If i put the angle value to 1, latitude to 0 and i increase the longitude with a timer, the resulting movement draw a eight on my sphere instead of turning around the equator.

Thanks in advance for any advice. Sébastien. [Edited by - cbastien on May 16, 2007 4:28:27 AM]
Advertisement
here a temporary version i made, it is not really accurate but it works !

void Quaternion::SpheriqueToQuat(const float latitude, const float longitude, const float angle){	//this is a temporary version // do NOT work Accurately	if( longitude>=-180 && longitude<=0 ){				float longi=-(longitude+90);		float lati=-latitude;		if( latitude <= 0){		this->x = float(longi/90);		this->y = float( lati / 180 );		this->z = float(1 - ( lati / 180 ) );		this->w = float(longi/90 * ( lati / 180 ) * 2 );		} else {			this->x = float(longi/90);			this->y = float( lati / 180 );			this->z = float(1 + ( lati / 180 ) );			this->w = float(longi/90 * ( lati / 180 ) * 2 );		}			}else{		float longi=(longitude-90);			float lati=-latitude;		if(longitude<90){					this->x = float( 1 + ( longi / 180 ));			this->y = float( (longi/180) * (lati / 90)  ); 			this->z = float( longi / 180 );			this->w = float( ( lati / 90 ) * (1+longi/180 ) );		}else{			this->x = float( 1 - ( longi / 180 ));			this->y = float( (longi/180) * (lati / 90) );			this->z = float( longi / 180 );			this->w = float( ( lati / 90 ) * (1-longi/180 ) );		}	}}


any advice to help me in a better way to do that ?

[Edited by - cbastien on May 16, 2007 4:41:09 AM]
One thread should be enough [smile]

Cheers,
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

This topic is closed to new replies.

Advertisement