/* Calcul des directions de reflexion           */
/* et de transmission a l'interface             */
/* entre deux milieux                           */
/*                                              */
/* Auteur: Nicolas JANEY                        */
/* nicolas.janey@univ-fcomte.fr                 */
/* Avril 2020                                */

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

#include "Dir3D.h"

#ifndef M_PI
#define M_PI 3.14159265358F
#endif

void print(const char *messageAvant,CH3D *ch,const char *messageApres) {
  printf("%s",messageAvant);
  ch->print();
  printf("%s",messageApres);
}

/* Fonction principale                          */

int main(int argc,char **argv) {
  { Dir3D n( 0.0000F,0.9397F,0.3420F);
    Dir3D i(-0.4082F,0.8142F,0.4128F);
    float ni = 2.4244F;
    float nt = 1.3333F;
    n.normalisation();
    i.normalisation();
    printf("ni : %f, nt :  %f\n",ni,nt);
    printf("thetai : %f\n",acos(n.produitScalaire(&i))*180.0F/M_PI);
    print("Direction normale      : ",&n,"\n");
    print("Direction incidence    : ",&i,"\n");
    { Dir3D r;
      if ( r.reflexion(&i,&n) ) {
        print("Direction reflexion    : ",&r,"\n"); }
        else
        printf("Pas de réflexion spéculaire\n"); }
    { Dir3D t;
      if ( t.transmission(&i,&n,ni/nt) ) {
        print("Direction transmission : ",&t,"\n");
        printf("thetat : %f\n",acos(-n.produitScalaire(&t))*180.0F/M_PI); }
        else
        printf("Pas de transmission\n"); } }
  printf("\n");
  { Dir3D n( 0.0000F,0.9397F,0.3420F);
    Dir3D i(-0.7750F,0.4990F,0.3870F);
    float ni = 1.5547F;
    float nt = 2.7958F;
    n.normalisation();
    i.normalisation();
    printf("ni : %f, nt :  %f\n",ni,nt);
    printf("thetai : %f\n",acos(n.produitScalaire(&i))*180.0F/M_PI);
    print("Direction normale      : ",&n,"\n");
    print("Direction incidence    : ",&i,"\n");
    { Dir3D r;
      if ( r.reflexion(&i,&n) ) {
        print("Direction reflexion    : ",&r,"\n"); }
        else
        printf("Pas de réflexion spéculaire\n"); }
    { Dir3D t;
      if ( t.transmission(&i,&n,ni/nt) ) {
        print("Direction transmission : ",&t,"\n");
        printf("thetat : %f\n",acos(-n.produitScalaire(&t))*180.0F/M_PI); }
        else
        printf("Pas de transmission\n"); } }
  printf("\n");
  { Dir3D n( 0.0000F,0.9397F,0.3420F);
    Dir3D i(-0.6980F,0.5930F,0.4010F);
    float ni = 1.8127F;
    float nt = 1.2844F;
    n.normalisation();
    i.normalisation();
    printf("ni : %f, nt :  %f\n",ni,nt);
    printf("thetai : %f\n",acos(n.produitScalaire(&i))*180.0F/M_PI);
    print("Direction normale      : ",&n,"\n");
    print("Direction incidence    : ",&i,"\n");
    { Dir3D r;
      if ( r.reflexion(&i,&n) ) {
        print("Direction reflexion    : ",&r,"\n"); }
        else
        printf("Pas de réflexion spéculaire\n"); }
    { Dir3D t;
      if ( t.transmission(&i,&n,ni/nt) ) {
        print("Direction transmission : ",&t,"\n");
        printf("thetat : %f\n",acos(-n.produitScalaire(&t))*180.0F/M_PI); }
        else
        printf("Pas de transmission\n"); } }
  getchar();
  return(0);
}
