Question: Write a C PROGRAM that reads an obj file (a file representing the 3D model), calculates the center of mass of the model, and rotates

Write a C PROGRAM" that reads an obj file (a file representing the 3D model), calculates the center of mass of the model, and rotates the model in the given x, y, z-directions. The center of mass of the 3D model is calculated as follows: (mean (x), mean (y), mean (z)) The average value of all x-values at the 3-dimensional point, the average value of all y-values and z-values, respectively. Translation is performed by adding x, y, z values corresponding to each 3-dimensional point of the model. Object files store 3-dimensional points and faces (triangles made up of 3 3D points). Points, also called vertices, begin with the letter "v", while faces begin with "f". In this assignment, you will need only "v" lines. Steps to be taken: * Create a structure named Point3D with 3 floating variables x, y, z (check lecture notes) * Get the number of 3d dots. (Open the file, get the number of lines starting with "v") * Dynamically allocate an array of equal size to the number of 3D points and type Point3D. Write a function that will input the Point3D array and the number of points and return the Point3D structure to calculate the center of mass * Display the resulting Point3D using printf (the x, y and z values of the center of mass) * Write a function that will convert each point according to the given x, y, z values. These values will be taken from the user. * Store the translated points in a file in the same format as the obj file (So you can visualize the result.) * To hide the result: * For each vertex v, then x, y and z coordinates, * For faces, simply copy the same values from the input obj file. Notes: You can use fscanf (fp, "% c% f% f% f \ n", & f_or_v, & x, & y, & z) to get the values in each row. (f_or_v, char, x, y, and z are float variables.)

It is not known how many points are in the file. Use the feof function.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!