#include <stdio.h>
#include <math.h>

typedef  struct complex{
  double Re,Im;
}Complex;

#define MAX(a,b) ((a)>(b)?(a):(b))

Complex axpbyComplex(double lambda,Complex z1,double mu, Complex z2);
double modulusComplex(Complex z);
double areaComplexT(Complex z1, Complex z2, Complex z3);
double maxLengthComplexT(Complex z1, Complex z2, Complex z3);
void Print3Complex(Complex z1,Complex z2, Complex z3);

int main(){
  Complex z1={0.,0.},z2={0.,1.},z3={1.,0.}; 
  printf("\n(0) Initial values of z1,z2,z3\n");
  Print3Complex(z1,z2,z3);
  printf("\n(1) Triangle (z1,z2,z3) : area=%.6lf, h=%.6lf\n",
	 areaComplexT(z1,z2,z3),maxLengthComplexT(z1,z2,z3));
  
}

Complex axpbyComplex(double lambda,Complex z1,double mu, Complex z2){
  Complex z;
  z.Re=lambda*z1.Re+mu*z2.Re;
  z.Im=lambda*z1.Im+mu*z2.Im;
  return z;
}

double modulusComplex(Complex z){
  return sqrt( z.Re*z.Re + z.Im*z.Im);
}
 
double areaComplexT(Complex z1, Complex z2, Complex z3){
   return 0.5*fabs( (z2.Re-z1.Re)*(z3.Im-z1.Im) - (z2.Im-z1.Im)*(z3.Re-z1.Re) );
}

void PrintComplex(Complex z){
  printf("(%.6f,%.6f)",z.Re,z.Im);
}

void Print3Complex(Complex z1,Complex z2, Complex z3){
  printf("  z1=");PrintComplex(z1);
  printf(", z2=");PrintComplex(z2);
  printf(", z3=");PrintComplex(z3);
}

double maxLengthComplexT(Complex z1, Complex z2, Complex z3){
  double h=0.;
  Complex Edge;
  h=MAX(h,fabs(modulusComplex(axpbyComplex(1.,z1,-1.,z2))));
  h=MAX(h,fabs(modulusComplex(axpbyComplex(1.,z1,-1.,z3))));
  h=MAX(h,fabs(modulusComplex(axpbyComplex(1.,z2,-1.,z3))));
  return h;
}
  