Question

All vector

First I want to call this following vector as:

Vector M1 = [O → M1]; Vector C1 = [O → E];

Vector M2 = [A → M2]; Vector C2 = [A → C];

Vector M3 = [B → M3]; Vector C3 = [B → G];

every M vector is main vector or base vector.

My problem is how to find angle between those vector(M to C). to decide which direction did C look compare from M.

e.g.

1.) M1 and C1 direction is right.

2.) M2 and C2 direction is left.

3.) M3 and C3 direction is back.

ps. sorry for my bad English, if you don't understand what I try to say, ask me.

Edited: angle should be in clockwise direction.

Was it helpful?

Solution

Thanks to MvG from Direct way of computing clockwise angle between 2 vectors his solution working perfect.

double dot = C.dot(M);
double det = ((C.getX()*M.getZ()) - (C.getZ()*M.getX()));
double angle = Math.toDegrees(Math.atan2(det, dot));

String movedirection = "";
if(angle < -135 || angle >= 135){
movedirection = "Front";
};
if(angle < 135 && angle >= 45){
movedirection = "right";
};
if(angle < 45 && angle >= -45){
movedirection = "back";
};
if(angle < -45 && angle >= -135){
movedirection = "left";
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top