vec2.js:操纵2D向量

  • Z3_719112
    了解作者
  • 16.7KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-06 01:33
    上传日期
Vec2.js 一个通用库,在需要处理二维空间中的点/向量时很有用。 用 var a = new Vec2 ( 10 , 10 ) , // new keyword b = Vec2 ( 100 , 10 ) ; // call the constructor directly console . log ( a . distance ( b ) ) ; // 90 注意事项:大多数Vec2的方法都将returnNew作为最后一个参数。 如果传递的是真实值,则会向您返回一个新向量。 否则,操作将被应用到this和this将被退回。 另外,由于Infinity和NaN非常阴险,因此该库将在检测到这两个库后立即抛出该异常,因此您可以采取措施来修复数据/算法。 支持的运营 变更([fn]) 添加一个观察者fn ,只要此向量改变,该观察者就会被调用。 在没有函数的情况下
vec2_js-master.zip
  • vec2.js-master
  • types
  • global.d.ts
    1.8KB
  • test
  • bench
  • observer.js
    343B
  • run.sh
    714B
  • ignore.js
    355B
  • random-sets.js
    266B
  • random-sets-int.js
    334B
  • create-many.js
    270B
  • index.html
    469B
  • test.js
    22.7KB
  • vec2.min.js
    4.6KB
  • LICENSE.txt
    1KB
  • .npmignore
    39B
  • .travis.yml
    45B
  • vec2.js
    11.3KB
  • README.md
    6.6KB
  • .gitignore
    48B
  • package.json
    962B
内容介绍
# Vec2.js ![travis](https://api.travis-ci.org/tmpvar/vec2.js.png) [![browser support](https://ci.testling.com/tmpvar/vec2.js.png)](http://ci.testling.com/tmpvar/vec2.js) A generic library useful when you need to work with points/vectors in 2d space. ## Use ```javascript var a = new Vec2(10, 10), // new keyword b = Vec2(100, 10); // call the constructor directly console.log(a.distance(b)); // 90 ``` **Stuff to Note**: most of the Vec2's methods take a `returnNew` as the last parameter. If passed a truthy value, a new vector will be returned to you. Otherwise the operation will be applied to `this` and `this` will be returned. Also, since `Infinity`and `NaN` are so insidious, this library will throw as soon as it detects either of these so you can take action to fix your data/algorithm. ## Supported operations __change__([fn]) Add an observer `fn` that will be called whenever this vector changes. Calling this method without a function causes it to notify observers. `fn` signature: `function(vec, prev) {}` - where `prev` is a clone of the vector before the last operation. this function returns the passed `fn` _returns_: `Vec2` <hr /> __ignore__([fn]) Pass a `fn` to remove it from the observers list. Calling this function without a `fn` will remove all observers. _returns_: `Vec2` <hr /> __set__(x, y [, notify]) or __set__(vec2 [, notify]) Sets the `x` and `y` coordinates of this vector. If `false` is passed for `notify`, none of the observers will be called. _returns_: `Vec2` <hr /> __zero__() Sets the `x` and `y` of this vector to `0` _returns_: `Vec2` <hr /> __clone__() Returns a clone of this vector. _Note_: this does not clone observers _returns_: `Vec2` <hr /> __negate__([returnNew]) Negate the `x` and `y` coords of this vector. If `returnNew` is truthy, a new vector with the negated coordinates will be returned. _returns_: `Vec2` <hr /> __add__(x, y [, returnNew]) or __add__(array, [, returnNew]) or __add__(vec2 [, returnNew]) Add the `x` and `y` to this vector's coordinates. If `returnNew` is truthy, return a new vector containing the resulting coordinates. Otherwise apply them to this vector and return it. _returns_: `Vec2` <hr /> __subtract__(x, y [, returnNew]) or __subtract__(array, [, returnNew]) or __subtract__(vec2 [, returnNew]) _returns_: `Vec2` <hr /> __multiply__(scalar [, returnNew]) or __multiply__(x, y [, returnNew]) or __multiply__(array, [, returnNew]) or __multiply__(vec2 [, returnNew]) Multiply this vectors components with the incoming, returning a clone if `returnNew` is truthy. _returns_: `Vec2` <hr /> __divide__(scalar [, returnNew]) or __divide__(x, y [, returnNew]) or __divide__(array, [, returnNew]) or __divide__(vec2 [, returnNew]) Divide this vectors components by the incoming, returning a clone if `returnNew` is truthy. _note_: this method will throw if you attempt to divide by zero or pass values that cause NaNs _returns_: `Vec2` <hr /> __rotate__(radians [, inverse [, returnNew]]) Rotate this vector's cordinates around `(0,0)`. If `returnNew` is specified, a new `Vec2` will be created and populated with the result and returned. Otherwise the result is applied to this vector and `this` is returned. `inverse` - inverts the direction of the rotation `returnNew` - causes the result to be applied to a new `Vec2`, otherwise the result is applied to `this` _returns_: `Vec2` <hr /> __length__() Returns the length of this vector from `(0,0)` _returns_: `double` <hr /> __lengthSquared__() Returns the length of this vector prior to the `Math.sqrt` call. This is usefull when you don't need to know the actual distance, but need a normalized value to compare with another `Vec2#lengthSquared` or similar. _returns_: `double` <hr /> __distance__(vec2) _returns_: the distance between this vector and the incoming <hr /> __nearest__(array) _returns_: closest vector in array to this vector. <hr /> __normalize__([returnNew]) Normalizes this vector. If `returnNew` is truthy, a new vector populated with the normalized coordinates will be returned. _returns_: `Vec2` <hr /> __equal__(vec2) or __equal__(x, y) or __equal__(array) returns true if the incoming coordinates are the same as this vector's _returns_: `boolean` __abs__([returnNew]) Return a `Vec2` that contains the absolute value of each of this vector's parts. If `returnNew` is truthy, create a new `Vec2` and return it. Otherwise apply the absolute values to to `this`. _returns_: `Vec2` <hr /> __min__(vec) Return a `Vec2` consisting of the smallest values from this vector and the incoming When returnNew is truthy, a new `Vec2` will be returned otherwise the minimum values in either this or `vec` will be applied to this vector. _returns_: `Vec2` <hr /> __max__(vec) Return a `Vec2` consisting of the largest values from this vector and the incoming When returnNew is truthy, a new `Vec2` will be returned otherwise the maximum values in either `this` or `vec` will be applied to this vector. _returns_: `Vec2` <hr /> __clamp__(low, high [, returnNew]) Clamp the coordinates of this vector to the high/low of the incoming vec2s. If `returnNew` apply the result to the new vector and return. Otherwise apply to this vector. _returns_: `Vec2` <hr /> __lerp__(vec, amount [, returnNew]) Perform linear interpolation between this vector and the incoming. `amount` - the percentage along the path to place the vector `returnNew` - if `truthy`, apply the result to a new vector and return it, otherwise return `this` _returns_: `Vec2` <hr /> __skew__([returnNew]) Returns a vector set with the `(-y,x)` coordinates of this vector. If `returnNew` a new vector is created and the operation is applied to the new vector. _returns_: `Vec2` <hr /> __dot__() _returns_: `double` <hr /> __perpDot__() _returns_: `double` <hr /> __angleTo__(vec) returns the angle from this vector to the incoming. _returns_: `double` <hr /> __isPointOnLine__(start, end) where `start` and `end` are vec2-like (e.g. `start.x` and `start.y`) _returns_: `boolean` <hr /> __toArray__() _returns_: `[x, y]` <hr /> __fromArray__(array) Applies the `[0]` to `this.x` and `[1]` to `this.y` _returns_: `Vec2` <hr /> __toJSON__() _returns_: `{ x: ..., y: ...}` <hr /> __toString__() _returns_: `'(x, y)'` ## Install ### Browser ```html <script type="text/javascript" src="https://raw.github.com/tmpvar/vec2.js/master/vec2.min.js"></script> <script type="text/javascript"> var v = new Vec2(); </script> ``` ### Node install with npm npm install vec2 and then require it! var Vec2 = require('vec2'); ## License MIT (see [LICENSE.txt](LICENSE.txt))
评论
    相关推荐
    • RNN.zip
      基于梯度下降的RNN,训练过程用到了BPTT算法,通俗易懂
    • 捷联惯导积分算法_SAVAGE
      捷联惯导经典算法姿态更新以及速度和位置更新 包括英文原文及其纠错
    • template-scala-rnn:RNN算法实现
      该模板提供情感分析算法 。 安装。 遵循。 安装后启动所有 PredictionIO 供应商并检查 pio 状态: pio-start-all pio status 将此模板复制到您的本地目录: pio template get ts335793/template-scala-spark-...
    • lip-movement-net:使用基于唇动的RNN检测器进行说话人检测
      RNN的检测算法如下: 从输入视频文件或网络摄像头中接受25帧的序列(即25 fps视频的1秒钟的帧值)。 序列长度是可配置的。 对于此序列中的每个视频帧: 将其转换为灰色框。 这样可以加快接下来的几个步骤(减少...
    • Algorithm-RNN-SM.zip
      Algorithm-RNN-SM.zip,RNN-SM:使用递归神经网络T-IFS对VoIP流的快速隐写分析,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
    • CMOS校验和算法
      CMOS校验和算法~~~!~~!~~!~!`1
    • rnn.rar
      逆向最近邻查询算法在实际应用中有很多领域
    • rnn-by-numpy:使用numpy实现rnn和语言模型
      本仓库主要用numpy从头开始构建rnn结构,包括前向传播算法 反向传播算法 学习率 随机梯度下降; 实例:给定一个x来预测y,虽然这个没有实际意义,所以在这里主要目的是为了阐释rnn算法 x: SENTENCE_START what are ...
    • RNN算法打包matlab
      matlab中rnn的用法
    • GaussDB_100_1.0.1-DATABASE-REDHAT-64bit.tar.gz
      guassdb100在redhat上安装包,单机部署的包,安装步骤请看我的文中介绍,经过大量实验搭建总结出来的文档