Converting from local coordinates

Goonmeister
Posts: 1
Joined: Tue Apr 30, 2013 12:14 am

Converting from local coordinates

Post by Goonmeister »

Hi everyone, I'm fairly new to this so I apologize if this is a fairly basic question.

I'm trying to get a robot arm to grasp an object by using an evolutionary algorithm, by having part of the fitness function include "distance from object to the robot's palm". Using the center of mass for both objects would mean that the back of the palm receives the same fitness as the front of the palm, which is not what I want.

How do I convert local coordinates (the preferred direction/distance away from the palm) into world coordinates? As it is now I use:

btVector3 position = body->getCenterOfMassPosition();
btVector3 position2 = body2->getCenterOfMassPosition();
double Xposition = abs(position.getX()-position2.getX());
double Yposition = abs(position.getY()-position2.getY());
double Zposition = abs(position.getZ()-position2.getZ());
double distance = (Xpos+Ypos+Zpos)/3;

Thanks for your time.
mikeshafer
Posts: 49
Joined: Fri Feb 24, 2012 10:45 am

Re: Converting from local coordinates

Post by mikeshafer »

So I'm not sure I quite understand what you're asking. In 3D programming, we go from world to local coordinates (and back) depending on the situation. For example, to make an object NOT at the origin rotate, you'd have to convert to local coordinates, do the rotation there and then convert back to world coordinates. Otherwise when you rotate an object not at the origin, you get unwanted translation (e.g. a pencil's eraser is at the origin, its tip is not at the origin, when you rotate the pencil on your desk holding the eraser in one place, the tip will rotate AND move, while the eraser will rotate in place).

To get the distance between 2 objects, you want to subtract one vector from the other and then get the magnitude. Something like:

Code: Select all

btScalar dist = (body->getCenterOfMassPosition() - body2->getCenterOfMassPosition()).length();
HTH,
Mike