diff --git a/Gemfile b/Gemfile index ad13bf4..cfc301c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ source "http://rubygems.org" gem "jake" - +gem "staticmatic" diff --git a/site/.htaccess b/site/.htaccess deleted file mode 100644 index d7af0a4..0000000 --- a/site/.htaccess +++ /dev/null @@ -1,4 +0,0 @@ -RewriteEngine On - -RewriteRule ^$ index.php [QSA] -RewriteRule ^([^.]+)$ $1.php [QSA] diff --git a/site/api/line.php b/site/api/line.php deleted file mode 100644 index 9f59608..0000000 --- a/site/api/line.php +++ /dev/null @@ -1,123 +0,0 @@ - - - - - -

Class: Line

- -

Sylvester version: 0.1.0 onwards

- -

Class methods: -create, -X, -Y, -Z -

- -

Instance methods: -contains, -distanceFrom, -dup, -eql, -intersectionWith, -intersects, -isParallelTo, -liesIn, -pointClosestTo, -reflectionIn, -rotate, -setVectors, -translate -

- -

Instance variables:

- - - -

Overview

- -

The Line class is designed to model infinite straight lines in 3 dimensions. It is possible to specify lines using 2D Vectors, but they will be stored in the Line instance as 3D vectors whose third element is zero. Lines created in this way are thus 3D lines confined to the x-y plane. You can also specify 2D vectors as arguments for many of Line’s instance methods – again, these will be interpreted as 3D vectors with a zero third component.

- -

Class methods

- - -

Line.create(anchor, direction) 0.1.0

-

Creates a Line instance with the specified properties. anchor and direction can each be either 2- or 3-dimensional arrays or Vectors, and they will be stored in the Line’s properties as 3D vectors. (The thrid element will be zero if a 2D vector was supplied.) direction will be normalized before being saved. The following are all fine:

- -
var A = Line.create([4,8], [1,5]);
-var B = Line.create($V([4,8]), $V([1,5]));
-var C = Line.create([9,2,5], $V([8,2,0]));
- -

For situations where x, y and z are used to refer to co-ordinates, x corresponds to the first element of a vector, y the second and z the third.

- -

This method is aliased as $L.

- - -

Line.X, Line.Y, Line.Z 0.1.0

-

Predefined Line instances representing the x, y and z axes respectively.

- -

Instance methods

- - -

contains(point) 0.1.0

-

Returns true iff the vector point is a point that lies on the receiver.

- - -

distanceFrom(obj) 0.1.0

-

Returns the shortest distance between the receiver and obj, which can be a Line, a Plane or a Vector. If a Plane, this method will only return a non-zero value if the receiver is parallel to obj.

- - -

dup() 0.1.0

-

Returns a copy of the receiver.

- - -

eql(line) 0.1.0

-

Returns true iff line is equal to the receiver, that is, if they both represent the same region of space. Their anchor and direction properties do not have to be identical for this to be the case. As long as line.anchor is a point on the receiver, and line.direction is (anti)parallel to the receiver’s direction, then this method returns true.

- - -

intersectionWith(obj) 0.1.0

-

Returns a Vector representing the unique point of intersection of the receiver with obj, which can be either a Line or a Plane. If no such point exists, returns null.

- - -

intersects(obj) 0.1.0

-

Returns true iff the receiver has a unique point of intersection with obj, which can be either a Line or a Plane.

- - -

isParallelTo(line) 0.1.0

-

Returns true iff the receiver and line are parallel lines. Their direction vectors can point in opposite directions – two lines with opposing directions represent the same set of points.

- - -

liesIn(plane) 0.1.0

-

Returns true iff the receiver lies in the given plane.

- - -

pointClosestTo(obj) 0.1.0

-

Returns a Vector representing the point on the receiver that is closest to obj, which can be either a Vector or a Line. If a Line, returns null if the lines are parallel – there is no unique closest point.

- - -

reflectionIn(obj) 0.1.0

-

Returns a Line representing the result of reflecting (inverting) the receiver in obj, which can be a Line, a Plane or a Vector.

- - -

rotate(angle, axis) 0.1.0

-

Returns the result of rotating the receiver by angle radians about axis, which can be a Line, or a Vector. If a Vector, the receiver is rotated about a line whose anchor is axis and whose direction is [0, 0, 1]. This is useful for working in 2D:

- -
var L = Line.X.rotate(Math.PI/2, $V([5,0]));
-
-var test = L.eql(Line.create([5,0], [0,1]));
-// Returns true - the 90-degree rotation leaves Line.X parallel to the y axis
- -

Be careful when working with axis as a Line – rotations are performed in a right-handed fashion about the line’s direction.

- - -

setVectors(anchor, direction) 0.1.0

-

Sets the receiver’s properties accordingly. See create.

- - -

translate(vector) 0.1.0

-

Returns the result of translating the receiver by adding vector to its anchor property. vector can be a 2- or 3- dimensional array or Vector. If 2-dimensional, a zero third component will be added.

- - diff --git a/site/api/matrix.php b/site/api/matrix.php deleted file mode 100644 index d5d3c0f..0000000 --- a/site/api/matrix.php +++ /dev/null @@ -1,358 +0,0 @@ - - - - - -

Class: Matrix

- -

Sylvester version: 0.1.0 onwards

- -

Class methods: -create, -Diagonal, -I, -Random, -Rotation, -RotationX, -RotationY, -RotationZ, -Zero -

- -

Instance methods: -add, -augment, -canMultiplyFromLeft, -col, -cols, -det, -determinant, -diagonal, -dimensions, -dup, -e, -eql, -indexOf, -inspect, -inv, -inverse, -isSameSizeAs, -isSingular, -isSquare, -map, -max, -minor, -multiply, -rank, -rk, -round, -row, -rows, -setElements, -snapTo, -subtract, -toRightTriangular, -toUpperTriangular, -tr, -trace, -transpose, -x -

- -

Instance variables:

- - - -

Overview

- -

The Matrix class is designed to model real matrices in any number of dimensions. All the elements in a matrix must be real numbers.

- -

Class methods

- - -

Matrix.create(elements) 0.1.0

-

Creates and returns a new Matrix instance from the array elements. elements should be a nested array: the top level array is the rows, and each row is an array of elements. This means you write out a matrix in code in the same orientation you would on paper.

- -
var M = $M([
-  [8,3,9],
-  [2,0,7],
-  [1,9,3]
-]);
- -

Every row must have the same number of elements, otherwise the method will return null.

- -

This method is aliased as $M.

- - -

Matrix.Diagonal(elements) 0.1.0

-

Returns a square matrix whose leading-diagonal elements are the values in the array elements, and whose off-diagonal elements are zero.

- -
var D = Matrix.Diagonal([4,3,7,1]);
-
-// D is the matrix
-//    4 0 0 0
-//    0 3 0 0
-//    0 0 7 0
-//    0 0 0 1
- - -

Matrix.I(n) 0.1.0

-

Returns the n×n identity matrix.

- - -

Matrix.Random(n, m) 0.1.0

-

Returns a matrix with n rows and m columns, all the elements of which are random numbers between 0 and 1.

- - -

Matrix.Rotation(angle [, axis]) 0.1.0

-

If called with only one argument, returns the 2×2 matrix for an anticlockwise rotation of angle radians about the origin. That is, vectors are rotated anticlockwise with respect to the coordinate system, not the other way round.

-

If called with two arguments, returns the 3×3 matrix for a right-handed rotation of angle radians about the axis given by the 3-vector axis, keeping the origin fixed.

- - -

Matrix.RotationX(angle), Matrix.RotationY(angle), Matrix.RotationZ(angle) 0.1.0

-

Each of these return the 3×3 matrix representing a right-handed rotation of points in 3-dimensional space relative to the coordinate system through an angle of angle radians about the x, y and z axes respectively. They are used as a foundation for the more general Matrix.Rotation.

- - -

Matrix.Zero(n, m) 0.1.0

-

Returns a matrix with n rows and m columns, all the elements of which are zero.

- -

Instance methods

- - -

add(matrix) 0.1.0

-

Returns the matrix sum of the receiver and matrix. Thus, A.add(B) is equivalent to A + B. Returns null if the matrices are different sizes.

- - -

augment(matrix) 0.1.0

-

Returns the result of augmenting the receiver with matrix, that is, appending matrix to the right hand side of the receiver. Both matrices must have the same number of rows for this to work.

- -
var M = $M([
-  [8,3,0],
-  [4,4,2],
-  [9,1,5]
-]).augment(Matrix.I(3));
-
-// M is the matrix
-//    8 3 0 1 0 0
-//    4 4 2 0 1 0
-//    9 1 5 0 0 1
- -

matrix can also be a Vector, as long as it has the same number of elements as the receiver has rows. It will be appended to the receiver as an extra column on the right hand side.

- - -

canMultiplyFromLeft(matrix) 0.1.0

-

A.canMultiplyFromLeft(B) returns true iff AB is a mathematically valid expression. This is the case iff A has the same number of columns as B has rows. matrix can also be a Vector, as long as it has the same number of elements as the receiver has rows.

- - -

col(j) 0.1.0

-

Returns the jth column of the receiver as a Vector.

- - -

cols() 0.1.0

-

Returns the number of columns the receiver has.

- - -

det() 0.1.0

-

Alias for determinant.

- - -

determinant() 0.1.0

-

If the receiver is square, returns its determinant, otherwise returns null. Note that if the receiver is singular, this method will return exactly zero, with no rounding errors.

- - -

diagonal() 0.1.0

-

If the receiver is square, returns its leading-diagonal elements as a Vector. Otherwise, returns null.

- - -

dimensions() 0.1.0

-

Returns an object containing the receiver’s dimensions.

- -
var dims = Matrix.Zero(4,3).dimensions();
-// dims is {rows: 4, cols: 3}
- - -

dup() 0.1.0

-

Returns a copy of the receiver.

- - -

e(i, j) 0.1.0

-

A.e(i,j) returns the element Aij of matrix A, that is the element in the ith row and jth column. Indexes begin at 1, in agreement with mathematical notation.

- - -

eql(matrix) 0.1.0

-

Returns true iff matrix has all its elements equal to those of the receiver.

- - -

indexOf(x) 0.1.0

-

Reads the receiver’s elements row by row from left to right and returns an object containing the indeces of the first exact match. Returns null if no match is found.

- -
var foo = $M([
-  [0,9,4],
-  [9,5,8],
-  [1,5,3]
-]).indexOf(9);
-
-// foo is {row: 1, col: 2}
- - -

inspect() 0.1.0

-

Returns a string representation of the receiver, useful for debugging.

- -
alert(Matrix.I(4).inspect());
-
-// alerts:
-// [1, 0, 0, 0]
-// [0, 1, 0, 0]
-// [0, 0, 1, 0]
-// [0, 0, 0, 1]
- - -

inv() 0.1.0

-

Alias for inverse.

- - -

inverse() 0.1.0

-

Returns the matrix inverse of the receiver, if one exists. If the matrix is singular or not square, then null is returned. The inverse is computed using Gauss-Jordan elimination.

- - -

isSameSizeAs(matrix) 0.1.0

-

Returns true iff matrix has the same number of rows and columns as the receiver. matrix can also be a Vector, as long as it has the same number of elements as the receiver has rows.

- - -

isSingular() 0.1.0

-

Returns true iff the receiver is square and has zero determinant.

- - -

isSquare() 0.1.0

-

Returns true iff the receiver is square.

- - -

map(iterator) 0.1.0

-

Maps the receiver to another matrix by calling iterator on each element of the receiver in turn. iterator receives the row and column index of each element as second and third arguments. Some examples:

- -
// Square all the elements of a matrix:
-
-var A_sq = A.map(function(x) { return x * x; });
-
-// Determine whether a matrix is symmetric:
-
-var is_sym = (A.map(
-  function(x, i, j) { return (A.e(i,j) == A.e(j,i)) ? 1 : 0; }
-).indexOf(0) === null);
- - -

max() 0.1.0

-

Returns the value of the element of the receiver with the largest absolute value.

- - -

minor(i, j, n, m) 0.1.0

-

This method returns a matrix formed from a subset of the receiver’s elements. It selects elements beginning at row i and column j of the receiver, and returns a matrix with n rows and m columns. The selection wraps to the other side of the receiver if n or m is large enough. This is best illustrated by example:

- -
var M = $M([
-  [9,2,6,5],
-  [0,1,7,4],
-  [4,2,6,7],
-  [1,8,5,3]
-]);
-
-var A = M.minor(2,1,2,3);
-// 0 1 7
-// 4 2 6
-
-var B = M.minor(1,4,3,3);
-// 5 9 2
-// 4 0 1
-// 7 4 2
-
-// Augment M with itself
-var C = M.minor(1,1,4,8);
-// 9 2 6 5 9 2 6 5
-// 0 1 7 4 0 1 7 4
-// 4 2 6 7 4 2 6 7
-// 1 8 5 3 1 8 5 3
- - -

multiply(object) 0.1.0

-

If object is a matrix, then this method returns the result of multiplying the receiver by object in that order: A.multiply(B) means AB. If object is a Vector, then it is converted to a column matrix, multiplied by the receiver, and the result is returned as a Vector (this saves you having to call col(1) on the result). If object is a scalar, then the method returns a copy of the receiver with all its elements multiplied by object.

- -

This method is aliased as x.

- - -

rank() 0.1.0

-

Returns the receiver’s rank, which is the number of linearly independent rows/columns it contains.

- - -

rk() 0.1.0

-

Alias for rank.

- - -

round() 0.1.0

-

Returns a copy of the receiver with all its elements rounded to the nearest integer.

- - -

row(i) 0.1.0

-

Returns the ith row of the receiver as a Vector.

- - -

rows() 0.1.0

-

Returns the number of rows the receiver has.

- - -

setElements(elements) 0.1.0

-

Sets the receiver’s elements from the array elements. The element array’ top-level elements should be the rows, and each row is an array of values reading from left to right across the columns. See Matrix.create.

- - -

snapTo(x) 0.1.0

-

Returns a copy of the receiver in which any elements that differ from x by less than the value of Sylvester.precision are set exactly equal to x.

- - -

subtract(matrix) 0.1.0

-

Returns the result of subtracting matrix from the receiver. Thus, A.subtract(B) is equivalent to AB. Returns null if the matrices are different sizes.

- - -

toRightTriangular() 0.1.0

-

Returns a copy of the receiver converted to right triangular form. The conversion is done only by adding multiples of rows to other rows, so the determinant (if the matrix is square) is unchanged. This method can be used on non-square matrices, which lets you use it to solve sets of simultaneous equations. For example: solving the system of linear equations

- - - -

would be written as:

- -
var equations = $M([
-  [ 3,   2, -1,  1],
-  [ 2,  -2,  4, -2],
-  [-1, 0.5, -1,  0]
-]);
-
-var eqns = equations.toRightTriangular();
-
-var sol_z = eqns.e(3,4) / eqns.e(3,3);
-var sol_y = (eqns.e(2,4) - eqns.e(2,3)*sol_z) / eqns.e(2,2);
-var sol_x = (eqns.e(1,4) - eqns.e(1,3)*sol_z - eqns.e(1,2)*sol_y) / eqns.e(1,1);
- - -

toUpperTriangular() 0.1.0

-

Alias for toRightTriangular.

- - -

tr() 0.1.0

-

Alias for trace.

- - -

trace() 0.1.0

-

Returns the trace for square matrices, which is the sum of their leading-diagonal elements.

- - -

transpose() 0.1.0

-

Returns the matrix transpose of the receiver.

- - -

x(k) 0.1.0

-

Alias for multiply(k).

- - diff --git a/site/api/plane.php b/site/api/plane.php deleted file mode 100644 index 37f421b..0000000 --- a/site/api/plane.php +++ /dev/null @@ -1,113 +0,0 @@ - - - - - -

Class: Plane

- -

Sylvester version: 0.1.0 onwards

- -

Class methods: -create, -XY, -XZ, -YX, -YZ, -ZX, -ZY -

- -

Instance methods: -contains, -distanceFrom, -dup, -eql, -intersectionWith, -intersects, -isParallelTo, -isPerpendicularTo, -pointClosestTo, -reflectionIn, -rotate, -setVectors, -translate -

- -

Instance variables:

- - - -

Overview

- -

The Plane class is designed to model infinite flat planes in 3 dimensions.

- -

Class methods

- - -

Plane.create(anchor, v1 [, v2]) 0.1.0

-

Creates a new Plane instance with the given properties. If two arguments are supplied, v1 should be the normal to the plane. If three arguments, v1 and v2 should be directions of vectors in the plane, such that the normal is v1 × v2. The instance will not store these directions, only the calculated normal. anchor is any point in the plane, and the normal vector is normalized before being saved.

- - - - -

Plane.XY, Plane.XZ, Plane.YX, Plane.YZ, Plane.ZX, Plane.ZY 0.1.0

-

Predefined Plane instances representing the x-y, y-z and z-x planes.

- -

Instance methods

- - -

contains(obj) 0.1.0

-

Returns true iff obj is a Line or a Vector that lies in the receiver.

- - -

distanceFrom(obj) 0.1.0

-

Returns the shortest distance between the receiver and obj, which can be a Line, a Plane or a Vector.

- - -

dup() 0.1.0

-

Returns a copy of the receiver.

- - -

eql(plane) 0.1.0

-

Returns true iff plane and the receiver represent the same region of space. Their anchor and normal properties need not be identical for this to be the case. As long as plane.anchor is a point in the receiver, and plane.normal is (anti)parallel to the receiver’s normal, then this method returns true.

- - -

intersectionWith(obj) 0.1.0

-

Returns the unique intersection of the receiver with obj, which can be either a Line or a Plane. If obj is a Line, a Vector is returned. If obj is a Plane, a Line is returned. If no intersection exists, returns null.

- - -

intersects(obj) 0.1.0

-

Returns true iff the receiver has a unique intersection with obj, which can be either a Line or a Plane.

- - -

isParallelTo(obj) 0.1.0

-

Returns true iff the receiver and obj are parallel. If obj is a plane, their normal vectors can point in opposite directions – two planes with opposing normals represent the same set of points. If obj is a Line then its direction must be perpendicular to the receiver’s normal.

- - -

isPerpendicularTo(plane) 0.1.1

-

Returns true iff plane is perpendicular to the receiver.

- - -

pointClosestTo(point) 0.1.0

-

Returns a Vector representing the point on the receiver that is closest to the vector point.

- - -

reflectionIn(obj) 0.1.0

-

Returns a Plane representing the result of reflecting (inverting) the receiver in obj, which can be a Line, a Plane or a Vector.

- - -

rotate(angle, axis) 0.1.0

-

Returns the result of rotating the receiver by angle radians about the Line axis. The rotation is performed in a right-handed fashion about axis.direction.

- - -

setVectors(anchor, v1 [, v2]) 0.1.0

-

Sets the receiver’s properties accordingly. See create.

- - -

translate(vector) 0.1.0

-

Returns the result of translating the receiver by adding vector to its anchor property. vector can be a 2- or 3- dimensional array or Vector. If 2-dimensional, a zero third component will be added.

- - diff --git a/site/api/vector.php b/site/api/vector.php deleted file mode 100644 index 9011946..0000000 --- a/site/api/vector.php +++ /dev/null @@ -1,232 +0,0 @@ - - - - - -

Class: Vector

- -

Sylvester version: 0.1.0 onwards

- -

Class methods: -create, -i, -j, -k, -Random, -Zero -

- -

Instance methods: -add, -angleFrom, -cross, -dimensions, -distanceFrom, -dot, -dup, -e, -each, -eql, -indexOf, -inspect, -isAntiparallelTo, -isParallelTo, -isPerpendicularTo, -liesIn, -liesOn, -map, -max, -modulus, -multiply, -reflectionIn, -rotate, -round, -setElements, -snapTo, -subtract, -to3D, -toDiagonalMatrix, -toUnitVector, -x -

- -

Instance variables:

- - - -

Overview

- -

The Vector class is designed to model vectors in any number of dimensions. All the elements of a vector must be real numbers. Depending on what you’re using them for, it can be helpful to think of a vector either as a point in n-dimensional space, or as a line connecting the origin to that same point.

- -

Class methods

- - -

Vector.create(elements) 0.1.0

-

Creates and returns new Vector instance from the array elements. Example usage:

-
var v = Vector.create([6,2,9]);
-

This method is aliased as $V.

- - -

Vector.i, Vector.j, Vector.k 0.1.0

-

Predefined Vector instances representing the 3-dimensional i, j and k vectors respectively.

- - -

Vector.Random(n) 0.1.0

-

Returns a vector with n elements, each of which is a random number between 0 and 1.

- - -

Vector.Zero(n) 0.1.0

-

Returns a vector with n elements, all of which are zero.

- -

Instance methods

- - -

add(vector) 0.1.0

-

If the receiver and vector have the same number of elements, returns a Vector formed by adding them together. Otherwise, returns null.

- - -

angleFrom(vector) 0.1.0

-

Returns the angle in radians between vector and the receiver. The return value will always be between 0 and inclusive. If the vectors have unequal numbers of elements, null is returned.

- - -

cross(vector) 0.1.0

-

Returns the cross product (aka the vector product) of the receiver with vector, in the order in which they are written. For example, a.cross(b) is the same as the mathematical statement a × b. Both vectors must have three elements, otherwise this method returns null.

- - -

dimensions() 0.1.0

-

Returns the number of elements the receiver has – that is, the dimensionality of the vector space it inhabits.

- - -

distanceFrom(vector) 0.1.0

-

Returns the (always positive) distance of the receiver from vector. That is, a.distanceFrom(b) is equivalent to |ab|.

- - -

dot(vector) 0.1.0

-

Returns the value of the dot product (aka the scalar product) of the receiver with vector. That is, a.dot(b) is the same as ab. Returns null if the vectors have unequal dimensions.

- - -

dup() 0.1.0

-

Returns a copy of the receiver.

- - -

e(i) 0.1.0

-

Returns the ith element of the receiver. Element indexes begin at 1, not 0 like array indexes. This is consistent with mathematical notation.

- - -

each(iterator) 0.1.1

-

Calls iterator for each element of the receiver. iterator is passed the index (numbered from 1) of each element as the second argument. For example, the following alerts the index and value of each of the vector’s elements:

- -
$V([4,9,3,6]).each(function(x, i) {
-  alert(i + ': ' + x);
-});
-
-// Alerts: '1: 4', '2: 9', '3: 3', '4: 6'
- - -

eql(vector) 0.1.0

-

Returns true iff the receiver is equal to vector, that is, if all their elements are equal. See note on accuracy.

- - -

indexOf(x) 0.1.0

-

Returns the index position (numbered from 1, just as for e()) of the first element exactly equal to x. If no match is found, returns null.

- - -

inspect() 0.1.0

-

Returns a string representation of the receiver, useful for debugging purposes. Example:

-
alert($V([7,-2,5]).inspect())
-// alerts "[7, -2, 5]"
- - -

isAntiparallelTo(vector) 0.1.0

-

Returns true iff vector’s direction is exactly opposed to that of the receiver, that is, if the angle between them is π. See note on accuracy.

- - -

isParallelTo(vector) 0.1.0

-

Returns true iff vector’s direction is exactly aligned with that of the receiver, that is, if the angle between them is zero. See note on accuracy.

- - -

isPerpendicularTo(vector) 0.1.0

-

Returns true iff vector’s direction is perpendicular to that of the receiver, that is, if the angle between them is π/2. See note on accuracy.

- - -

liesIn(plane) 0.1.0

-

Returns true iff the receiver is a point in the given Plane. Only works on 3-dimensional vectors.

- - -

liesOn(line) 0.1.0

-

Returns true iff the receiver is a point on the given Line. Only works on 3-dimensional vectors.

- - -

map(iterator) 0.1.0

-

Maps the receiver to another vector by calling iterator with each element in turn. iterator is also passed the index (numbered from 1) of each element as the second argument. Some examples:

-
var a = $V([3,4,5]);
-
-// To square the elements of a
-var b = a.map(function(x) { return x * x; });
-
-// To add each element's index to its value
-var c = a.map(function(x, i) { return x + i; });
- - -

max() 0.1.0

-

Returns the element of the receiver with the largest absolute value. For example, $V([0,-6,5]).max() returns -6.

- - -

modulus() 0.1.0

-

Returns the modulus of the receiver, given by |v| = √( Σ vi² ).

- - -

multiply(k) 0.1.0

-

Returns the vector obtained by multiplying all the elements of the receiver by the scalar quantity k. Aliased as x(k).

- - -

reflectionIn(object) 0.1.0

-

Returns the vector that results from reflecting the receiver in object, which can be a Vector, a Line or a Plane. If object is a Vector, then a.reflectionIn(b) returns b + (ba). Otherwise, the same formula applies but b is the closest point on the line or plane to a.

- - -

rotate(angle, axis) 0.1.0

-

Returns a copy of the receiver rotated by angle radians about axis. If the receiver is a 2-vector then axis should also be a 2-vector, and the method returns the result of rotating the receiver about the point given by axis. The rotation is performed anticlockwise from the point of view of someone looking down on the x-y plane, so for example:

- -
var a = $V([10,5]);
-var b = $V([5,5]);
-
-var c = a.rotate(Math.PI/2, b);
-// c is the point (5,10)
- -

If the receiver is a 3-vector, then axis should be a Line, and the rotation is performed in a right-handed fashion around the line’s direction. Be careful that the line points in the right direction when using this method!

- - -

round() 0.1.0

-

Returns a copy of the receiver with all its elements rounded to the nearest integer.

- - -

setElements(els) 0.1.0

-

Sets the receiver’s elements property equal to the array els. Since version 0.1.1, the numericality of els’s elements is not checked for performance reasons. It is assumed you’ll be using this with numbers, and if you throw anything else in then most method calls won’t work.

- - -

snapTo(x) 0.1.0

-

Returns a copy of the receiver with any elements that differ from x by less than the value of Sylvester.precision set exactly equal to x. This can be useful for working around rounding errors.

- - -

subtract(vector) 0.1.0

-

If the receiver and vector have the same number of elements, returns a Vector formed by subtracting the latter from the former. Otherwise, returns null.

- - -

to3D() 0.1.0

-

If the receiver is 3-dimensional, it returns a copy of the receiver. If it is 2-dimensional, it returns a copy of the receiver with an additional third element, which is set to zero. For all other sizes, it returns null. Something is similar is done in many of the methods of the Line and Plane classes, although for performance reasons they don’t use this method.

- - -

toDiagonalMatrix() 0.1.0

-

Returns an n×n square Matrix, where n is the number of elements in the receiver, whose leading-diagonal elements are the elements of the receiver. All the off-diagonal elements are zero.

- - -

toUnitVector() 0.1.0

-

Returns a copy of the receiver, whose elements have been scaled such that the modulus of the new vector is equal to 1. If the receiver has zero modulus then a copy of it is returned unchanged.

- - -

x(k) 0.1.0

-

Alias for multiply(k).

- - diff --git a/site/apinav.php b/site/apinav.php deleted file mode 100644 index 65c7a9f..0000000 --- a/site/apinav.php +++ /dev/null @@ -1,6 +0,0 @@ - \ No newline at end of file diff --git a/site/config/compass.rb b/site/config/compass.rb new file mode 100644 index 0000000..6ec0dfa --- /dev/null +++ b/site/config/compass.rb @@ -0,0 +1,3 @@ +require "staticmatic/compass" + +project_type = :staticmatic \ No newline at end of file diff --git a/site/config/site.rb b/site/config/site.rb new file mode 100644 index 0000000..5f54328 --- /dev/null +++ b/site/config/site.rb @@ -0,0 +1,16 @@ +# Default is 3000 +# configuration.preview_server_port = 3000 + +# Default is localhost +# configuration.preview_server_host = "localhost" + +# Default is true +# When false .html & index.html get stripped off generated urls +# configuration.use_extensions_for_page_links = true + +# Default is an empty hash +# configuration.sass_options = {} + +# Default is an empty hash +# http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#options +# configuration.haml_options = {} \ No newline at end of file diff --git a/site/docs.php b/site/docs.php deleted file mode 100644 index 95bad1a..0000000 --- a/site/docs.php +++ /dev/null @@ -1,25 +0,0 @@ - - - - - -

API Documentation

- -

There a couple of things that don’t really fit in to any of the class references listed above. The first one is that there exist a series of shorthand functions for creating objects in Sylvester. They are:

- - - -

Note on accuracy

- -

The second is that a lot of functionality in Sylvester relies on computing various quantities and comparing them to zero. Rounding errors on floating point numbers mean that quantities that should be zero can actually be a bit off. Therefore, quantities are compared to the value of Sylvester.precision – if the absolute value of x is less than this number, x is considered to be equal to zero. By default, Sylvester.precision is set to 1e-6, but you can just set the value yourself if you want to be more strict – it should ideally be several orders of magnitude smaller than the vector/matrix elements you’re working with.

- -

Null return values

- -

Finally, as a general rule, trying to compute something that is not mathematically meaningful (like multiplying matrices with incompatible sizes) will produce a result of null. Similarly, trying to compute something that does not exist, such as the intersection of two parallel lines, will return null.

- - diff --git a/site/footer.php b/site/footer.php deleted file mode 100644 index 1c0cfd5..0000000 --- a/site/footer.php +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - diff --git a/site/header.php b/site/header.php deleted file mode 100644 index 35701d8..0000000 --- a/site/header.php +++ /dev/null @@ -1,26 +0,0 @@ - - - - - -Sylvester - <?php echo $title; ?> - - - - - -
- - - -
-
- diff --git a/site/index.php b/site/index.php deleted file mode 100644 index bfd1623..0000000 --- a/site/index.php +++ /dev/null @@ -1,63 +0,0 @@ - - - -

What is it?

- -

Sylvester is a JavaScript library designed to let you do mathematics with vectors and matrices without having to write lots of loops and throw piles of arrays around. It includes classes for modelling vectors and matrices in any number of dimensions, and for modelling infinite lines and planes in 3-dimensional space. It lets you write object-oriented easy-to-read code that mirrors the maths it represents. For example, it lets you multiply vectors together:

- -
var V1 = $V([3,4,5]);
-var V2 = $V([9,-3,0]);
-
-var d = V1.dot(V2);
-// d is 15
-
-var c = V1.cross(V2);
-// c is the vector (15,45,-45)
- -

and multiply matrices:

- -
var M1 = $M([
-  [1,7,3],
-  [9,4,0],
-  [2,7,1]
-]);
-
-var M2 = $M([
-  [6,2,8],
-  [9,1,3],
-  [0,7,6]
-]);
-
-var M = M1.x(M2);
-
-// M is the matrix
-//   69 30 47
-//   90 22 84
-//   75 18 43
- -

and any number of other useful arithmetic and geometric operations. For more information, take a look at the API documentation.

- - -

Download version 0.1.3

- -

The download is a ZIP archive containing the following files:

- -
    -
  • sylvester.src.js – the full source code, with comments (43.8 kb)
  • -
  • sylvester.js – the packed version (13.2 kb)
  • -
  • sylvester.js.gz – a gzipped copy of the packed version (5.0 kb), so you can serve compressed code
  • -
  • CHANGELOG.txt
  • -
- -

Sylvester is © 2007 James Coglan, and is released under the MIT license.

- -

0.1 is the first released version. It consists of the Vector, Matrix, Line and Plane classes – a useful mathematical base on which to build. Later releases will add components for more specific geometric modelling functionality, building towards a feature-complete 1.0 release. For news and announcements, head over to my blog.

- -

Bug reports and feature requests are both welcome at james@jcoglan.com. I am working on extending Sylvester to support line segments, flat polygons and 3-dimensional objects, with a view to building a 3D geometry framework with a rendering layer for the <canvas> element.

- -

Compatibility

- -

Sylvester has been successfully tested in Firefox 1.0, 1.5 and 2.0, Internet Explorer 5.5, 6.0 and 7.0, Opera 7, 8 and 9, and Safari 3 for -Windows.

- diff --git a/site/docs.gif b/site/site/docs.gif similarity index 100% rename from site/docs.gif rename to site/site/docs.gif diff --git a/site/download.gif b/site/site/download.gif similarity index 100% rename from site/download.gif rename to site/site/download.gif diff --git a/site/header.gif b/site/site/header.gif similarity index 100% rename from site/header.gif rename to site/site/header.gif diff --git a/site/style.css b/site/site/style.css similarity index 95% rename from site/style.css rename to site/site/style.css index 00a117d..b17c110 100644 --- a/site/style.css +++ b/site/site/style.css @@ -145,7 +145,7 @@ ins { ================================================================*/ #header { - background: url(header.gif) center top repeat-x; + background: url(/header.gif) center top repeat-x; margin: 0; height: 150px; } @@ -155,7 +155,7 @@ ins { } #header h1 { - background: url(title.gif) left top no-repeat; + background: url(/title.gif) left top no-repeat; margin: 0; position: absolute; left: 0; @@ -222,12 +222,12 @@ ins { } #nav-home { - background: url(download.gif) left top no-repeat; + background: url(/download.gif) left top no-repeat; right: 174px; } #nav-docs { - background: url(docs.gif) left top no-repeat; + background: url(/docs.gif) left top no-repeat; right: 81px; } diff --git a/site/title.gif b/site/site/title.gif similarity index 100% rename from site/title.gif rename to site/site/title.gif diff --git a/site/src/layouts/default.haml b/site/src/layouts/default.haml new file mode 100644 index 0000000..965b4f9 --- /dev/null +++ b/site/src/layouts/default.haml @@ -0,0 +1,48 @@ +:plain + + + + + Sylvester + + + + +
+ + + +
+
+ += yield + +:plain +
+
+ + + +
+ + + + + + diff --git a/site/src/pages/api/line.haml b/site/src/pages/api/line.haml new file mode 100644 index 0000000..2253891 --- /dev/null +++ b/site/src/pages/api/line.haml @@ -0,0 +1,201 @@ += partial 'api_navigation' + +:plain +

Class: Line

+ +

Sylvester version: 0.1.0 onwards

+ +

Class methods: + create, + X, + Y, + Z +

+ +

Instance methods: + contains, + distanceFrom, + dup, + eql, + intersectionWith, + intersects, + isParallelTo, + liesIn, + pointClosestTo, + reflectionIn, + rotate, + setVectors, + translate +

+ +

Instance variables:

+ +
    +
  • anchor – a 3D + Vector corresponding to a + point on the line
  • +
  • direction – a + normalized 3D + Vector representing the + line’s direction
  • +
+ +

Overview

+ +

The Line class is designed to model infinite straight lines in + 3 dimensions. It is possible to specify lines using 2D + Vectors, but they will be stored + in the Line instance as 3D vectors whose third element is zero. + Lines created in this way are thus 3D lines confined to the + x-y plane. You can also specify 2D vectors as + arguments for many of Line’s instance methods – + again, these will be interpreted as 3D vectors with a zero third + component.

+ +

Class methods

+ + +

Line.create(anchor, direction) 0.1.0

+ +

Creates a Line instance with the specified properties. + anchor and direction can each be either 2- or + 3-dimensional arrays or Vectors, + and they will be stored in the Line’s properties as 3D + vectors. (The thrid element will be zero if a 2D vector was supplied.) + direction will be + normalized before being saved. + The following are all fine:

+ +
var A = Line.create([4,8], [1,5]);
+  var B = Line.create($V([4,8]), $V([1,5]));
+  var C = Line.create([9,2,5], $V([8,2,0]));
+ +

For situations where x, y and z are used to refer to + co-ordinates, x corresponds to the first element + of a vector, y the second and z the third.

+ +

This method is aliased as $L.

+ + +

Line.X, Line.Y, Line.Z 0.1.0

+ +

Predefined Line instances representing the x, y and z axes respectively.

+ +

Instance methods

+ + +

contains(point) 0.1.0

+ +

Returns true iff the vector point is a point that + lies on the receiver.

+ + +

distanceFrom(obj) 0.1.0

+ +

Returns the shortest distance between the receiver and obj, + which can be a Line, a + Plane or a + Vector. If a + Plane, this method will only + return a non-zero value if the receiver is parallel to obj.

+ + +

dup() 0.1.0

+ +

Returns a copy of the receiver.

+ + +

eql(line) 0.1.0

+ +

Returns true iff line is equal to the receiver, + that is, if they both represent the same region of space. Their + anchor and direction properties do not have to be + identical for this to be the case. As long as line.anchor is a + point on the receiver, and line.direction is (anti)parallel to + the receiver’s direction, then this method returns + true.

+ + +

intersectionWith(obj) 0.1.0

+ +

Returns a Vector representing + the unique point of intersection of the receiver with obj, + which can be either a Line or a + Plane. If no such point exists, + returns null.

+ + +

intersects(obj) 0.1.0

+ +

Returns true iff the receiver has a unique point of + intersection with obj, which can be either a Line + or a Plane.

+ + +

isParallelTo(line) 0.1.0

+ +

Returns true iff the receiver and line are + parallel lines. Their direction vectors can point in opposite directions + – two lines with opposing directions represent the same set of + points.

+ + +

liesIn(plane) 0.1.0

+ +

Returns true iff the receiver lies in the given + plane.

+ + +

pointClosestTo(obj) 0.1.0

+ +

Returns a Vector representing + the point on the receiver that is closest to obj, which can be + either a Vector or a Line. If a Line, + returns null if the lines are parallel – there is no + unique closest point.

+ + +

reflectionIn(obj) 0.1.0

+ +

Returns a Line representing the result of reflecting + (inverting) the receiver in obj, which can be a + Line, a Plane or a + Vector.

+ + +

rotate(angle, axis) 0.1.0

+ +

Returns the result of rotating the receiver by angle radians + about axis, which can be a Line, or a + Vector. If a Vector, + the receiver is rotated about a line whose anchor is axis and + whose direction is [0, 0, 1]. This is useful for working in + 2D:

+ +
var L = Line.X.rotate(Math.PI/2, $V([5,0]));
+  
+  var test = L.eql(Line.create([5,0], [0,1]));
+  // Returns true - the 90-degree rotation leaves Line.X parallel to the y axis
+ +

Be careful when working with axis as a Line + – rotations are performed in a right-handed fashion about the + line’s direction.

+ + +

setVectors(anchor, direction) 0.1.0

+ +

Sets the receiver’s properties accordingly. See + create.

+ + +

translate(vector) 0.1.0

+ +

Returns the result of translating the receiver by adding + vector to its anchor property. vector + can be a 2- or 3- dimensional array or + Vector. If 2-dimensional, a zero + third component will be added.

diff --git a/site/src/pages/api/matrix.haml b/site/src/pages/api/matrix.haml new file mode 100644 index 0000000..68cc6e8 --- /dev/null +++ b/site/src/pages/api/matrix.haml @@ -0,0 +1,486 @@ += partial 'api_navigation' + +:plain +

Class: Matrix

+ +

Sylvester version: 0.1.0 onwards

+ +

Class methods: + create, + Diagonal, + I, + Random, + Rotation, + RotationX, + RotationY, + RotationZ, + Zero +

+ +

Instance methods: + add, + augment, + canMultiplyFromLeft, + col, + cols, + det, + determinant, + diagonal, + dimensions, + dup, + e, + eql, + indexOf, + inspect, + inv, + inverse, + isSameSizeAs, + isSingular, + isSquare, + map, + max, + minor, + multiply, + rank, + rk, + round, + row, + rows, + setElements, + snapTo, + subtract, + toRightTriangular, + toUpperTriangular, + tr, + trace, + transpose, + x +

+ +

Instance variables:

+ +
    +
  • elements – a nested array containing the matrix’s elements
  • +
+ +

Overview

+ +

The Matrix class is designed to model real matrices in any + number of dimensions. All the elements in a matrix must be real numbers.

+ +

Class methods

+ + +

Matrix.create(elements) 0.1.0

+ +

Creates and returns a new Matrix instance from the array + elements. elements should be a nested array: the + top level array is the rows, and each row is an array of elements. This + means you write out a matrix in code in the same orientation you would on + paper.

+ +
var M = $M([
+    [8,3,9],
+    [2,0,7],
+    [1,9,3]
+  ]);
+ +

Every row must have the same number of elements, otherwise the method will + return null.

+ +

This method is aliased as $M.

+ + +

Matrix.Diagonal(elements) 0.1.0

+ +

Returns a square matrix whose leading-diagonal elements are the values in + the array elements, and whose off-diagonal elements are zero.

+ +
var D = Matrix.Diagonal([4,3,7,1]);
+  
+  // D is the matrix
+  //    4 0 0 0
+  //    0 3 0 0
+  //    0 0 7 0
+  //    0 0 0 1
+ + +

Matrix.I(n) 0.1.0

+ +

Returns the n×n identity matrix.

+ + +

Matrix.Random(n, m) 0.1.0

+ +

Returns a matrix with n rows and m columns, all + the elements of which are random numbers between 0 and 1.

+ + +

Matrix.Rotation(angle [, axis]) 0.1.0

+ +

If called with only one argument, returns the 2×2 matrix for an + anticlockwise rotation of angle radians about the origin. That + is, vectors are rotated anticlockwise with respect to the coordinate system, + not the other way round.

+ +

If called with two arguments, returns the 3×3 matrix for a + right-handed rotation of angle radians about the axis given by + the 3-vector axis, keeping the origin fixed.

+ + +

Matrix.RotationX(angle), Matrix.RotationY(angle), Matrix.RotationZ(angle) 0.1.0

+ +

Each of these return the 3×3 matrix representing a right-handed + rotation of points in 3-dimensional space relative to the coordinate system + through an angle of angle radians about the x, y and z axes respectively. They are used as a foundation for + the more general Matrix.Rotation.

+ + +

Matrix.Zero(n, m) 0.1.0

+ +

Returns a matrix with n rows and m columns, all + the elements of which are zero.

+ +

Instance methods

+ + +

add(matrix) 0.1.0

+ +

Returns the matrix sum of the receiver and matrix. Thus, + A.add(B) is equivalent to A + + B. Returns null if the matrices are different + sizes.

+ + +

augment(matrix) 0.1.0

+ +

Returns the result of augmenting the receiver with matrix, + that is, appending matrix to the right hand side of the + receiver. Both matrices must have the same number of rows for this to + work.

+ +
var M = $M([
+    [8,3,0],
+    [4,4,2],
+    [9,1,5]
+  ]).augment(Matrix.I(3));
+  
+  // M is the matrix
+  //    8 3 0 1 0 0
+  //    4 4 2 0 1 0
+  //    9 1 5 0 0 1
+ +

matrix can also be a + Vector, as long as it has the + same number of elements as the receiver has rows. It will be appended to the + receiver as an extra column on the right hand side.

+ + +

canMultiplyFromLeft(matrix) 0.1.0

+ +

A.canMultiplyFromLeft(B) returns true iff + AB is a mathematically valid expression. This is the + case iff A has the same number of columns as B has rows. matrix can also be a + Vector, as long as it has the + same number of elements as the receiver has rows.

+ + +

col(j) 0.1.0

+ +

Returns the jth column of the receiver as a + Vector.

+ + +

cols() 0.1.0

+ +

Returns the number of columns the receiver has.

+ + +

det() 0.1.0

+ +

Alias for determinant.

+ + +

determinant() 0.1.0

+ +

If the receiver is square, returns its determinant, otherwise returns + null. Note that if the receiver is singular, this method will + return exactly zero, with no rounding errors.

+ + +

diagonal() 0.1.0

+ +

If the receiver is square, returns its leading-diagonal elements as a + Vector. Otherwise, returns + null.

+ + +

dimensions() 0.1.0

+ +

Returns an object containing the receiver’s dimensions.

+ +
var dims = Matrix.Zero(4,3).dimensions();
+  // dims is {rows: 4, cols: 3}
+ + +

dup() 0.1.0

+ +

Returns a copy of the receiver.

+ + +

e(i, j) 0.1.0

+ +

A.e(i,j) returns the element Aij of matrix A, + that is the element in the ith row and jth column. + Indexes begin at 1, in agreement with mathematical notation.

+ + +

eql(matrix) 0.1.0

+ +

Returns true iff matrix has all its elements + equal to those of the receiver.

+ + +

indexOf(x) 0.1.0

+ +

Reads the receiver’s elements row by row from left to right and + returns an object containing the indeces of the first exact match. Returns + null if no match is found.

+ +
var foo = $M([
+    [0,9,4],
+    [9,5,8],
+    [1,5,3]
+  ]).indexOf(9);
+  
+  // foo is {row: 1, col: 2}
+ + +

inspect() 0.1.0

+ +

Returns a string representation of the receiver, useful for debugging.

+ +
alert(Matrix.I(4).inspect());
+  
+  // alerts:
+  // [1, 0, 0, 0]
+  // [0, 1, 0, 0]
+  // [0, 0, 1, 0]
+  // [0, 0, 0, 1]
+ + +

inv() 0.1.0

+ +

Alias for inverse.

+ + +

inverse() 0.1.0

+ +

Returns the matrix inverse of the receiver, if one exists. If the matrix is + singular or not square, then null is returned. The inverse is + computed using + Gauss-Jordan + elimination.

+ + +

isSameSizeAs(matrix) 0.1.0

+ +

Returns true iff matrix has the same number of + rows and columns as the receiver. matrix can also be a + Vector, as long as it has the + same number of elements as the receiver has rows.

+ + +

isSingular() 0.1.0

+ +

Returns true iff the receiver is square and has zero + determinant.

+ + +

isSquare() 0.1.0

+ +

Returns true iff the receiver is square.

+ + +

map(iterator) 0.1.0

+ +

Maps the receiver to another matrix by calling iterator on + each element of the receiver in turn. iterator receives the row + and column index of each element as second and third arguments. Some + examples:

+ +
// Square all the elements of a matrix:
+  
+  var A_sq = A.map(function(x) { return x * x; });
+  
+  // Determine whether a matrix is symmetric:
+  
+  var is_sym = (A.map(
+    function(x, i, j) { return (A.e(i,j) == A.e(j,i)) ? 1 : 0; }
+  ).indexOf(0) === null);
+ + +

max() 0.1.0

+ +

Returns the value of the element of the receiver with the largest absolute + value.

+ + +

minor(i, j, n, m) 0.1.0

+ +

This method returns a matrix formed from a subset of the receiver’s + elements. It selects elements beginning at row i and column + j of the receiver, and returns a matrix with n + rows and m columns. The selection wraps to the other side of + the receiver if n or m is large enough. This is + best illustrated by example:

+ +
var M = $M([
+    [9,2,6,5],
+    [0,1,7,4],
+    [4,2,6,7],
+    [1,8,5,3]
+  ]);
+  
+  var A = M.minor(2,1,2,3);
+  // 0 1 7
+  // 4 2 6
+  
+  var B = M.minor(1,4,3,3);
+  // 5 9 2
+  // 4 0 1
+  // 7 4 2
+  
+  // Augment M with itself
+  var C = M.minor(1,1,4,8);
+  // 9 2 6 5 9 2 6 5
+  // 0 1 7 4 0 1 7 4
+  // 4 2 6 7 4 2 6 7
+  // 1 8 5 3 1 8 5 3
+ + +

multiply(object) 0.1.0

+ +

If object is a matrix, then this method returns the result of + multiplying the receiver by object in that order: + A.multiply(B) means AB. If + object is a Vector, + then it is converted to a column matrix, multiplied by the receiver, and the + result is returned as a Vector + (this saves you having to call col(1) on the result). If + object is a scalar, then the method returns a copy of the + receiver with all its elements multiplied by object.

+ +

This method is aliased as x.

+ + +

rank() 0.1.0

+ +

Returns the receiver’s rank, which is the number of linearly + independent rows/columns it contains.

+ + +

rk() 0.1.0

+ +

Alias for rank.

+ + +

round() 0.1.0

+ +

Returns a copy of the receiver with all its elements rounded to the nearest + integer.

+ + +

row(i) 0.1.0

+ +

Returns the ith row of the receiver as a + Vector.

+ + +

rows() 0.1.0

+ +

Returns the number of rows the receiver has.

+ + +

setElements(elements) 0.1.0

+ +

Sets the receiver’s elements from the array elements. + The element array’ top-level elements should be the rows, and each row + is an array of values reading from left to right across the columns. See + Matrix.create.

+ + +

snapTo(x) 0.1.0

+ +

Returns a copy of the receiver in which any elements that differ from + x by less than the value of Sylvester.precision + are set exactly equal to x.

+ + +

subtract(matrix) 0.1.0

+ +

Returns the result of subtracting matrix from the receiver. + Thus, A.subtract(B) is equivalent to A + − B. Returns null if the matrices are + different sizes.

+ + +

toRightTriangular() 0.1.0

+ +

Returns a copy of the receiver converted to + right triangular + form. The conversion is done only by adding multiples of rows to other + rows, so the determinant (if the matrix is square) is unchanged. This method + can be used on non-square matrices, which lets you use it to solve sets of + simultaneous equations. For example: solving the system of linear + equations

+ +
    +
  • 3x + 2yz = 1
  • +
  • 2x − 2y + 4z = −2
  • +
  • x + ½yz = 0
  • +
+ +

would be written as:

+ +
var equations = $M([
+    [ 3,   2, -1,  1],
+    [ 2,  -2,  4, -2],
+    [-1, 0.5, -1,  0]
+  ]);
+  
+  var eqns = equations.toRightTriangular();
+  
+  var sol_z = eqns.e(3,4) / eqns.e(3,3);
+  var sol_y = (eqns.e(2,4) - eqns.e(2,3)*sol_z) / eqns.e(2,2);
+  var sol_x = (eqns.e(1,4) - eqns.e(1,3)*sol_z - eqns.e(1,2)*sol_y) / eqns.e(1,1);
+ + +

toUpperTriangular() 0.1.0

+ +

Alias for toRightTriangular.

+ + +

tr() 0.1.0

+ +

Alias for trace.

+ + +

trace() 0.1.0

+ +

Returns the trace for square matrices, which is the sum of their + leading-diagonal elements.

+ + +

transpose() 0.1.0

+ +

Returns the matrix transpose of the receiver.

+ + +

x(k) 0.1.0

+ +

Alias for multiply(k).

diff --git a/site/src/pages/api/plane.haml b/site/src/pages/api/plane.haml new file mode 100644 index 0000000..7a8ddb4 --- /dev/null +++ b/site/src/pages/api/plane.haml @@ -0,0 +1,172 @@ += partial 'api_navigation' + +:plain +

Class: Plane

+ +

Sylvester version: 0.1.0 onwards

+ +

Class methods: + create, + XY, + XZ, + YX, + YZ, + ZX, + ZY +

+ +

Instance methods: + contains, + distanceFrom, + dup, + eql, + intersectionWith, + intersects, + isParallelTo, + isPerpendicularTo, + pointClosestTo, + reflectionIn, + rotate, + setVectors, + translate +

+ +

Instance variables:

+ +
    +
  • anchor – a 3D + Vector corresponding to a + point in the plane
  • +
  • normal – a + normalized 3D + Vector perpendicular to the + plane
  • +
+ +

Overview

+ +

The Plane class is designed to model infinite flat planes in 3 + dimensions.

+ +

Class methods

+ + +

Plane.create(anchor, v1 [, v2]) 0.1.0

+ +

Creates a new Plane instance with the given properties. If two + arguments are supplied, v1 should be the normal to the plane. + If three arguments, v1 and v2 should be directions + of vectors in the plane, such that the normal is v1 × v2. The + instance will not store these directions, only the calculated normal. + anchor is any point in the plane, and the normal vector is + normalized before being saved.

+ + +

Plane.XY, Plane.XZ, Plane.YX, Plane.YZ, Plane.ZX, Plane.ZY 0.1.0

+ +

Predefined Plane instances representing the x-y, y-z and z-x planes.

+ +

Instance methods

+ + +

contains(obj) 0.1.0

+ +

Returns true iff obj is a + Line or a + Vector that lies in the + receiver.

+ + +

distanceFrom(obj) 0.1.0

+ +

Returns the shortest distance between the receiver and obj, + which can be a Line, a + Plane or a Vector.

+ + +

dup() 0.1.0

+ +

Returns a copy of the receiver.

+ + +

eql(plane) 0.1.0

+ +

Returns true iff plane and the receiver represent + the same region of space. Their anchor and normal + properties need not be identical for this to be the case. As long as + plane.anchor is a point in the receiver, and + plane.normal is (anti)parallel to the receiver’s normal, + then this method returns true.

+ + +

intersectionWith(obj) 0.1.0

+ +

Returns the unique intersection of the receiver with obj, + which can be either a Line or a + Plane. If obj is a Line, a + Vector is returned. If obj is a Plane, + a Line is returned. If no intersection exists, returns + null.

+ + +

intersects(obj) 0.1.0

+ +

Returns true iff the receiver has a unique intersection with + obj, which can be either a + Line or a Plane.

+ + +

isParallelTo(obj) 0.1.0

+ +

Returns true iff the receiver and obj are + parallel. If obj is a plane, their normal vectors can point in + opposite directions – two planes with opposing normals represent the + same set of points. If obj is a + Line then its direction must be + perpendicular to the receiver’s normal.

+ + +

isPerpendicularTo(plane) 0.1.1

+ +

Returns true iff plane is perpendicular to the + receiver.

+ + +

pointClosestTo(point) 0.1.0

+ +

Returns a Vector representing + the point on the receiver that is closest to the vector point.

+ + +

reflectionIn(obj) 0.1.0

+ +

Returns a Plane representing the result of reflecting + (inverting) the receiver in obj, which can be a + Line, a Plane or a + Vector.

+ + +

rotate(angle, axis) 0.1.0

+ +

Returns the result of rotating the receiver by angle radians + about the Line axis. + The rotation is performed in a right-handed fashion about + axis.direction.

+ + +

setVectors(anchor, v1 [, v2]) 0.1.0

+ +

Sets the receiver’s properties accordingly. See + create.

+ + +

translate(vector) 0.1.0

+ +

Returns the result of translating the receiver by adding + vector to its anchor property. vector + can be a 2- or 3- dimensional array or + Vector. If 2-dimensional, a zero + third component will be added.

diff --git a/site/src/pages/api/vector.haml b/site/src/pages/api/vector.haml new file mode 100644 index 0000000..08c67c9 --- /dev/null +++ b/site/src/pages/api/vector.haml @@ -0,0 +1,354 @@ += partial 'api_navigation' + +:plain +

Class: Vector

+ +

Sylvester version: 0.1.0 onwards

+ +

Class methods: + create, + i, + j, + k, + Random, + Zero +

+ +

Instance methods: + add, + angleFrom, + cross, + dimensions, + distanceFrom, + dot, + dup, + e, + each, + eql, + indexOf, + inspect, + isAntiparallelTo, + isParallelTo, + isPerpendicularTo, + liesIn, + liesOn, + map, + max, + modulus, + multiply, + reflectionIn, + rotate, + round, + setElements, + snapTo, + subtract, + to3D, + toDiagonalMatrix, + toUnitVector, + x +

+ +

Instance variables:

+ +
    +
  • elements – an array containing the vector’s + elements
  • +
+ +

Overview

+ +

The Vector class is designed to model vectors in any number of + dimensions. All the elements of a vector must be real numbers. Depending on + what you’re using them for, it can be helpful to think of a vector + either as a point in n-dimensional space, or as a line connecting the origin + to that same point.

+ +

Class methods

+ + +

Vector.create(elements) 0.1.0

+ +

Creates and returns new Vector instance from the array + elements. Example usage:

+ +
var v = Vector.create([6,2,9]);
+ +

This method is aliased as $V.

+ + +

Vector.i, Vector.j, Vector.k 0.1.0

+ +

Predefined Vector instances representing the 3-dimensional + i, j and k + vectors respectively.

+ + +

Vector.Random(n) 0.1.0

+ +

Returns a vector with n elements, each of which is a random + number between 0 and 1.

+ + +

Vector.Zero(n) 0.1.0

+ +

Returns a vector with n elements, all of which are zero.

+ +

Instance methods

+ + +

add(vector) 0.1.0

+ +

If the receiver and vector have the same number of elements, + returns a Vector formed by adding them together. Otherwise, + returns null.

+ + +

angleFrom(vector) 0.1.0

+ +

Returns the angle in radians between vector and the receiver. + The return value will always be between 0 and + inclusive. If the vectors have unequal numbers of elements, null + is returned.

+ + +

cross(vector) 0.1.0

+ +

Returns the cross product (aka the vector product) of the receiver with + vector, in the order in which they are written. For example, + a.cross(b) is the same as the mathematical statement a × b. Both vectors must have three + elements, otherwise this method returns null.

+ + +

dimensions() 0.1.0

+ +

Returns the number of elements the receiver has – that is, the + dimensionality of the vector space it inhabits.

+ + +

distanceFrom(vector) 0.1.0

+ +

Returns the (always positive) distance of the receiver from + vector. That is, a.distanceFrom(b) is equivalent + to |ab|.

+ + +

dot(vector) 0.1.0

+ +

Returns the value of the dot product (aka the scalar product) of the + receiver with vector. That is, a.dot(b) is the + same as ab. Returns + null if the vectors have unequal dimensions.

+ + +

dup() 0.1.0

+ +

Returns a copy of the receiver.

+ + +

e(i) 0.1.0

+ +

Returns the ith element of the receiver. Element indexes begin + at 1, not 0 like array indexes. This is consistent with mathematical + notation.

+ + +

each(iterator) 0.1.1

+ +

Calls iterator for each element of the receiver. + iterator is passed the index (numbered from 1) of each element + as the second argument. For example, the following alerts the index and + value of each of the vector’s elements:

+ +
$V([4,9,3,6]).each(function(x, i) {
+    alert(i + ': ' + x);
+  });
+  
+  // Alerts: '1: 4', '2: 9', '3: 3', '4: 6'
+ + +

eql(vector) 0.1.0

+ +

Returns true iff the receiver is equal to vector, + that is, if all their elements are equal. See note on + accuracy.

+ + +

indexOf(x) 0.1.0

+ +

Returns the index position (numbered from 1, just as for + e()) of the first element exactly equal to + x. If no match is found, returns null.

+ + +

inspect() 0.1.0

+ +

Returns a string representation of the receiver, useful for debugging + purposes. Example:

+ +
alert($V([7,-2,5]).inspect())
+  // alerts "[7, -2, 5]"
+ + +

isAntiparallelTo(vector) 0.1.0

+ +

Returns true iff vector’s direction is + exactly opposed to that of the receiver, that is, if the angle between them + is π. See note on + accuracy.

+ + +

isParallelTo(vector) 0.1.0

+ +

Returns true iff vector’s direction is + exactly aligned with that of the receiver, that is, if the angle between + them is zero. See note on accuracy.

+ + +

isPerpendicularTo(vector) 0.1.0

+ +

Returns true iff vector’s direction is + perpendicular to that of the receiver, that is, if the angle between them is + π/2. See note on + accuracy.

+ + +

liesIn(plane) 0.1.0

+ +

Returns true iff the receiver is a point in the given + Plane. Only works on + 3-dimensional vectors.

+ + +

liesOn(line) 0.1.0

+ +

Returns true iff the receiver is a point on the given + Line. Only works on 3-dimensional + vectors.

+ + +

map(iterator) 0.1.0

+ +

Maps the receiver to another vector by calling iterator with + each element in turn. iterator is also passed the index + (numbered from 1) of each element as the second argument. Some examples:

+ +
var a = $V([3,4,5]);
+  
+  // To square the elements of a
+  var b = a.map(function(x) { return x * x; });
+  
+  // To add each element's index to its value
+  var c = a.map(function(x, i) { return x + i; });
+ + +

max() 0.1.0

+ +

Returns the element of the receiver with the largest absolute value. For + example, $V([0,-6,5]).max() returns -6.

+ + +

modulus() 0.1.0

+ +

Returns the modulus of the receiver, given by |v| + = √( Σ vi² ).

+ + +

multiply(k) 0.1.0

+ +

Returns the vector obtained by multiplying all the elements of the receiver + by the scalar quantity k. Aliased as + x(k).

+ + +

reflectionIn(object) 0.1.0

+ +

Returns the vector that results from reflecting the receiver in + object, which can be a Vector, a + Line or a + Plane. If object is + a Vector, then a.reflectionIn(b) returns b + (ba). Otherwise, the + same formula applies but b is the closest point on the + line or plane to a.

+ + +

rotate(angle, axis) 0.1.0

+ +

Returns a copy of the receiver rotated by angle radians about + axis. If the receiver is a 2-vector then axis + should also be a 2-vector, and the method returns the result of rotating the + receiver about the point given by axis. The rotation is + performed anticlockwise from the point of view of someone looking down on + the x-y plane, so for example:

+ +
var a = $V([10,5]);
+  var b = $V([5,5]);
+  
+  var c = a.rotate(Math.PI/2, b);
+  // c is the point (5,10)
+ +

If the receiver is a 3-vector, then axis should be a + Line, and the rotation is + performed in a right-handed fashion around the line’s direction. Be + careful that the line points in the right direction when using this method!

+ + +

round() 0.1.0

+ +

Returns a copy of the receiver with all its elements rounded to the nearest + integer.

+ + +

setElements(els) 0.1.0

+ +

Sets the receiver’s elements property equal to the array + els. Since version 0.1.1, the numericality of + els’s elements is not checked for performance reasons. It + is assumed you’ll be using this with numbers, and if you throw + anything else in then most method calls won’t work.

+ + +

snapTo(x) 0.1.0

+ +

Returns a copy of the receiver with any elements that differ from + x by less than the value of Sylvester.precision + set exactly equal to x. This can be useful for working around + rounding errors.

+ + +

subtract(vector) 0.1.0

+ +

If the receiver and vector have the same number of elements, + returns a Vector formed by subtracting the latter from the + former. Otherwise, returns null.

+ + +

to3D() 0.1.0

+ +

If the receiver is 3-dimensional, it returns a copy of the receiver. If it + is 2-dimensional, it returns a copy of the receiver with an additional third + element, which is set to zero. For all other sizes, it returns + null. Something is similar is done in many of the methods of + the Line and + Plane classes, although for + performance reasons they don’t use this method.

+ + +

toDiagonalMatrix() 0.1.0

+ +

Returns an n×n square + Matrix, where n is + the number of elements in the receiver, whose leading-diagonal elements are + the elements of the receiver. All the off-diagonal elements are zero.

+ + +

toUnitVector() 0.1.0

+

Returns a copy of the receiver, whose elements have been scaled such that + the modulus of the new vector is equal + to 1. If the receiver has zero modulus then a copy of it is returned + unchanged.

+ + +

x(k) 0.1.0

+

Alias for multiply(k).

diff --git a/site/src/pages/docs.haml b/site/src/pages/docs.haml new file mode 100644 index 0000000..16eeaf9 --- /dev/null +++ b/site/src/pages/docs.haml @@ -0,0 +1,36 @@ += partial 'api_navigation' + +:plain +

API Documentation

+ +

There a couple of things that don’t really fit in to any of the class + references listed above. The first one is that there exist a series of + shorthand functions for creating objects in Sylvester. They are:

+ + + +

Note on accuracy

+ +

The second is that a lot of functionality in Sylvester relies on computing + various quantities and comparing them to zero. Rounding errors on floating + point numbers mean that quantities that should be zero can actually be a bit + off. Therefore, quantities are compared to the value of + Sylvester.precision – if the absolute value of + x is less than this number, x is considered to be + equal to zero. By default, Sylvester.precision is set to + 1e-6, but you can just set the value yourself if you want to be + more strict – it should ideally be several orders of magnitude smaller + than the vector/matrix elements you’re working with.

+ +

Null return values

+ +

Finally, as a general rule, trying to compute something that is not + mathematically meaningful (like multiplying matrices with incompatible sizes) + will produce a result of null. Similarly, trying to compute + something that does not exist, such as the intersection of two parallel + lines, will return null.

diff --git a/site/src/pages/index.haml b/site/src/pages/index.haml new file mode 100644 index 0000000..6010a8a --- /dev/null +++ b/site/src/pages/index.haml @@ -0,0 +1,47 @@ +:plain +

Sylvester is a vector, matrix and geometry library for JavaScript, that + runs in the browser and on the server side. It includes classes for + modelling vectors and matrices in any number of dimensions, and for + modelling infinite lines and planes in 3-dimensional space. It lets you + write object-oriented easy-to-read code that mirrors the maths it represents. + For example, it lets you multiply vectors and matrics together:

+ +
var V1 = $V([3,4,5]);
+  var V2 = $V([9,-3,0]);
+  
+  var d = V1.dot(V2);
+  // d is 15
+  
+  var c = V1.cross(V2);
+  // c is the vector (15,45,-45)
+ +
var M1 = $M([
+    [1,7,3],
+    [9,4,0],
+    [2,7,1]
+  ]);
+  
+  var M2 = $M([
+    [6,2,8],
+    [9,1,3],
+    [0,7,6]
+  ]);
+  
+  var M = M1.x(M2);
+  
+  // M is the matrix
+  //   69 30 47
+  //   90 22 84
+  //   75 18 43
+ +

and any number of other useful arithmetic and geometric + operations. For more information, take a look at the API + documentation.

+ + +

Download version 0.1.3

+ +

Sylvester is © 2007–2012 James + Coglan, and is released under the MIT license. Source code and bug + tracker are available + on GitHub.

diff --git a/site/src/partials/api_navigation.haml b/site/src/partials/api_navigation.haml new file mode 100644 index 0000000..51e0197 --- /dev/null +++ b/site/src/partials/api_navigation.haml @@ -0,0 +1,7 @@ +:plain + diff --git a/site/sylvester.js b/site/sylvester.js deleted file mode 100644 index 3e83bee..0000000 --- a/site/sylvester.js +++ /dev/null @@ -1 +0,0 @@ -eval(function(p,a,c,k,e,r){e=function(c){return(c35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('9 17={3i:\'0.1.3\',16:1e-6};l v(){}v.23={e:l(i){8(i<1||i>7.4.q)?w:7.4[i-1]},2R:l(){8 7.4.q},1u:l(){8 F.1x(7.2u(7))},24:l(a){9 n=7.4.q;9 V=a.4||a;o(n!=V.q){8 1L}J{o(F.13(7.4[n-1]-V[n-1])>17.16){8 1L}}H(--n);8 2x},1q:l(){8 v.u(7.4)},1b:l(a){9 b=[];7.28(l(x,i){b.19(a(x,i))});8 v.u(b)},28:l(a){9 n=7.4.q,k=n,i;J{i=k-n;a(7.4[i],i+1)}H(--n)},2q:l(){9 r=7.1u();o(r===0){8 7.1q()}8 7.1b(l(x){8 x/r})},1C:l(a){9 V=a.4||a;9 n=7.4.q,k=n,i;o(n!=V.q){8 w}9 b=0,1D=0,1F=0;7.28(l(x,i){b+=x*V[i-1];1D+=x*x;1F+=V[i-1]*V[i-1]});1D=F.1x(1D);1F=F.1x(1F);o(1D*1F===0){8 w}9 c=b/(1D*1F);o(c<-1){c=-1}o(c>1){c=1}8 F.37(c)},1m:l(a){9 b=7.1C(a);8(b===w)?w:(b<=17.16)},34:l(a){9 b=7.1C(a);8(b===w)?w:(F.13(b-F.1A)<=17.16)},2k:l(a){9 b=7.2u(a);8(b===w)?w:(F.13(b)<=17.16)},2j:l(a){9 V=a.4||a;o(7.4.q!=V.q){8 w}8 7.1b(l(x,i){8 x+V[i-1]})},2C:l(a){9 V=a.4||a;o(7.4.q!=V.q){8 w}8 7.1b(l(x,i){8 x-V[i-1]})},22:l(k){8 7.1b(l(x){8 x*k})},x:l(k){8 7.22(k)},2u:l(a){9 V=a.4||a;9 i,2g=0,n=7.4.q;o(n!=V.q){8 w}J{2g+=7.4[n-1]*V[n-1]}H(--n);8 2g},2f:l(a){9 B=a.4||a;o(7.4.q!=3||B.q!=3){8 w}9 A=7.4;8 v.u([(A[1]*B[2])-(A[2]*B[1]),(A[2]*B[0])-(A[0]*B[2]),(A[0]*B[1])-(A[1]*B[0])])},2A:l(){9 m=0,n=7.4.q,k=n,i;J{i=k-n;o(F.13(7.4[i])>F.13(m)){m=7.4[i]}}H(--n);8 m},2Z:l(x){9 a=w,n=7.4.q,k=n,i;J{i=k-n;o(a===w&&7.4[i]==x){a=i+1}}H(--n);8 a},3g:l(){8 S.2X(7.4)},2d:l(){8 7.1b(l(x){8 F.2d(x)})},2V:l(x){8 7.1b(l(y){8(F.13(y-x)<=17.16)?x:y})},1o:l(a){o(a.K){8 a.1o(7)}9 V=a.4||a;o(V.q!=7.4.q){8 w}9 b=0,2b;7.28(l(x,i){2b=x-V[i-1];b+=2b*2b});8 F.1x(b)},3a:l(a){8 a.1h(7)},2T:l(a){8 a.1h(7)},1V:l(t,a){9 V,R,x,y,z;2S(7.4.q){27 2:V=a.4||a;o(V.q!=2){8 w}R=S.1R(t).4;x=7.4[0]-V[0];y=7.4[1]-V[1];8 v.u([V[0]+R[0][0]*x+R[0][1]*y,V[1]+R[1][0]*x+R[1][1]*y]);1I;27 3:o(!a.U){8 w}9 C=a.1r(7).4;R=S.1R(t,a.U).4;x=7.4[0]-C[0];y=7.4[1]-C[1];z=7.4[2]-C[2];8 v.u([C[0]+R[0][0]*x+R[0][1]*y+R[0][2]*z,C[1]+R[1][0]*x+R[1][1]*y+R[1][2]*z,C[2]+R[2][0]*x+R[2][1]*y+R[2][2]*z]);1I;2P:8 w}},1t:l(a){o(a.K){9 P=7.4.2O();9 C=a.1r(P).4;8 v.u([C[0]+(C[0]-P[0]),C[1]+(C[1]-P[1]),C[2]+(C[2]-(P[2]||0))])}1d{9 Q=a.4||a;o(7.4.q!=Q.q){8 w}8 7.1b(l(x,i){8 Q[i-1]+(Q[i-1]-x)})}},1N:l(){9 V=7.1q();2S(V.4.q){27 3:1I;27 2:V.4.19(0);1I;2P:8 w}8 V},2n:l(){8\'[\'+7.4.2K(\', \')+\']\'},26:l(a){7.4=(a.4||a).2O();8 7}};v.u=l(a){9 V=25 v();8 V.26(a)};v.i=v.u([1,0,0]);v.j=v.u([0,1,0]);v.k=v.u([0,0,1]);v.2J=l(n){9 a=[];J{a.19(F.2F())}H(--n);8 v.u(a)};v.1j=l(n){9 a=[];J{a.19(0)}H(--n);8 v.u(a)};l S(){}S.23={e:l(i,j){o(i<1||i>7.4.q||j<1||j>7.4[0].q){8 w}8 7.4[i-1][j-1]},33:l(i){o(i>7.4.q){8 w}8 v.u(7.4[i-1])},2E:l(j){o(j>7.4[0].q){8 w}9 a=[],n=7.4.q,k=n,i;J{i=k-n;a.19(7.4[i][j-1])}H(--n);8 v.u(a)},2R:l(){8{2D:7.4.q,1p:7.4[0].q}},2D:l(){8 7.4.q},1p:l(){8 7.4[0].q},24:l(a){9 M=a.4||a;o(1g(M[0][0])==\'1f\'){M=S.u(M).4}o(7.4.q!=M.q||7.4[0].q!=M[0].q){8 1L}9 b=7.4.q,15=b,i,G,10=7.4[0].q,j;J{i=15-b;G=10;J{j=10-G;o(F.13(7.4[i][j]-M[i][j])>17.16){8 1L}}H(--G)}H(--b);8 2x},1q:l(){8 S.u(7.4)},1b:l(a){9 b=[],12=7.4.q,15=12,i,G,10=7.4[0].q,j;J{i=15-12;G=10;b[i]=[];J{j=10-G;b[i][j]=a(7.4[i][j],i+1,j+1)}H(--G)}H(--12);8 S.u(b)},2i:l(a){9 M=a.4||a;o(1g(M[0][0])==\'1f\'){M=S.u(M).4}8(7.4.q==M.q&&7.4[0].q==M[0].q)},2j:l(a){9 M=a.4||a;o(1g(M[0][0])==\'1f\'){M=S.u(M).4}o(!7.2i(M)){8 w}8 7.1b(l(x,i,j){8 x+M[i-1][j-1]})},2C:l(a){9 M=a.4||a;o(1g(M[0][0])==\'1f\'){M=S.u(M).4}o(!7.2i(M)){8 w}8 7.1b(l(x,i,j){8 x-M[i-1][j-1]})},2B:l(a){9 M=a.4||a;o(1g(M[0][0])==\'1f\'){M=S.u(M).4}8(7.4[0].q==M.q)},22:l(a){o(!a.4){8 7.1b(l(x){8 x*a})}9 b=a.1u?2x:1L;9 M=a.4||a;o(1g(M[0][0])==\'1f\'){M=S.u(M).4}o(!7.2B(M)){8 w}9 d=7.4.q,15=d,i,G,10=M[0].q,j;9 e=7.4[0].q,4=[],21,20,c;J{i=15-d;4[i]=[];G=10;J{j=10-G;21=0;20=e;J{c=e-20;21+=7.4[i][c]*M[c][j]}H(--20);4[i][j]=21}H(--G)}H(--d);9 M=S.u(4);8 b?M.2E(1):M},x:l(a){8 7.22(a)},32:l(a,b,c,d){9 e=[],12=c,i,G,j;9 f=7.4.q,1p=7.4[0].q;J{i=c-12;e[i]=[];G=d;J{j=d-G;e[i][j]=7.4[(a+i-1)%f][(b+j-1)%1p]}H(--G)}H(--12);8 S.u(e)},31:l(){9 a=7.4.q,1p=7.4[0].q;9 b=[],12=1p,i,G,j;J{i=1p-12;b[i]=[];G=a;J{j=a-G;b[i][j]=7.4[j][i]}H(--G)}H(--12);8 S.u(b)},1y:l(){8(7.4.q==7.4[0].q)},2A:l(){9 m=0,12=7.4.q,15=12,i,G,10=7.4[0].q,j;J{i=15-12;G=10;J{j=10-G;o(F.13(7.4[i][j])>F.13(m)){m=7.4[i][j]}}H(--G)}H(--12);8 m},2Z:l(x){9 a=w,12=7.4.q,15=12,i,G,10=7.4[0].q,j;J{i=15-12;G=10;J{j=10-G;o(7.4[i][j]==x){8{i:i+1,j:j+1}}}H(--G)}H(--12);8 w},30:l(){o(!7.1y){8 w}9 a=[],n=7.4.q,k=n,i;J{i=k-n;a.19(7.4[i][i])}H(--n);8 v.u(a)},1K:l(){9 M=7.1q(),1c;9 n=7.4.q,k=n,i,1s,1n=7.4[0].q,p;J{i=k-n;o(M.4[i][i]==0){2e(j=i+1;j17.16){1Y++;1I}}H(--G)}H(--a);8 1Y},3d:l(){8 7.1Y()},2W:l(a){9 M=a.4||a;o(1g(M[0][0])==\'1f\'){M=S.u(M).4}9 T=7.1q(),1p=T.4[0].q;9 b=T.4.q,15=b,i,G,10=M[0].q,j;o(b!=M.q){8 w}J{i=15-b;G=10;J{j=10-G;T.4[i][1p+j]=M[i][j]}H(--G)}H(--b);8 T},2w:l(){o(!7.1y()||7.2y()){8 w}9 a=7.4.q,15=a,i,j;9 M=7.2W(S.I(a)).1K();9 b,1n=M.4[0].q,p,1c,2v;9 c=[],2c;J{i=a-1;1c=[];b=1n;c[i]=[];2v=M.4[i][i];J{p=1n-b;2c=M.4[i][p]/2v;1c.19(2c);o(p>=15){c[i].19(2c)}}H(--b);M.4[i]=1c;2e(j=0;j3||b.4.q>3){8 w}9 c=b.1u();o(c===0){8 w}7.K=a;7.U=v.u([b.4[0]/c,b.4[1]/c,b.4[2]/c]);8 7}};14.u=l(a,b){9 L=25 14();8 L.1Z(a,b)};14.X=14.u(v.1j(3),v.i);14.Y=14.u(v.1j(3),v.j);14.Z=14.u(v.1j(3),v.k);l 11(){}11.23={24:l(a){8(7.1h(a.K)&&7.1m(a))},1q:l(){8 11.u(7.K,7.W)},2U:l(a){9 V=a.4||a;8 11.u([7.K.4[0]+V[0],7.K.4[1]+V[1],7.K.4[2]+(V[2]||0)],7.W)},1m:l(a){9 b;o(a.W){b=7.W.1C(a.W);8(F.13(b)<=17.16||F.13(F.1A-b)<=17.16)}1d o(a.U){8 7.W.2k(a.U)}8 w},2k:l(a){9 b=7.W.1C(a.W);8(F.13(F.1A/2-b)<=17.16)},1o:l(a){o(7.1v(a)||7.1h(a)){8 0}o(a.K){9 A=7.K.4,B=a.K.4,N=7.W.4;8 F.13((A[0]-B[0])*N[0]+(A[1]-B[1])*N[1]+(A[2]-B[2])*N[2])}1d{9 P=a.4||a;9 A=7.K.4,N=7.W.4;8 F.13((A[0]-P[0])*N[0]+(A[1]-P[1])*N[1]+(A[2]-(P[2]||0))*N[2])}},1h:l(a){o(a.W){8 w}o(a.U){8(7.1h(a.K)&&7.1h(a.K.2j(a.U)))}1d{9 P=a.4||a;9 A=7.K.4,N=7.W.4;9 b=F.13(N[0]*(A[0]-P[0])+N[1]*(A[1]-P[1])+N[2]*(A[2]-(P[2]||0)));8(b<=17.16)}},1v:l(a){o(1g(a.U)==\'1f\'&&1g(a.W)==\'1f\'){8 w}8!7.1m(a)},1U:l(a){o(!7.1v(a)){8 w}o(a.U){9 A=a.K.4,D=a.U.4,P=7.K.4,N=7.W.4;9 b=(N[0]*(P[0]-A[0])+N[1]*(P[1]-A[1])+N[2]*(P[2]-A[2]))/(N[0]*D[0]+N[1]*D[1]+N[2]*D[2]);8 v.u([A[0]+D[0]*b,A[1]+D[1]*b,A[2]+D[2]*b])}1d o(a.W){9 c=7.W.2f(a.W).2q();9 N=7.W.4,A=7.K.4,O=a.W.4,B=a.K.4;9 d=S.1j(2,2),i=0;H(d.2y()){i++;d=S.u([[N[i%3],N[(i+1)%3]],[O[i%3],O[(i+1)%3]]])}9 e=d.2w().4;9 x=N[0]*A[0]+N[1]*A[1]+N[2]*A[2];9 y=O[0]*B[0]+O[1]*B[1]+O[2]*B[2];9 f=[e[0][0]*x+e[0][1]*y,e[1][0]*x+e[1][1]*y];9 g=[];2e(9 j=1;j<=3;j++){g.19((i==j)?0:f[(j+(5-i)%3)%3])}8 14.u(g,c)}},1r:l(a){9 P=a.4||a;9 A=7.K.4,N=7.W.4;9 b=(A[0]-P[0])*N[0]+(A[1]-P[1])*N[1]+(A[2]-(P[2]||0))*N[2];8 v.u([P[0]+N[0]*b,P[1]+N[1]*b,(P[2]||0)+N[2]*b])},1V:l(t,a){9 R=S.1R(t,a.U).4;9 C=a.1r(7.K).4;9 A=7.K.4,N=7.W.4;9 b=C[0],1E=C[1],1J=C[2],1w=A[0],18=A[1],1a=A[2];9 x=1w-b,y=18-1E,z=1a-1J;8 11.u([b+R[0][0]*x+R[0][1]*y+R[0][2]*z,1E+R[1][0]*x+R[1][1]*y+R[1][2]*z,1J+R[2][0]*x+R[2][1]*y+R[2][2]*z],[R[0][0]*N[0]+R[0][1]*N[1]+R[0][2]*N[2],R[1][0]*N[0]+R[1][1]*N[1]+R[1][2]*N[2],R[2][0]*N[0]+R[2][1]*N[1]+R[2][2]*N[2]])},1t:l(a){o(a.W){9 A=7.K.4,N=7.W.4;9 b=A[0],18=A[1],1a=A[2],2M=N[0],2L=N[1],2Q=N[2];9 c=7.K.1t(a).4;9 d=b+2M,2p=18+2L,2m=1a+2Q;9 Q=a.1r([d,2p,2m]).4;9 e=[Q[0]+(Q[0]-d)-c[0],Q[1]+(Q[1]-2p)-c[1],Q[2]+(Q[2]-2m)-c[2]];8 11.u(c,e)}1d o(a.U){8 7.1V(F.1A,a)}1d{9 P=a.4||a;8 11.u(7.K.1t([P[0],P[1],(P[2]||0)]),7.W)}},1Z:l(a,b,c){a=v.u(a);a=a.1N();o(a===w){8 w}b=v.u(b);b=b.1N();o(b===w){8 w}o(1g(c)==\'1f\'){c=w}1d{c=v.u(c);c=c.1N();o(c===w){8 w}}9 d=a.4[0],18=a.4[1],1a=a.4[2];9 e=b.4[0],1W=b.4[1],1X=b.4[2];9 f,1i;o(c!==w){9 g=c.4[0],2l=c.4[1],2t=c.4[2];f=v.u([(1W-18)*(2t-1a)-(1X-1a)*(2l-18),(1X-1a)*(g-d)-(e-d)*(2t-1a),(e-d)*(2l-18)-(1W-18)*(g-d)]);1i=f.1u();o(1i===0){8 w}f=v.u([f.4[0]/1i,f.4[1]/1i,f.4[2]/1i])}1d{1i=F.1x(e*e+1W*1W+1X*1X);o(1i===0){8 w}f=v.u([b.4[0]/1i,b.4[1]/1i,b.4[2]/1i])}7.K=a;7.W=f;8 7}};11.u=l(a,b,c){9 P=25 11();8 P.1Z(a,b,c)};11.2I=11.u(v.1j(3),v.k);11.2H=11.u(v.1j(3),v.i);11.2G=11.u(v.1j(3),v.j);11.36=11.2I;11.35=11.2H;11.3j=11.2G;9 $V=v.u;9 $M=S.u;9 $L=14.u;9 $P=11.u;',62,206,'||||elements|||this|return|var||||||||||||function|||if||length||||create|Vector|null|||||||||Math|nj|while||do|anchor||||||||Matrix||direction||normal||||kj|Plane|ni|abs|Line|ki|precision|Sylvester|A2|push|A3|map|els|else||undefined|typeof|contains|mod|Zero|D3|D2|isParallelTo|kp|distanceFrom|cols|dup|pointClosestTo|np|reflectionIn|modulus|intersects|A1|sqrt|isSquare|X2|PI|X3|angleFrom|mod1|C2|mod2|sin|cos|break|C3|toRightTriangular|false|Y3|to3D|E2|E1|E3|Rotation|Y2|Y1|intersectionWith|rotate|v12|v13|rank|setVectors|nc|sum|multiply|prototype|eql|new|setElements|case|each|PA3|PA2|part|new_element|round|for|cross|product|AD2|isSameSizeAs|add|isPerpendicularTo|v22|AN3|inspect|AD3|AN2|toUnitVector|PsubQ3|PsubQ2|v23|dot|divisor|inverse|true|isSingular|determinant|max|canMultiplyFromLeft|subtract|rows|col|random|ZX|YZ|XY|Random|join|N2|N1|D1|slice|default|N3|dimensions|switch|liesIn|translate|snapTo|augment|Diagonal|trace|indexOf|diagonal|transpose|minor|row|isAntiparallelTo|ZY|YX|acos|RotationZ|RotationY|liesOn|RotationX|inv|rk|tr|det|toDiagonalMatrix|toUpperTriangular|version|XZ'.split('|'),0,{})) \ No newline at end of file