Skip to content

Physics

Functions

Bitmap Circle Collision

Bitmap Circle Collision

Tests if a bitmap drawn at pt would intersect with a circle.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
ptPoint 2dThe location where the bitmap is drawn
circCircleThe circle to test

Return Type: Boolean

Signatures:

bool bitmap_circle_collision(bitmap bmp, const point_2d &pt, const circle &circ)

Bitmap Circle Collision

Tests if a bitmap drawn at x, y would intersect with a circle.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
xDoubleThe x location where the bitmap is drawn
yDoubleThe y location where the bitmap is drawn
circCircleThe circle to test

Return Type: Boolean

Signatures:

bool bitmap_circle_collision(bitmap bmp, double x, double y, const circle &circ)

Bitmap Circle Collision

Tests if a bitmap cell drawn using a passed in translation, will intersect with a circle. You can use this to detect collisions between bitmaps and circles.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
translationMatrix 2dThe matrix used to transfrom the bitmap when drawing
circCircleThe circle to test

Return Type: Boolean

Signatures:

bool bitmap_circle_collision(bitmap bmp, int cell, const matrix_2d &translation, const circle &circ)

Bitmap Circle Collision

Tests if a bitmap cell drawn at pt would intersect with a circle.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
ptPoint 2dThe location where the bitmap is drawn
circCircleThe circle to test

Return Type: Boolean

Signatures:

bool bitmap_circle_collision(bitmap bmp, int cell, const point_2d &pt, const circle &circ)

Bitmap Circle Collision

Tests if a bitmap cell drawn at x, y would intersect with a circle.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
xDoubleThe x location where the bitmap is drawn
yDoubleThe y location where the bitmap is drawn
circCircleThe circle to test

Return Type: Boolean

Signatures:

bool bitmap_circle_collision(bitmap bmp, int cell, double x, double y, const circle &circ)

Bitmap Collision

Bitmap Collision

Check if two bitmaps collide.

Parameters:

NameTypeDescription
bmp1BitmapThe first bitmap
x1DoubleThe x location where the first bitmap is drawn
y1DoubleThe y location where the first bitmap is drawn
bmp2BitmapThe second bitmap
x2DoubleThe x location where the second bitmap is drawn
y2DoubleThe y location where the second bitmap is drawn

Return Type: Boolean

Signatures:

bool bitmap_collision(bitmap bmp1, double x1, double y1, bitmap bmp2, double x2, double y2)

Bitmap Collision

Check if two bitmaps collide.

Parameters:

NameTypeDescription
bmp1BitmapThe first bitmap
pt1Point 2dThe point where bitmap 1 is drawn
bmp2BitmapThe second bitmap
pt2Point 2dThe point where bitmap 2 is drawn

Return Type: Boolean

Signatures:

bool bitmap_collision(bitmap bmp1, const point_2d &pt1, bitmap bmp2, const point_2d &pt2)

Bitmap Collision

Check if two bitmaps collide, based on their cell and transform matricies.

Parameters:

NameTypeDescription
bmp1BitmapThe first bitmap
cell1IntegerThe cell of the first bitmap.
matrix1Matrix 2dThe transformation for the first matrix
bmp2BitmapThe second bitmap
cell2IntegerThe cell of the second bitmap.
matrix2Matrix 2dThe transformation for the second matrix

Return Type: Boolean

Signatures:

bool bitmap_collision(bitmap bmp1, int cell1, const matrix_2d &matrix1, bitmap bmp2, int cell2, const matrix_2d &matrix2)

Bitmap Collision

Check if two bitmaps collide.

Parameters:

NameTypeDescription
bmp1BitmapThe first bitmap
cell1IntegerThe cell of the first bitmap.
pt1Point 2dThe point where bitmap 1 is drawn
bmp2BitmapThe second bitmap
cell2IntegerThe cell of the second bitmap.
pt2Point 2dThe point where bitmap 2 is drawn

Return Type: Boolean

Signatures:

bool bitmap_collision(bitmap bmp1, int cell1, const point_2d &pt1, bitmap bmp2, int cell2, const point_2d &pt2)

Bitmap Collision

Check if two bitmaps collide.

Parameters:

NameTypeDescription
bmp1BitmapThe first bitmap
cell1IntegerThe cell of the first bitmap.
x1DoubleThe x location where the first bitmap is drawn
y1DoubleThe y location where the first bitmap is drawn
bmp2BitmapThe second bitmap
cell2IntegerThe cell of the second bitmap.
x2DoubleThe x location where the second bitmap is drawn
y2DoubleThe y location where the second bitmap is drawn

Return Type: Boolean

Signatures:

bool bitmap_collision(bitmap bmp1, int cell1, double x1, double y1, bitmap bmp2, int cell2, double x2, double y2)

Bitmap Point Collision

Bitmap Point Collision

Tests if a bitmap drawn using the passed in translation matrix would draw a pixel at the passed in point. Use to check collisions between a point and a bitmap.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test.
translationMatrix 2dThe translation matrix that represents the position, scale, and rotation of the bitmap when it is drawn.
ptPoint 2dThe point in the resulting drawing that is being tested.

Return Type: Boolean

Signatures:

bool bitmap_point_collision(bitmap bmp, const matrix_2d &translation, const point_2d &pt)

Bitmap Point Collision

Tests if a bitmap drawn at the bmp_pt point would draw a pixel at point pt. Use to check collisions between a point and a bitmap.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test.
bmp_ptPoint 2dThe point where the bitmap is drawn.
ptPoint 2dThe point in the resulting drawing that is being tested.

Return Type: Boolean

Signatures:

bool bitmap_point_collision(bitmap bmp, const point_2d &bmp_pt, const point_2d &pt)

Bitmap Point Collision

Tests if a bitmap drawn at x,y would draw a pixel at the passed in point. Use to check collisions between a point and a bitmap.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test.
bmp_xDoubleThe x location where the bitmap is drawn
bmp_yDoubleThe y location where the bitmap is drawn
xDoubleThe x location of the point to test
yDoubleThe y location of the point to test

Return Type: Boolean

Signatures:

bool bitmap_point_collision(bitmap bmp, double bmp_x, double bmp_y, double x, double y)

Bitmap Point Collision

Tests if a bitmap cell drawn using the passed in translation matrix would draw a pixel at the passed in point.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test.
cellIntegerThe cell of the bitmap to check.
translationMatrix 2dThe translation matrix that represents the position, scale, and rotation of the bitmap when it is drawn.
ptPoint 2dThe point in the resulting drawing that is being tested.

Return Type: Boolean

Signatures:

bool bitmap_point_collision(bitmap bmp, int cell, const matrix_2d &translation, const point_2d &pt)

Bitmap Point Collision

Tests if a cell of a bitmap drawn at x,y would draw a pixel at the passed in point. Use to check collisions between a point and a bitmap.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to test
bmp_ptPoint 2dThe point where the bitmap is drawn.
ptPoint 2dThe point in the resulting drawing that is being tested.

Return Type: Boolean

Signatures:

bool bitmap_point_collision(bitmap bmp, int cell, const point_2d &bmp_pt, const point_2d &pt)

Bitmap Point Collision

Tests if a cell of a bitmap drawn at x,y would draw a pixel at the passed in point. Use to check collisions between a point and a bitmap.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to test
bmp_xDoubleThe x location where the bitmap is drawn
bmp_yDoubleThe y location where the bitmap is drawn
xDoubleThe x location of the point to test
yDoubleThe y location of the point to test

Return Type: Boolean

Signatures:

bool bitmap_point_collision(bitmap bmp, int cell, double bmp_x, double bmp_y, double x, double y)

Bitmap Rectangle Collision

Bitmap Rectangle Collision

Tests if a bitmap drawn at pt would intersect with a rectangle.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
ptPoint 2dThe location where the bitmap is drawn
rectRectangleThe rectangle to test

Return Type: Boolean

Signatures:

bool bitmap_rectangle_collision(bitmap bmp, const point_2d &pt, const rectangle &rect)

Bitmap Rectangle Collision

Tests if a bitmap drawn at x, y would intersect with a rectangle.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
xDoubleThe x location where the bitmap is drawn
yDoubleThe y location where the bitmap is drawn
rectRectangleThe rectangle to test

Return Type: Boolean

Signatures:

bool bitmap_rectangle_collision(bitmap bmp, double x, double y, const rectangle &rect)

Bitmap Rectangle Collision

Tests if a bitmap cell drawn using a passed in translation, will intersect with a rectangle. You can use this to detect collisions between bitmaps and rectangles.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
translationMatrix 2dThe matrix used to transfrom the bitmap when drawing
rectRectangleThe rectangle to test

Return Type: Boolean

Signatures:

bool bitmap_rectangle_collision(bitmap bmp, int cell, const matrix_2d &translation, const rectangle &rect)

Bitmap Rectangle Collision

