Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 5, 2020. It is now read-only.
/JustMath.jsPublic archive

A rich toolset for two dimensional vector math.

License

NotificationsYou must be signed in to change notification settings

dcodeIO/JustMath.js

Repository files navigation

JustMath.js - 2D Vector Math

An implementation of two dimensional vector math including a rich toolset for vector operations. It's also the mathlibrary behindeSoccer, a cross-platform multiplayer HTML5 game developed atUniversity ofApplied Sciences Bonn.

JustMath

  • Augments core Math
  • Allows replacement of all methods (e.g. custom implementations ofJustMath.sqrt(value))
  • Adds some convenience methods (JustMath.sq(value),JustMath.cot(angle))

JustMath.Vec2

  • Vector instantiation (new Vec2(vOrX[, y])) and cloning (Vec2#clone())

  • Direct modification throughVec2#x andVec2#y, also provides getters (Vec2#getX(),Vec2#getY()) and a setter(Vec2#set(vOrX[, y]))

  • Vector addition (Vec2#add(vOrX[, y])), subtraction (Vec2#sub(vOrX[, y])) and multiplication(Vec2#dot(vOrX[, y])))

  • Vector orthogonality (Vec2#ort())

  • Vector normalization (Vec2#norm()), scaling (Vec2#scale(factor)), inversion (Vec2#inv()) and magnitude(Vec2#mag(),Vec2#magSq()) calculation

  • Vector-Vector distances (Vec2#dist(b),Vec2#distSq(b))

  • Vector rotation (Vec2#rot(angle)) and direction calculation (Vec2#dir())

  • Vector projection (Vec2#project(b)) and rejection (Vec2#reject(b))

  • Vector reflection (Vec2#reflect(n)), also with component-wise (projected and rejected component) scaling(Vec2#reflectAndScale(n, projectFactor, rejectFactor))

  • Vector interpolation (Vec2#lerp(p, percent))

  • Vector containment in rectangle (Vec2#inRect(p1, p2))

  • [Vector,Vector] determinant calculation (Vec2.det(v1, v2))

  • Provides Vector#toString andVector#equals()

  • Provides vector operation chaining, e.g.

    vara=newVec2(1,2);varb=newVec2(2,1);varn=newVec2(0,1);a.clone().sub(b).norm().project(n)...
  • ProvidesVec2#toString() for pain-free debugging

  • Is of course able to evaluateVec2#equals(b)

  • Exports and imports JSON payloads (Vec2#getXY(),new Vec2(jsonPayload))

  • Small allocation footprint when usingVec2#clone() wisely

  • Accepts another Vec2 or plain X and Y coordinates as parameters where possible (e.g.Vec2#add(vOrX[, y]))

Features

  • CommonJS compatible
  • RequireJS/AMD compatible
  • Shim compatible
  • node.js compatible, also available vianpm (npm install justmath)
  • Closure Compiler ADVANCED_OPTIMIZATIONS compatible (fully annotated)
  • Fully documented usingjsdoc3
  • Zero dependencies and prerequisites
  • Small footprint

Usage

Node.js / CommonJS

  • Install:npm install justmath
varJustMath=require("justmath"),Vec2=JustMath.Vec2;vara=newVec2(1,2);console.log("Not more than "+a.x+", "+a.y+", 3.");

Browser (shim)

<scriptsrc="//raw.github.com/dcodeIO/JustMath.js/master/JustMath.min.js"></script>
varJustMath=dcodeIO.JustMath,Vec2=JustMath.Vec2;vara=newVec2(1,2);alert("Not more than "+a.x+", "+a.y+", 3.");

RequireJS / AMD

varJustMath=require("/path/to/JustMath.js"),Vec2=JustMath.Vec2;vara=newVec2(1,2);alert("Not more than "+a.x+", "+a.y+", 3.");

Downloads

Documentation

Examples & TestsBuild Status

License

Apache License, Version 2.0 -http://www.apache.org/licenses/LICENSE-2.0.html

About

A rich toolset for two dimensional vector math.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp