Write a general computer program (in C, C++ or Java) to convert a vector in one
ID: 3849733 • Letter: W
Question
Write a general computer program (in C, C++ or Java) to convert a vector in one coordinate systems to a vector in another coordinate systems e.g. Cartesian to cylindrical, cartesian to spherical: spherical to Cartesian, cylindrical to Cartesian system, cylindrical to spherical system, or spherical to cylindrical system) using matrix representation of the conversion at a given point. Follow the "Formal for Computer Assignment Report" in preparing this report. The report should have a cover page, problem statement and must be neatly prepared using only an 8.5" by 11" engineering paper. All pages must be stapled and sequentially numbered. Figures, flow graphs, and tables must be properly labeled and tilled. The report must be signed and dated. References should be in proper format and cited in the report. Using your computer program above, express a uniform field F = 4 x y^2 a_rho + y x^2 a_z in cylindrical coordinates (a) to Cartesian Coordinates at P (2, 3, 2). Verify your results by hand calculations.Explanation / Answer
Answer for Question:
This below C++ code is convert the vector coordinate system to another vector of coordinate system.
See the below cod for with tranorm equations and calculations performed in below.
#include <Eigen/Dense>
#include <Eigen/Geometry>
using namespace Eigen;
/// Determine rotation quaternion from coordinate system 1 (vectors
/// x1, y1, z1) to coordinate system 2 (vectors x2, y2, z2)
Quaterniond QuaternionRot(Vector3d x1, Vector3d y1, Vector3d z1,
Vector3d x2, Vector3d y2, Vector3d z2) {
Matrix3d M = x1*x2.transpose() + y1*y2.transpose() + z1*z2.transpose();
Matrix4d N;
N << M(0,0)+M(1,1)+M(2,2) ,M(1,2)-M(2,1) , M(2,0)-M(0,2) , M(0,1)-M(1,0),
M(1,2)-M(2,1) ,M(0,0)-M(1,1)-M(2,2) , M(0,1)+M(1,0) , M(2,0)+M(0,2),
M(2,0)-M(0,2) ,M(0,1)+M(1,0) ,-M(0,0)+M(1,1)-M(2,2) , M(1,2)+M(2,1),
M(0,1)-M(1,0) ,M(2,0)+M(0,2) , M(1,2)+M(2,1) ,-M(0,0)-M(1,1)+M(2,2);
EigenSolver<Matrix4d> N_es(N);
Vector4d::Index maxIndex;
N_es.eigenvalues().real().maxCoeff(&maxIndex);
Vector4d ev_max = N_es.eigenvectors().col(maxIndex).real();
Quaterniond quat(ev_max(0), ev_max(1), ev_max(2), ev_max(3));
quat.normalize();
return quat;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.