Vector functions in scripts

Vectors can be defined in scripts by putting the components in square brackets: A = [1,2,3];. The following vector functions have been defined.

  • length(A) - length of vector $|\vec{A}|=\sqrt{A_x^2 + A_y^2 + A_z^2}$
  • dot(A,B) - scalar product of two vectors $\vec{A}\cdot\vec{B} = A_xB_x + A_yB_y + A_zB_z$
  • dot(a,B) - scalar times a vector $ a\vec{B} = aB_x\,\hat{x} + aB_y\,\hat{y} + aB_z\,\hat{z}$
  • cross(A,B) - cross product $\vec{A}\times\vec{B}$
  • unit(A) - unit vector $\vec{A}/|\vec{A}|$
  • vadd(A,B) - vector addition $\vec{A}+\vec{B}=(A_x + B_x)\,\hat{x} + (A_y + B_y)\,\hat{y} + (A_z + B_z)\,\hat{z}$
  • vsub(A,B) - vector subtraction $\vec{A}-\vec{B}=(A_x - B_x)\,\hat{x} + (A_y - B_y)\,\hat{y} + (A_z - B_z)\,\hat{z}$

The function dot(A,B) is overloaded. If the arguments A and B are vectors, it returns the scalar vector product of these vectors but if the arguments are a vector and a scalar, it returns the vector muliplied by the scalar. The vector functions report intermediate results to the Script Output. You can load example scripts with the buttons at the bottom.




Script Output