Tests if a bitmap cell drawn at pt would intersect with a rectangle.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
ptPoint 2dThe location where the bitmap is drawn
rectRectangleThe rectangle to test

Return Type: Boolean

Signatures:

bool bitmap_rectangle_collision(bitmap bmp, int cell, const point_2d &pt, const rectangle &rect)

Bitmap Rectangle Collision

Tests if a cell of the bitmap drawn at x, y would intersect with a rectangle.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
xDoubleThe x location where the bitmap is drawn
yDoubleThe y location where the bitmap is drawn
rectRectangleThe rectangle to test

Return Type: Boolean

Signatures:

bool bitmap_rectangle_collision(bitmap bmp, int cell, double x, double y, const rectangle &rect)

Sprite Bitmap Collision

Sprite Bitmap Collision

Tests if a sprite will collide with a bitmap drawn at the indicated location.

Parameters:

NameTypeDescription
sSpriteThe sprite to test
bmpBitmapThe bitmap to test
xDoubleThe x location where the bitmap is drawn
yDoubleThe y location where the bitmap is drawn

Return Type: Boolean

Signatures:

bool sprite_bitmap_collision(sprite s, bitmap bmp, double x, double y)

Sprite Bitmap Collision

Tests if a sprite will collide with a bitmap drawn at the indicated location.

Parameters:

NameTypeDescription
sSpriteThe sprite to test
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
ptPoint 2dThe point where the bitmap is drawn

Return Type: Boolean

Signatures:

bool sprite_bitmap_collision(sprite s, bitmap bmp, int cell, const point_2d &pt)

Sprite Bitmap Collision

Tests if a sprite will collide with a bitmap drawn at the indicated location.

Parameters:

NameTypeDescription
sSpriteThe sprite to test
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
xDoubleThe x location where the bitmap is drawn
yDoubleThe y location where the bitmap is drawn

Return Type: Boolean

Signatures:

bool sprite_bitmap_collision(sprite s, bitmap bmp, int cell, double x, double y)

Sprite Collision

Tests if two given sprites s1 and s2 are collided

Parameters:

NameTypeDescription
s1Spritethe first Sprite to test
s2Spritethe second Sprite to test

Return Type: Boolean

Signatures:

bool sprite_collision(sprite s1, sprite s2)

Sprite Point Collision

Tests if a sprite is drawn at a given point.

Parameters:

NameTypeDescription
sSpriteThe sprite to test
ptPoint 2dThe point to check

Return Type: Boolean

Signatures:

bool sprite_point_collision(sprite s, const point_2d &pt)

Sprite Rectangle Collision

Tests if a sprite is drawn within an given area (rectangle).

Parameters:

NameTypeDescription
sSpriteThe sprite to test
rectRectangleThe rectangle to check

Return Type: Boolean

Signatures:

bool sprite_rectangle_collision(sprite s, const rectangle &rect)

Apply Matrix

Apply Matrix

Use a matrix to transform all of the points in a quad.

Parameters:

NameTypeDescription
matrixMatrix 2dThe matrix with the transformations needed.
qQuadThe quad to transform.

Signatures:

void apply_matrix(const matrix_2d &matrix, quad &q)

Apply Matrix

Use a matrix to transform all of the points in a triangle.

Parameters:

NameTypeDescription
mMatrix 2dThe matrix to be applied to the triangle.
triTriangleThe triangle to tranform.

Signatures:

void apply_matrix(const matrix_2d &m, triangle &tri)

Identity Matrix

Returns the identity matrix. When a matrix_2d or Vector is multiplied by the identity matrix the result is the original matrix or vector.

Return Type: Matrix 2d

Signatures:

matrix_2d identity_matrix()

Matrix Inverse

Calculate the inverse of a matrix.

Parameters:

NameTypeDescription
mMatrix 2dThe matrix to invert.

Return Type: Matrix 2d

Signatures:

matrix_2d matrix_inverse(const matrix_2d &m)

Matrix Multiply

Matrix Multiply

Multiplies the Point 2d parameter v with the [Matrix 2d](/api/physics/#matrix-2d) m and returns the result as a Point 2d. Use this to transform the vector with the matrix (to apply scaling, rotation or translation effects).

Parameters:

NameTypeDescription
mMatrix 2dThe matrix with the transformation to apply.
ptPoint 2dThe point to be transformed.

Return Type: Point 2d

Signatures:

point_2d matrix_multiply(const matrix_2d &m, const point_2d &pt)

Matrix Multiply

Multiplies the two Matrix 2d parameters, m1 by m2, and returns the result as a new Matrix 2d. Use this to combine the effects to two matrix transformations.

Parameters:

NameTypeDescription
m1Matrix 2dThe first matrix
m2Matrix 2dThe second matrix

Return Type: Matrix 2d

Signatures:

matrix_2d matrix_multiply(const matrix_2d &m1, const matrix_2d &m2)

Matrix Multiply

Multiplies the Vector parameter v with the Matrix 2d m and returns the result as a Vector. Use this to transform the vector with the matrix (to apply scaling, rotation or translation effects).

Parameters:

NameTypeDescription
mMatrix 2dThe matrix with the transformation to apply.
vVector 2dThe vector to be transformed.

Return Type: Vector 2d

Signatures:

vector_2d matrix_multiply(const matrix_2d &m, const vector_2d &v)

Matrix To String

This function returns a string representation of a Matrix.

Parameters:

NameTypeDescription
matrixMatrix 2dThe matrix to convert to a string.

Return Type: String

Signatures:

string matrix_to_string(const matrix_2d &matrix)

Rotation Matrix

Returns a rotation matrix that rotates 2d points by the angle.

Parameters:

NameTypeDescription
degDoubleThe amount to rotate points

Return Type: Matrix 2d

Signatures:

matrix_2d rotation_matrix(double deg)

Scale Matrix

Scale Matrix

Create a scale matrix that scales x and y to different degrees.

Parameters:

NameTypeDescription
scalePoint 2dThe amount to scale, with separate x and y components.

Return Type: Matrix 2d

Signatures:

matrix_2d scale_matrix(const point_2d &scale)

Scale Matrix

Create a scale matrix that scales x and y to different degrees.

Parameters:

NameTypeDescription
scaleVector 2dThe amount to scale, with separate x and y components.

Return Type: Matrix 2d

Signatures:

matrix_2d scale_matrix(const vector_2d &scale)

Scale Matrix

Returns a matrix that can be used to scale 2d points (both x and y).

Parameters:

NameTypeDescription
scaleDoubleThe amount to scale points by.

Return Type: Matrix 2d

Signatures:

matrix_2d scale_matrix(double scale)

Scale Rotate Translate Matrix

Create a matrix that can scale, rotate then translate geometry points.

Parameters:

NameTypeDescription
scalePoint 2dThe amount to scale
degDoubleThe amount to rotate
translatePoint 2dThe amount to move

Return Type: Matrix 2d

Signatures:

matrix_2d scale_rotate_translate_matrix(const point_2d &scale, double deg, const point_2d &translate)

Translation Matrix

Translation Matrix

Returns a translation matric used to translate 2d points by the distance in the point_2d.

Parameters:

NameTypeDescription
ptPoint 2dThe point to translate to.

Return Type: Matrix 2d

Signatures:

matrix_2d translation_matrix(const point_2d &pt)

Translation Matrix

Returns a translation matric used to translate 2d points by the distance in the vector_2d.

Parameters:

NameTypeDescription
ptVector 2dThe point to translate to.

Return Type: Matrix 2d

Signatures:

matrix_2d translation_matrix(const vector_2d &pt)

Translation Matrix

Returns a matrix that can be used to translate 2d points. Moving them by dx and dy.

Parameters:

NameTypeDescription
dxDoubleThe amount to move points along the x axis.
dyDoubleThe amount to move points along the y axis.

Return Type: Matrix 2d

Signatures:

matrix_2d translation_matrix(double dx, double dy)

Angle Between

Calculates the angle from one vector to another.

Parameters:

NameTypeDescription
v1Vector 2dThe first vector
v2Vector 2dThe second vector

Return Type: Double

Signatures:

double angle_between(const vector_2d &v1, const vector_2d &v2)

Dot Product

Calculates the dot product (scalar product) between the two vector parameters provided (v1 and v2). It returns the result as a scalar value. If the result is 0.0 it means that the vectors are orthogonal (at right angles to each other). If v1 and v2 are unit vectors (length of 1.0) and the dot product is 1.0, it means that v1 and v2 vectors are parallel.

Parameters:

NameTypeDescription
v1Vector 2dThe first vector
v2Vector 2dThe other vector

Return Type: Double

Signatures:

double dot_product(const vector_2d &v1, const vector_2d &v2)

Is Zero Vector

Returns if the vector is a null/zero vector — having no size or direction.

Parameters:

NameTypeDescription
vVector 2dThe vector

Return Type: Boolean

Signatures:

bool is_zero_vector(const vector_2d &v)

Ray Intersection Point

Casts a ray in a heading and returns true is it intersects with a line

Parameters:

NameTypeDescription
from_ptPoint 2dThe origin of the ray
headingVector 2dThe direction the ray is heading (as a Vector 2d)
lLineThe line to be checked
ptPoint 2dOutputs the point where the line and ray intersect

Return Type: Boolean

Signatures:

bool ray_intersection_point(const point_2d &from_pt, const vector_2d &heading, const line &l, point_2d &pt)

Unit Vector

Returns the unit vector of the parameter vector (v). The unit vector has a magnitude of 1, resulting in a vector that indicates the direction of the original vector.

Parameters:

NameTypeDescription
vVector 2dThe vector

Return Type: Vector 2d

Signatures:

vector_2d unit_vector(const vector_2d &v)

Vector Add

Adds the two passed in vectors returns the result as new Vector 2d.

Parameters:

NameTypeDescription
v1Vector 2dThe first vector.
v2Vector 2dThe other vector.

Return Type: Vector 2d

Signatures:

vector_2d vector_add(const vector_2d &v1, const vector_2d &v2)

Vector Angle

Calculates the angle of a vector

Parameters:

NameTypeDescription
vVector 2dThe vector

Return Type: Double

Signatures:

double vector_angle(const vector_2d v)

Vector From Angle

Returns a Vector 2d from the supplied angle and distance.

Parameters:

NameTypeDescription
angleDoubleThe angle in degrees
magnitudeDoubleThe length of the vector

Return Type: Vector 2d

Signatures:

vector_2d vector_from_angle(double angle, double magnitude)

Vector From Line

Returns a vector that points from the start to the end of a line.

Parameters:

NameTypeDescription
lLineThe line

Return Type: Vector 2d

Signatures:

vector_2d vector_from_line(const line &l)

Vector From Point To Rect

Returns a vector from a point to a rectangle.

Parameters:

NameTypeDescription
ptPoint 2dThe point
rectRectangleThe rectangle

Return Type: Vector 2d

Signatures:

vector_2d vector_from_point_to_rect(const point_2d &pt, const rectangle &rect)

Vector In Rect

Returns true if the resulting vector would end in the rectangle if placed at the origin.

Parameters:

NameTypeDescription
vVector 2dThe vector
rectRectangleThe rectangle

Return Type: Boolean

Signatures:

bool vector_in_rect(const vector_2d &v, const rectangle &rect)

Vector Invert

Returns a new Vector that is an inverted version of the parameter vector (v). In other words, the -/+ sign of the x and y values are changed.

Parameters:

NameTypeDescription
vVector 2dThe vector

Return Type: Vector 2d

Signatures:

vector_2d vector_invert(const vector_2d &v)

Vector Limit

Returns a scaled vector that ensures the new vector points in the same direction as v, but has a magnitude that is limited to the length specified in the limit prameter.

Parameters:

NameTypeDescription
vVector 2dThe vector
limitDoubleIts maximum magnitude

Return Type: Vector 2d

Signatures:

vector_2d vector_limit(const vector_2d &v, double limit)

Vector Magnitude

Returns the magnitude (or “length”) of the vector.

Parameters:

NameTypeDescription
vVector 2dThe vector

Return Type: Double

Signatures:

double vector_magnitude(const vector_2d &v)

Vector Magnitude Squared

Returns the squared magnitude (or “length”) of the vector.

Parameters:

NameTypeDescription
vVector 2dThe vector

Return Type: Double

Signatures:

double vector_magnitude_squared(const vector_2d &v)

Vector Multiply

Multiplies the vector by the passed in value.

Parameters:

NameTypeDescription
v1Vector 2dThe original vector
sDoubleThe amount to multiply by

Return Type: Vector 2d

Signatures:

vector_2d vector_multiply(const vector_2d &v1, double s)

Vector Normal

Returns a new Vector 2d that is perpendicular (“normal”) to the parameter vector v provided. The concept of a “normal” vector is usually extracted from (or associated with) a line. Note: when passed a zero or null vector (a vector with no magnitude or direction) then this function returns a zero/null vector.

Parameters:

NameTypeDescription
vVector 2dThe vector

Return Type: Vector 2d

Signatures:

vector_2d vector_normal(const vector_2d &v)

Vector Out Of Circle From Circle

Returns a vector to back one circle out of another, assuming the first circle was moving at a specified velocity.

Parameters:

NameTypeDescription
srcCircleThe circle that is moving
boundsCircleThe area you want to move the circle out of
velocityVector 2dThe circle’s velocity

Return Type: Vector 2d

Signatures:

vector_2d vector_out_of_circle_from_circle(const circle &src, const circle &bounds, const vector_2d &velocity)

Vector Out Of Circle From Point

Returns the vector out to move a point back out of a circle, given the point was moving at the specified velocity.

Parameters:

NameTypeDescription
ptPoint 2dThe point that is moving
cCircleThe circle you want to move the point out of
velocityVector 2dThe point’s velocity

Return Type: Vector 2d

Signatures:

vector_2d vector_out_of_circle_from_point(const point_2d &pt, const circle &c, const vector_2d &velocity)

Vector Out Of Rect From Circle

Returns a vector that can be used to move a circle back out of a rectangle, given that the circle is moving at the specified velocity.

Parameters:

NameTypeDescription
cCircleThe circle that is moving
rectRectangleThe area you wan to move the circle out of
velocityVector 2dThe circle’s velocity

Return Type: Vector 2d

Signatures:

vector_2d vector_out_of_rect_from_circle(const circle &c, const rectangle &rect, const vector_2d &velocity)

Vector Out Of Rect From Point

Determines the vector needed to move back from point pt out of rectangle rect given the point was moving at the velocity specified.

Parameters:

NameTypeDescription
ptPoint 2dThe point you want to move out of a rectangle
rectRectangleThe rectangle to move out of
velocityVector 2dThe velocity of the point. This is used to determine where the point should return to.

Return Type: Vector 2d

Signatures:

vector_2d vector_out_of_rect_from_point(const point_2d &pt, const rectangle &rect, const vector_2d &velocity)

Vector Out Of Rect From Rect

Returns the vector needed to move rectangle src back out of rectangle bounds assuming the rectangle was moving at the velocity specified.

Parameters:

NameTypeDescription
srcRectangleThe rectangle you want to move.
boundsRectangleThe area you want to move the rectangle out of
velocityVector 2dThe velocity of the src rectangle

Return Type: Vector 2d

Signatures:

vector_2d vector_out_of_rect_from_rect(const rectangle &src, const rectangle &bounds, const vector_2d &velocity)

Vector Point To Point

Returns a Vector 2d created from the difference from the p1 to the second p2 points (Point2D).

Parameters:

NameTypeDescription
startPoint 2dThe starting point
end_ptPoint 2dThe ending point

Return Type: Vector 2d

Signatures:

vector_2d vector_point_to_point(const point_2d &start, const point_2d &end_pt)

Vector Subtract

Subtracts the second vector parameter (v2) from the first vector (v1) and returns the result as new Vector 2d.

Parameters:

NameTypeDescription
v1Vector 2dThe first vector.
v2Vector 2dThe other vector.

Return Type: Vector 2d

Signatures:

vector_2d vector_subtract(const vector_2d &v1, const vector_2d &v2)

Vector To

Vector To

Returns a new Vector 2d using the x and y value of a Point 2d parameter. This is a vector from the origin to that point.

Parameters:

NameTypeDescription
p1Point 2dThe point

Return Type: Vector 2d

Signatures:

vector_2d vector_to(const point_2d &p1)

Vector To

Returns a vector to the indicated point.

Parameters:

NameTypeDescription
xDoubleThe amount to move horizontally
yDoubleThe amount to move vertically

Return Type: Vector 2d

Signatures:

vector_2d vector_to(double x, double y)

Vector To String

Get a text description of the Vector 2d.

Parameters:

NameTypeDescription
vVector 2dThe vector

Return Type: String

Signatures:

string vector_to_string(const vector_2d &v)

Vectors Equal

Determines if two vectors are the same.

Parameters:

NameTypeDescription
v1Vector 2dThe first vector
v2Vector 2dThe other vector

Return Type: Boolean

Signatures:

bool vectors_equal(const vector_2d &v1, const vector_2d v2)

Vectors Not Equal

Determines if two vectors are not the same.

Parameters:

NameTypeDescription
v1Vector 2dThe first vector
v2Vector 2dThe other vector

Return Type: Boolean

Signatures:

bool vectors_not_equal(const vector_2d &v1, const vector_2d v2)

Types

Matrix 2d

FieldTypeDescription
elementsDoubleThe elements of the matrix

In SplashKit, matrices can be used to combine together a number of operations that need to be performed on Vector 2d values. You can translate, rotate and scale, and combine these together into a single matrix that can then be applied to vectors and points.