/* To find angle between two vectors */
#include<stdio.h>
#include<math.h>
int main()
{
float ax, ay, az, bx, by, bz, AdotB, ModA, ModB, ModAModB, AngleAB;
printf("Enter the values of ax, ay, az:\n");
scanf("%f%f%f", &ax, &ay, &az);
printf("A=(%f)i+(%f)j+(%f)k", ax, ay, az);
printf("\nEnter the values of bx, by, bz:\n");
scanf("%f%f%f", &bx, &by, &bz);
printf("B=(%f)i+(%f)j+(%f)k", bx, by,bz);
AdotB=ax*bx+ay*by+az*bz;
printf("\nA.B=%f", AdotB);
ModA=sqrt(ax*ax+ay*ay+az*az);
ModB=sqrt(bx*bx+by*by+bz*bz);
ModAModB=ModA*ModB;
AngleAB=AdotB/ModAModB;
AngleAB=AngleAB*180/3.14159;
printf("\nAngle between A and B in degree is Cos/_A,B=%f\n", AngleAB);
return(0);
}
#include<stdio.h>
#include<math.h>
int main()
{
float ax, ay, az, bx, by, bz, AdotB, ModA, ModB, ModAModB, AngleAB;
printf("Enter the values of ax, ay, az:\n");
scanf("%f%f%f", &ax, &ay, &az);
printf("A=(%f)i+(%f)j+(%f)k", ax, ay, az);
printf("\nEnter the values of bx, by, bz:\n");
scanf("%f%f%f", &bx, &by, &bz);
printf("B=(%f)i+(%f)j+(%f)k", bx, by,bz);
AdotB=ax*bx+ay*by+az*bz;
printf("\nA.B=%f", AdotB);
ModA=sqrt(ax*ax+ay*ay+az*az);
ModB=sqrt(bx*bx+by*by+bz*bz);
ModAModB=ModA*ModB;
AngleAB=AdotB/ModAModB;
AngleAB=AngleAB*180/3.14159;
printf("\nAngle between A and B in degree is Cos/_A,B=%f\n", AngleAB);
return(0);
}
Comments
Post a Comment