matlabrotationlinear-algebrageometry-surfacecross-product# Rotate a vector by 90 degree via cross product

I am trying to understand a code wherein the authors have rotated vectors in 3D by 90 degrees. They used a cross-product to do so. How cross-product can incorporate rotation by 90 degrees? Any explanation would be helpful.

```
% Inputs:
% V #vertices by dim list of mesh vertex positions
% F #faces by simplex-size list of mesh face indices
% Gradient of a scalar function defined on piecewise linear elements (mesh)
% is constant on each triangle i,j,k:
% grad(Xijk) = (Xj-Xi) * (Vi - Vk)^R90 / 2A + (Xk-Xi) * (Vj - Vi)^R90 / 2A
% grad(Xijk) = Xj * (Vi - Vk)^R90 / 2A + Xk * (Vj - Vi)^R90 / 2A +
% -Xi * (Vi - Vk)^R90 / 2A - Xi * (Vj - Vi)^R90 / 2A
% where Xi is the scalar value at vertex i, Vi is the 3D position of vertex
% i, and A is the area of triangle (i,j,k). ^R90 represent a rotation of
% 90 degrees
%
% renaming indices of vertices of triangles for convenience
i1 = F(:,1); i2 = F(:,2); i3 = F(:,3);
% #F x 3 matrices of triangle edge vectors, named after opposite vertices
v32 = V(i3,:) - V(i2,:); v13 = V(i1,:) - V(i3,:); v21 = V(i2,:) - V(i1,:);
% area of parallelogram is twice area of triangle
% area of parallelogram is || v1 x v2 ||
n = cross(v32,v13,2);
% This does correct l2 norm of rows so that it contains #F list of twice
% triangle areas
dblA = normrow(n);
% now normalize normals to get unit normals
u = normalizerow(n);
% rotate each vector 90 degrees around normal ---- ????
eperp21 = bsxfun(@times,cross(u,v21),1./dblA);
eperp13 = bsxfun(@times,cross(u,v13),1./dblA);
```

Solution

In 3d the *cross product* `a x b`

of two vectors `a`

and `b`

results in a vector `p := a x b`

that is *perpendicular* to both `a`

and `b`

.

This means if you cross-multiply a vector with an unit vector `u`

that represents the rotation axis, you will get a vector that is rotated 90 degrees around the rotation axis.

- How to execute .m files in Octave
- Return the maximum value of every subgroup in a table
- How can I reformat code in MATLAB editor?
- Create blockwise shifted sparse matrix in matlab directly
- ms-coherence in matlab and python
- MATLAB: Using ODE solvers?
- 'Invalid operator' error when running MATLAB script without changing working directory
- quad function to work in a loop without calling to file
- Integration via trapezoidal sums in MATLAB
- How to solve integral in Matlab having an upper limit set as the sine function?
- Obtaining the constant that makes the integral equal to zero in Matlab
- Code wont produce the value of a definite integral in MATLAB
- CT projection (distance-driven) operator implementation?
- "Array indices must be positive integers or logical values"
- How do I mark (or) shade the area below the graph of Surface plot in Matlab?
- How do I add each frame back together after spectral subtraction (MATLAB)?
- Spectrum Derivative in MATLAB, the end point problem
- implementation of Lomb-Scargle periodogram
- Rectangular Nesting - Convergence to optimal solution using Simulated Annealing
- Parfor for Python
- How to replace NaN from armadillo matrix?
- Clarifying the Process of Generating iid Gaussian Random Vectors in MATLAB
- Fastest way to do repeated element wise matrix multiplication in MATLAB?
- Multiple date formats in MATLAB
- Extract .mat data without matlab - tried scilab unsuccessfully
- How to get recursion coefficients for a Chebychev filter in Matlab
- MATLAB - Stuck on changing x axis for boxplot
- Convert matlab.double array to python array
- Histogram with a mean line in same spot
- Spatial toolbox robot model