Suppose I have the following MATLAB code:
function xn=normalize(x)
xn=x/norm(x);
end
nTriangles=size(faces,1);
trN=zeros(nTriangles,3);
for i=1:nTriangles
trN(i,:)=normalize(cross(vert(faces(i,2),:)-vert(faces(i,1),:),...vert(faces(i,3),:)-vert(faces(i,1),:)));
end
I want to convert it to JavaScript using the math.js libraries.
I tried doing the following:
const math = require('mathjs')
function normalize(x){
return x/math.norm(x);}
let nTriangles = math.size(faces)[0];
let trNormals=math.zeros(nTriangles,3);
for (let i = 0; i < nTriangles; i++) {
let trN=math.row(trNormals,i);
trN = normalize(math.cross(math.row(vert,math.subset(faces,math.index(i,1)))-math.row(vert,math.subset(faces,math.index(i,0))),... math.row(vert,math.subset(faces,math.index(i,2)))-math.row(vert,math.subset(faces,math.index(i,0)))));
However,this is wrong. I get an error:
Argument type number is not assignable to parameter type MathArray | Matrix
I keep trying to resolve the error, but to no success.
Can someone suggest how I can go about solving the issue or how I could else write the MATLAB code into JS?
On another note, the MATLAB code uses ,… while in Javascript this doesn’t seem to work.