Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is causing Uncaught TypeError: number is not a function?

Tags:

javascript

3d

As you can tell I'm trying to put together a very simple 3d engine. I'm writing it in javascript. I think it's likely that there is an error in the formula, but for the life of me I can't find it. So now I'm thinking there might be something else I haven't considered yet. The error occurs on line 21 (dx = Math.cos.....)

Here is the relevant part of my code:

// Camera Position in x,y,z
var c = [ 0,0,0 ];

// Viewer position [x,y,z]
var v = [ 0,0,0 ];

// Angle of view [x, y, z]
var a = [ 0.01, 0.01, 0.01 ];

var point =  [ 0,0, 50 ];

dx = Math.cos(a[1])(Math.sin(a[2])(point[1] - c[1]) + Math.cos(a[2])(point[0] - c[0])) - Math.sin(a[1])(point[2] - c[2]);
dy = Math.sin(a[0])(Math.cos(a[1])(point[2] - c[2]) + Math.sin(a[1])(Math.sin(a[2])(point[1] - c[1]) + Math.cos(a[2])(point[0] - c[0]))) + Math.cos(a[0])(Math.cos(a[2])(point[1] - c[1]) - Math.sin(a[2])(point[0] - c[0]));
dz = Math.cos(a[0])(Math.cos(a[1])(point[2] - c[2]) + Math.sin(a[1])(Math.sin(a[2])(point[1] - c[1]) + Math.cos(a[2])(point[0] - c[0]))) - Math.sin(a[0])(Math.cos(a[2])(point[1] - c[1]) - Math.sin(a[2])(point[0] - c[0]));

bx = (dx - v[0])(v[2]/dz);
by = (dy - v[1])(v[2]/dz);
like image 270
Tyler Biscoe Avatar asked Dec 07 '25 04:12

Tyler Biscoe


1 Answers

You need to use * to multiply:

dx = Math.cos(a[1])*(Math.sin(a[2])*(point[1] - c[1]) ... etc
like image 60
mVChr Avatar answered Dec 08 '25 17:12

mVChr