GithubHelp home page GithubHelp logo

vector's Introduction

Vector

A DragonRuby GTK Library to work with vector (2D or 3D)

... work in progress ...

Methods

add(Vector) -> new Vector

Add a Vector

a = Vector.new(2, 1)
b = Vector.new(5, 2)
c = a.add b       # => c = {x: 7, y: 2, z: 0 }

sub(Vector) -> new Vector

Substract a Vector

a = Vector.new(2, 1, 1)
b = Vector.new(5, 2)
c = a.sub b       # => c = {x: -3, y: -1, z: 1 }

mult(Number) -> new Vector

Multiplies by a scalar

a = Vector.new(6, 2)
c = a.mult 3      # => c = {x: 18, y: 6, z: 0 }

div(Number) -> new Vector

Divide by a scalar Return nil if scalar = 0

a = Vector.new(6, 2, 1.5)
c = a.div 2       # => c = {x: 3, y: 1, z: 0.725 }

dot(Vector) -> Number

Make the dot product of two vectors

a = Vector.new(2 ,1 ,0)
b = Vector.new(1, 3)
c = a.dot b       # => c = 6

cross(Vector) -> new Vector

Return the cross products of vectors

mag -> Number

Return the magnitude of the vector

a = Vector.new(3, 4)
c = a.mag         # => c = 5

mag_squared -> Number

Return the squared magnitude of the vector (faster than mag)

a = Vector.new(3, 4)
c = a.mag_squared         # => c = 25

dir -> Number

Return, in radians, the direction (heading) of a vector

set!(x, y, z) -> Vector

Set the value of the vector to x, y, z

a = Vector.new(3, 1, 4)
a.set!(1, 5, 9)
puts a # => {x: 1, y: 5, z: 9}

dist(Vector) -> Number

Return the distance between two points(as vectors)

vector's People

Contributors

littleb0xes avatar

Watchers

James Cloos 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.