npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

saber-vector

v1.1.1

Published

math/vector lib for javascript!

Downloads

15

Readme

saber-vector

npm

math/vector lib for javascript!

npm install saber-vector

API

angleToRad

角度转弧度

angleToRad(90) // 1.5707963267948966

radToAngle

弧度转角度

radToAngle(Math.PI / 2) // 90

magnitude2d

求 2d 向量的模

magnitude2d(3, 4) // 5

magnitude3d

求 3d 向量的模

magnitude3d(1, 2, 2) // 3

Vec2

2d 坐标类型

构造函数:

new Vec2(x, y)

方法:

注意:以下方法均为纯函数

  1. props 获取所有坐标属性
  2. equals 判断两个向量是否相等
  3. add 向量和
  4. sub 向量差
  5. mul 向量乘
  6. div 向量除
  7. scale 向量缩放
  8. neg 向量取反
  9. mag 返回向量的模
  10. angleWith 与另一个向量夹角
  11. dot 向量数量积
  12. cross 向量叉积
  13. unitized 单位化

Vec3

3d 坐标类型

构造函数:

new Vec3(x, y, z)

方法:...同 Vec2

Line2D

二维有向线段

构造函数:

new Line2D(start_vec2, end_vec2)

方法:

注意:以下方法均为纯函数

  1. projection 在另一个二维有向线段上的投影
  2. toVec 转为 Vec2 类型

Line3D

三维有向线段

构造函数:

new Line3D(start_vec3, end_vec3)

方法:...同 Line2D

Examples

let start_3d = new Vector3D(0, 0, 0)

let end1_3d = new Vector3D(0, 1, 0)
let line1_3d = new Line3D(start_3d, end1_3d)

let end2_3d = new Vector3D(0, 1, 1)
let line2_3d = new Line3D(start_3d, end2_3d)

// v.neg().neg()
console.log(
  end2_3d
    .neg()
    .neg()
    .isEquals(end2_3d)
) // true

// get angle in two vectors?
console.log(radToAngle(line1_3d.toVec().angleWith(line2_3d.toVec()))) // 45

// get props of vector?
console.log(line1_3d.toVec().props())

// get line's projection on line2?
console.log(
  line1_3d
    .projection(line2_3d)
    .toVec()
    .props()
)

// same to 2d
let start_2d = new Vector2D(0, 0)

let end1_2d = new Vector2D(0, 1)
let line1_2d = new Line2D(start_2d, end1_2d)

let end2_2d = new Vector2D(1, 1)
let line2_2d = new Line2D(start_2d, end2_2d)

console.log('2d: ', radToAngle(line1_2d.toVec().angleWith(line2_2d.toVec())))
console.log(
  line1_2d
    .projection(line2_2d)
    .toVec()
    .props()
)
console.log(
  end2_2d
    .neg()
    .neg()
    .isEquals(end2_2d)
) // true

Author

saber2pr