Class: GeometryUtils

GeometryUtils

new GeometryUtils()

Utility methods of some 2D or 3D geometry tasks.
Source:

Methods

(static) getCrossPointOfLines(line1Coord1, line1Coord2, line2Coord1, line2Coord2) → {Hash}

Returns the cross point coord of line1 and line2. If no cross point or the point out of lines, null will be returned. The algorithm is explained in https://www.jb51.net/article/90104.htm.
Parameters:
Name Type Description
line1Coord1 Hash
line1Coord2 Hash
line2Coord1 Hash
line2Coord2 Hash
Source:
Returns:
Type
Hash

(static) getDihedralAngleOfPoints(c1, c2, c3, c4) → {Float}

Returns dihedral angle of plane (c1, c2, c3) and (c2, c3, c4) while c1-4 are coords of 3D.
Parameters:
Name Type Description
c1 Hash
c2 Hash
c3 Hash
c4 Hash
Source:
Returns:
Type
Float

(static) getDihedralAngleOfVectors(v1, v2, v3) → {Float}

Returns dihedral angle defined by three vectors (e.g., three bonds in molecule). v1-3 is formed by {x, y, z} coords. The calculation is based on formula: alpha = atan2([v1×v2]×[v2×v3].[v2/|v2|], [v1×v2].[v2×v3]) (http://en.wikipedia.org/wiki/Dihedral_angle)
Parameters:
Name Type Description
v1 Hash
v2 Hash
v3 Hash
Source:
Returns:
An angle of 0-2Pi is returned. If angle can not be calculated (e.g., v1/v2 or v2/v3 on same line, not forms a plane), a negtive value will be returned instead.
Type
Float

(static) getDistanceFromPointToLine(coord, lineCoord1, lineCoord2, isUnlimitedLine) → {Hash}

Returns the minial distance from point (coord) to line (lineCoord1, lineCoord2)
Parameters:
Name Type Description
coord Hash
lineCoord1 Hash
lineCoord2 Hash
isUnlimitedLine Bool If true, the line length will not be considered.
Source:
Returns:
Type
Hash

(static) getPerpendicularCrossPointFromCoordToLine(coord, lineCoord1, lineCoord2, isUnlimitedLine) → {Hash}

Returns the cross point of a vertical line from coord to a existing line (lineCoord1-lineCoord2)
Parameters:
Name Type Description
coord Hash
lineCoord1 Hash
lineCoord2 Hash
isUnlimitedLine Bool If true, the line length will not be considered.
Source:
Returns:
Type
Hash

(static) getVectorCrossProduct(coord1, coord2) → {Hash}

Returns the cross product (v1Xv2) of two vectors represented by coord1 and coord2.
Parameters:
Name Type Description
coord1 Hash
coord2 Hash
Source:
Returns:
Type
Hash

(static) getVectorIncludedAngle(vector1, vector2) → {Number}

Returns included angle of two vectors represented by vector1 and vector2. Note this method always returns result less than Math.PI / 2.
Parameters:
Name Type Description
vector1 Hash
vector2 Hash
Source:
Returns:
Type
Number

(static) getVectorIncludedAngle2(vector1, vector2) → {Number}

Returns included angle of two vectors represented by vector1 and vector2. Note this method always returns result between 0 to 2pi.
Parameters:
Name Type Description
vector1 Hash
vector2 Hash
Source:
Returns:
Type
Number

(static) getVectorScalarProduct(coord1, coord2) → {Float}

Returns the cross product (v1.v2) of two vectors represented by coord1 and coord2.
Parameters:
Name Type Description
coord1 Hash
coord2 Hash
Source:
Returns:
Type
Float

(static) polarToCartesian(centerX, centerY, radius, angle) → {Hash}

Convert a polar coord to cartesian one.
Parameters:
Name Type Description
centerX Float
centerY Float
radius Float
angle Float
Source:
Returns:
Type
Hash

(static) standardizeAngle(angle, rangeMin)

Add or substract 2Pi to angle, ensure the angle in range rangeMin to rangeMin + 2Pi
Parameters:
Name Type Description
angle Float
rangeMin Float Default is 0.
Source: