jt_vectors

by Jtgibson
A fully-featured object-oriented suite of floating-point vector and coordinate functions to break free of the boundaries of tiles.
ID:125089
 
The jt_vectors library is a procedure-rich object-oriented library which allows the definition and use of coordinates and vectors in 3D space. Creative applications of this allow for the foundations of 3D physics, and even rudimentary use of the library allows you to create seamless pixel-based games where objects are not constrained to the tile grid.


jt_vectors defines three object types:

/coordinate: A coordinate is a single point in 3D space consisting of an x-, y-, and z-coordinate. It can also refer to a point in 2D space (like a traditional BYOND game) just fine, since there's nothing that says you have to use a z-coordinate unless you really want to.

/vector: A vector is a special construct used to mathematically refer to a "quantity" associated with a "direction". A typical number (say, "30 km/h") is a "scalar" -- it is just a "quantity" that doesn't really say anything except how much you have (for instance, if I was going 30 km/h, I might never arrive at my destination if I'm driving the wrong way). A "vector" includes a direction; if I was going 30 km/h and travelling due north, I could plot that in terms of a vector on the planet's surface.

/jt_vectors: The jt_vectors library also defines a catch-all utility object which allows you to access some handy shorthand procedures for working with vectors and coordinates.





Function List:

/coordinate
CoordinateX()
CoordinateY()
CoordinateZ()
SetCoordinateX(setting)
SetCoordinateY(setting)
SetCoordinateZ(setting)
ModCoordinateX(mod)
ModCoordinateY(mod)
ModCoordinateZ(mod)
Copy()
AddVector(alt)
AddVectors(...)
SubtractVector(alt)
SubtractVectors(...)
AngleTo(dest)
AngleXYTo(dest)
AngleXZTo(dest)
AngleYZTo(dest)
BearingTo(dest)
DistanceTo(dest)
PitchTo(dest)

/vector
ComponentX()
ComponentY()
ComponentZ()
SetComponentX(setting)
SetComponentY(setting)
SetComponentZ(setting)
ModComponentX(mod)
ModComponentY(mod)
ModComponentZ(mod)
Copy()
Reverse()
Magnitude()
Scale(modifier)
ScaleX(modifier)
ScaleY(modifier)
ScaleZ(modifier)
ScaleToMagnitude(setting)
AdjustMagnitude(mod)
UnitVector()
Angle()
Bearing()
Pitch()
AngleXY()
AngleXZ()
AngleYZ()
AddVector(alt)
AddVectors(...)
SubtractVector(alt)
SubtractVectors(...)
DotProduct(alt)
CrossProduct(alt)
DeflectXY()
DeflectXZ()
DeflectYZ()
RotateX(angle)
RotateY(angle)
RotateZ(angle)
RotateAngle(angle)
RotateBearing(bearing)
BearingWithin(left_bound,right_bound)
AngleWithin(left_bound,right_bound)
AngleXYWithin(left_bound,right_bound)
AngleXZWithin(left_bound,right_bound)
AngleYZWithin(left_bound,right_bound)

/jt_vectors
VectorFromAngle(angle,magnitude,pitch)
VectorFromBearing(bearing,magnitude,pitch)
AngleToBearing(standard_angle)
BearingToAngle(bearing)
AngleAB(src_a, src_b, trg_a, trg_b)
AngleABWithin(angle,left,right)
arctan(x,y) //thanks to Lummox JR





Version History:

(Version 0)
* Initial release

(Version 1)
* Added jt_vectors.AngleABWithin(angle, left, right)
* Added vector.AngleWithin(left, right)
* Added vector.BearingWithin(left, right)
* Added vector.AngleXYWithin(left, right)
* Added vector.AngleXZWithin(left, right)
* Added vector.AngleYZWithin(left, right)

(Version 2)
* Fixed vector.RotateX(angle)
* Fixed vector.RotateY(angle)
* Fixed vector.RotateZ(angle)
* Fixed vector.RotateAngle(angle)
* Fixed vector.RotateBearing(bearing)

(Version 3)
* Fixed glaring but extremely minor error in the utility procedure VectorFromBearing(bearing, magnitude, pitch) -- the proc was asking for the magnitude and pitch in the wrong order.