Git Product home page Git Product logo

vector_math's Introduction

vector_math

==============

Build Status

Introduction

A Vector math library for 2D and 3D applications.

Features

  • 2D,3D, and 4D vector and matrix types.
  • Quaternion type for animating rotations.
  • Flexible getters and setters, for example, position.xwz = color.grb;.
  • Fully documented.
  • Well tested.
  • Heavily optimized.

Libraries using vector_math

Getting Started

1. Add the following to your project's pubspec.yaml and run pub install.

dependencies:
  vector_math:
    git: https://github.com/johnmccutchan/vector_math.git

2. Add the correct import for your project.

import 'package:vector_math/vector_math.dart';

Documentation

Read the docs

Examples

1. Using the GLSL getter and setter syntax.

void main() {
	Vector3 x = new Vector3.zero(); // Zero vector
	Vector4 y = new Vector4.splat(4.0); // Vector with 4.0 in all lanes
	x.zyx = y.xzz; // Sets z,y,x the values in x,z,z
}

2. Transforming a vector.

void main() {
	// Rotation of pi/2 degrees around the Y axis followed by a 
	// translation of (5.0, 2.0, 3.0).
	Matrix4 T = new Matrix4.rotationY(pi*0.5).translate(5.0, 2.0, 3.0);
	// A point.
	Vector3 position = new Vector3(1.0, 1.0, 1.0);
	// Transform position by T.
	T.transform3(position);
}

3. Invert a matrix

void main() {
	// Rotation of 90 degrees around the Y axis followed by a 
	// translation of (5.0, 2.0, 3.0).
	Matrix4 T = new Matrix4.rotationY(pi*0.5).translate(5.0, 2.0, 3.0);
	// Invert T.
	T.invert();
	// Invert just the rotation in T.
	T.invertRotation();
}

4. Rotate a vector using a quaternion

void main() {
	// The X axis.
	Vector3 axis = new Vector3(1.0, 0.0, 0.0);
	// 90 degrees.
	double angle = pi/2.0;
	// Quaternion encoding a 90 degree rotation along the X axis. 
	Quaternion q = new Quaternion.axisAngle(axis, angle);
	// A point.
	Vector3 point = new Vector3(1.0, 1.0, 1.0);
	// Rotate point by q.
	q.rotate(point);
}

vector_math's People

Contributors

adam-singer avatar andersforsell avatar coderespawn avatar dmah42 avatar donny-dont avatar fkleon avatar fox32 avatar johnmccutchan avatar laszlokorte avatar lohandus avatar pseudopeach avatar steveno avatar toji avatar zach-brockway avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.