Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gl-vec2

Package Overview
Dependencies
Maintainers
13
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gl-vec2

gl-matrix's vec2, split into smaller pieces

  • 1.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
133K
increased by3.41%
Maintainers
13
Weekly downloads
 
Created

What is gl-vec2?

The gl-vec2 npm package provides a set of functions for performing vector operations in 2D space. It is part of the gl-matrix library, which is widely used for matrix and vector math in WebGL applications. The package includes functions for creating, manipulating, and performing mathematical operations on 2D vectors.

What are gl-vec2's main functionalities?

Vector Creation

This feature allows you to create a new 2D vector. The `create` function initializes a vector with default values [0, 0].

const vec2 = require('gl-vec2');
let v = vec2.create(); // Creates a new, empty vector
console.log(v); // Output: [0, 0]

Vector Addition

This feature allows you to add two 2D vectors. The `add` function takes two vectors and returns their sum.

const vec2 = require('gl-vec2');
let v1 = vec2.fromValues(1, 2);
let v2 = vec2.fromValues(3, 4);
let result = vec2.add([], v1, v2);
console.log(result); // Output: [4, 6]

Vector Scaling

This feature allows you to scale a 2D vector by a scalar value. The `scale` function multiplies each component of the vector by the scalar.

const vec2 = require('gl-vec2');
let v = vec2.fromValues(1, 2);
let scaled = vec2.scale([], v, 2);
console.log(scaled); // Output: [2, 4]

Vector Dot Product

This feature allows you to compute the dot product of two 2D vectors. The `dot` function returns the scalar product of the vectors.

const vec2 = require('gl-vec2');
let v1 = vec2.fromValues(1, 2);
let v2 = vec2.fromValues(3, 4);
let dotProduct = vec2.dot(v1, v2);
console.log(dotProduct); // Output: 11

Vector Length

This feature allows you to compute the length (magnitude) of a 2D vector. The `length` function returns the Euclidean length of the vector.

const vec2 = require('gl-vec2');
let v = vec2.fromValues(3, 4);
let length = vec2.length(v);
console.log(length); // Output: 5

Other packages similar to gl-vec2

Keywords

FAQs

Package last updated on 24 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc