Organize the three angles into a struct we will call Euler. Contains three doubl
ID: 3732457 • Letter: O
Question
Organize the three angles into a struct we will call Euler.
Contains three doubles, yaw, pitch and roll.
typedef struct
{
double yaw;
double pitch;
double roll;
} Euler;
Define the struct at the top of the file.
Also define PI:
#define PI 3.1415926535897932
Create the following functions:RadiansToDegrees
INPUT: One Euler variable
OUTPUT: Euler variable converted to degrees
degrees.yaw = radians.yaw * 180.0 / PI
Repeat for pitch and roll
DegreesToRadians
INPUT: One Euler variable
OUTPUT: Euler variable converted to radians
radians.yaw = degrees.yaw * PI / 180.0
Repeat for pitch and roll
PrintAngles
INPUT: One Euler variable
OUTPUT: void
Prints the angles (yaw, pitch, roll)
Within your main function:Create three Euler variables.
One to hold the initial angle which will be in degrees.
One to hold the result of DegreesToRadians().
One to hold the result of RadiansToDegrees().
Prompt to user to enter three values in degrees (using scanf) and save what they enter to your initial Euler variable.
You may assume that the user will only enter values from 0-360 degrees.
Call DegreesToRadians with the initial angle. Save the result to your Euler variable that will hold radians.
Call RadiansToDegrees with your radians variable. Save the result to your Euler veriable that will hold degrees.
Call PrintVector to print the result from DegreesToRadians.
Call PrintVector to print the result from RadiansToDegrees.
Note: The degrees value may not match what was initially entered, but it should be close.
Define ALL of the functions in this code with const and pass by reference.
Explanation / Answer
#include <stdio.h
#define PI 3.1415926535897932
typedef struct
{
double yaw;
double pitch;
double roll;
}Euler;
const void convert_degrees_to_radians (Euler *first, Euler *second)
{
second->yaw = (first->yaw*PI)/180.0;
second->pitch = (first->pitch*PI)/180.0;
second->roll = (first->roll*PI)/180.0;
}
const void convert_radians_to_degrees (Euler *second, Euler *third)
{
third->yaw = (second->yaw * 180)/PI;
third->pitch = (second->pitch * 180)/PI;
third->roll = (second->roll * 180)/PI;
}
const void print_euler (Euler *euler)
{
printf("Yaw value is %lf, Pitch value is %lf, Roll value is %lf ",euler->yaw, euler->pitch, euler->roll);
}
void main()
{
Euler first;
printf("Enter three values for yaw, pitch and roll in degrees ");
double yaw, pitch, roll;
scanf("%lf", &yaw);
scanf("%lf", &pitch);
scanf("%lf", &roll);
first.yaw = yaw;
first.pitch = pitch;
first.roll = roll;
printf("Values before Converting to radians ");
printf("==================================== ");
print_euler(&first);
Euler second;
convert_degrees_to_radians(&first, &second);
printf("Values After Converting to radians ");
printf("==================================== ");
print_euler(&second);
Euler third;
convert_radians_to_degrees(&second, &third);
printf("Values before Converting to back to degrees ");
printf("==================================== ");
print_euler(&third);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.