CONTENTS OTHER MATERIAL |
Vector Math Due to some limitations of Javascript, we cannot use the standard math operators +, -, /, and * with vectors. Instead, you need to use special vector math methods: add(vector1, vector2) Unfortunately, this means that vector math operations can quickly become hard to read. For instance, a simple operation such as (a-b)/2 becomes div(sub(a,b),2); Obviously, this is harder to decipher. Its also harder to write, and is more likely to introduce a typo or other bug into your expression. In general, you want to keep things very simple and very readable, because they are then more likely to work. So vector math seems to be a problem. One good solution is to break up operations like this into a series of simple steps. For instance, we could rewrite the above example: temp=sub(a,b); This version is much easier to follow, and less likely to introduce bugs into your expression. I strongly recommend that you break compound vector math operations up into a series of simple steps, each containing just one operation. |
Entire contents © 2001 JJ Gifford.