It is actually easier than I thought. I guess those linear algebra classes was actually useful.
In this case, I assume you have some 3D geometry defined as a class named 'GeomType'. An 'Object' is made up of many 'GeomType'. Here an 'Object' is simple a vector of 'GeomType'.
Each 'GeomType' in an 'Object' is defined by it centre point location relative to the centre point of the 'Object' and an quaternion which represent the rotation from a default neutral position. Here is some sample code.
There are also PointType which is basically (x, y, z) in double, and QuaternionType which is (w,x,y,z) in double as well.
//suppose you have this Object
std::vector <GeomType> Object; //and it is already initialized
//you were given the rotation quaternion and the point to rotate about.
PointType origin;
QuaternionType Q2;
//rotate the GeomTypes
unsigned int numGeom = Object.size();
for (unsigned int i = 0; i <numGeom; i++)
{
//1. translate the individual GeomType
const PointType geomCentre= Object[i].GetCentrePosition();
//Rotate vector representing the direction and distance from origin to geom
//note that the origin of rotation does not need to be the centre
const PointType newPos =
RotateAbout(PointType(geomCentre[0], geomCentre[1], dGeomPos[2]),
Q2, origin);
//move the GeomType to the new position
Object[i].SetCentrePosition(newPos.GetX(), newPos.GetY(), newPos.GetZ());
//2. Rotate the GeomType
QuaternionType Qo = Object[i].GetQuaternion(); //current quaternion of the geom
QuaternionType Qr; //resultant quaternion of the geom
Qr = Q2*Qo; //rotating by multiplication
//(please check other sites on how to multiply quaternions)
Object[i].SetQuaternion(Qr); //set the new quaternion
}
This is the RotateAbout function which was used to rotate a vector about a point
PointType RotateAbout(const PointType &InitPos, const QuaternionType &Qr, const PointType& Origin)
{
//the vector from the origin
PointType newVec = InitPos-Origin;
//extract the magnitude
const double vecLength = newVec.Length();
//normalize the vector and rotate that vector
//then translate the geom to the new position
newVec = Origin + Qr*(newVec.GetUnitVector())*vecLength;
return newVec;
}
Here is the general program to rotate a set of 3D objects relative to a point. It should be applicable to any programming language though it is written based on C++.