Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If I am not mistaken, one way for you to get the Z axis is to find a perpendicular vector to X axis, or Y axis. Here is a handy Java code to find a perpendicular vector.

// Point pt0, pt1: define the line you want to find a perpendicular vector from.
// Point intersect: is the point of intersection between that line and the perpendicular vector.
// double vectorLength: the lenght in pixels of perpendicular vector.    

double angle = Math.PI/2; // 90 degrees
double perpendicularCos = Math.cos(angle);
double perpendicularSin = Math.sin(angle);
double d = pointsDist(pt0, pt1); // distance in pixels between 2 points.

// (x,y) define a vector of length vectorLength perpendicular to (pt0,pt1)
double x = intersec.x - ((pt1.x - pt0.x) * perpendicularCos - (pt1.y - pt0.y) * arrowSin) * (vectorLength / d);    
double y = intersec.y - ((pt1.y - pt0.y) * perpendicularCos + (pt1.x - pt0.x) * arrowSin) * (vectorLength / d);

If I am not mistaken, one way for you to get the Z axis is to find a perpendicular vector to X axis, or Y axis. Here is a handy Java code to find a perpendicular vector.

// Point pt0, pt1: define the line you want to find a perpendicular vector from.
// Point intersect: is the point of intersection between that line and the perpendicular vector.
// double vectorLength: the lenght in pixels of perpendicular vector.    

double angle = Math.PI/2; // 90 degrees
double perpendicularCos = Math.cos(angle);
Math.cos(angle); // or just use '= 0' because angle is 90º
double perpendicularSin = Math.sin(angle);
Math.sin(angle); // or just use '= 1' because angle is 90º
double d = pointsDist(pt0, pt1); // distance in pixels between 2 points.

// (x,y) define a vector of length vectorLength perpendicular to (pt0,pt1)
double x = intersec.x - ((pt1.x - pt0.x) * perpendicularCos - (pt1.y - pt0.y) * arrowSin) * (vectorLength / d);    
double y = intersec.y - ((pt1.y - pt0.y) * perpendicularCos + (pt1.x - pt0.x) * arrowSin) * (vectorLength / d);