Giter VIP home page Giter VIP logo

2dvector's Introduction

2D-VECTOR-LIBRARY-

2D vector library in C

Provides vector functions, similar to pygame.math.Vector2 library

// Vector intialization
struct vector2d;
void vecinit(struct vector2d *v, float x, float y);

// Vector distance
float distance_to(struct vector2d v1, struct vector2d v2);
float distance_squared_to(struct vector2d v1, struct vector2d v2);

// Vector length
float vlength(struct vector2d *v);
float length_squared(struct vector2d v);

// Vectors operations inplace (similar to elementwise in pygame.math.Vector2 library)
// the result of the operation is assigned to the variable v1 (v2 remains unchanged)
void subv_inplace(struct vector2d *v1, struct vector2d v2);
void addv_inplace(struct vector2d *v1, struct vector2d v2);
void divv_inplace(struct vector2d *v1, struct vector2d v2);
void mulv_inplace(struct vector2d *v1, struct vector2d v2);

// Vector operations elementwise (similar to elementwise in pygame.math.Vector2 library)
// Return a new vector2d (v1 and v2 remains unchanged)
struct vector2d mulcomponents(struct vector2d v1, struct vector2d v2);
struct vector2d addcomponents(struct vector2d v1, struct vector2d v2);
struct vector2d subcomponents(struct vector2d v1, struct vector2d v2);
struct vector2d divcomponents(struct vector2d v1, struct vector2d v2);

// Scaling vectors 
void scalevector2d_self(float c, struct vector2d *v);
struct vector2d scalevector2d(float c, struct vector2d *v);

// Dot product 
float dot(struct vector2d *v1, struct vector2d *v2);

// Normalisation
void normalize (struct vector2d *v);

// Vector rotation
void vrotate_deg(struct vector2d *v, float deg);
void vrotate_rad(struct vector2d *v, float rad);

// Vector Angle
float angle_to(struct vector2d v1, struct vector2d v2);
float vangle_rad(struct vector2d v);
float vangle_deg(struct vector2d v);

2dvector's People

Contributors

yoyoberenguer avatar

Watchers

 avatar  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.