To draw a rectangle around the face from given eye positions, get inspired by the following code snippet (written in C#) to obtain face rectangle coordinates.
public static Vector[] GetFaceRectangle(Vector leftEyeVec, Vector rightEyeVec) {
Vector eyeVec = leftEyeVec - rightEyeVec;
double eyeDist = eyeVec.Length;
double widthFace = eyeDist / 0.25d; //ICAO ratios
double heigthFace = widthFace / 0.75d;
Vector n = eyeVec.Unit().Normal(); //normalize
Vector[] result = new Vector[5];
result[0] = new Vector(rightEyeVec.X, rightEyeVec.Y); //find out origin of the rectangle
result[0] -= n * (heigthFace * 0.45d);
result[0] -= eyeVec.Unit() * ((widthFace - eyeDist) / 2.0);
result[1] = result[0] + eyeVec.Unit() * widthFace;
result[2] = result[1] + n * heigthFace;
result[3] = result[0] + n * heigthFace;
result[4] = new Vector(widthFace, heigthFace);
return result;
}
class Vector {
public double X, Y;
public double Length {
get { return Math.Sqrt(X * X + Y * Y); }
}
public Vector(double x, double y){
this.X = x; this.Y = y;
}
public static Vector operator +(Vector a, Vector b) {
return new Vector(a.X + b.X, a.Y + b.Y);
}
public static Vector operator -(Vector a, Vector b) {
return new Vector(a.X - b.X, a.Y - b.Y);
}
public static Vector operator *(Vector a, double b) {
return new Vector(a.X * b, a.Y * b);
}
public static Vector operator /(Vector a, double d) {
return new Vector(a.X / d, a.Y / d);
}
public Vector Unit() {
return this / this.Length;
}
public Vector Normal() {
return new Vector(Y, -X) * -1;
}
}