Vector - Polkm105/DesignPatternPractice GitHub Wiki

COMPLETE

This section contains all functions relating to CP_Vector

Table Of Contents

CP_Vector_Set

Manually create a CP_Vector by inputting its two values

Function

CP_Vector CP_Vector_Set(float x, float y);

Parameters

  • x (float) - The x value you want in the vector
  • y (float) - The y value you want in the vector

Return

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(0, 0, 0, 255));
  CP_Vector random_v = CP_Vector_Set(CP_Random_RangeFloat(0, 50), CP_Random_RangeFloat(0, 50));
}

Related

CP_Vector_Zero

Creates a CP_Vector with both values being 0

Function

CP_Vector CP_Vector_Zero();

Parameters

This function has no parameters

Return

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(0, 0, 0, 255));
  CP_Vector zero_v = CP_Vector_Zero();
}

Related

CP_Vector_Negate

Returns a vector with the negated values of a given CP_Vector

Function

CP_Vector CP_Vector_Negate(CP_Vector v);

Parameters

  • v (CP_Vector) - The vector to negate the value in

Return

  • CP_Vector - A vector with the negated values

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(0, 0, 0, 255));
  CP_Vector random_v = CP_Vector_Set(CP_Random_RangeFloat(0, 50), CP_Random_RangeFloat(0, 50));
  CP_Vector negated_v = CP_Vector_Negate(random_v);
}

Related

CP_Vector_Add

Adds together the values within two given CP_Vectors

Function

CP_Vector CP_Vector_Add(CP_Vector a, CP_Vector b);

Parameters

Return

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(0, 0, 0, 255));
  CP_Vector vec_a = CP_Vector_Set(1, 1);
  CP_Vector vec_b = CP_Vector_Set(-1, 6);
  CP_Vector sum_v = CP_Vector_Add(vec_a, vec_b);  // Returns a vector with values (0, 7)
}

Related

CP_Vector_Subtract

Subtracts the values within two given CP_Vectors

Function

CP_Vector CP_Vector_Subtract(CP_Vector a, CP_Vector b);

Parameters

  • a (CP_Vector) - The vector that will subtract b
  • b (CP_Vector) - The vector that will be subtracted from a

Return

  • CP_Vector - The difference of the two vectors

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(0, 0, 0, 255));
  CP_Vector vec_a = CP_Vector_Set(1, 1);
  CP_Vector vec_b = CP_Vector_Set(-1, 6);
  CP_Vector sum_v = CP_Vector_Subtract(vec_a, vec_b);  // Returns a vector with values (2, -5)
}

Related

CP_Vector_Scale

Returns a new CP_Vector that has the values of the given CP_Vector scaled by the given scalar

Function

CP_Vector CP_Vector_Scale(CP_Vector a, float scale);

Parameters

  • a (CP_Vector) - The vector to scale
  • scale (float) - The value to scale the vector by

Return

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(0, 0, 0, 255));
  CP_Vector vec_a = CP_Vector_Set(1, 1);
  CP_Vector sum_v = CP_Vector_Scale(vec_a, 4);  // Returns a vector with values (4, 4)
}

Related

CP_Vector_Normalize

Returns a new CP_Vector that is the noramlized version of the given CP_Vector

Function

CP_Vector CP_Vector_Normalize(CP_Vector vec);

Parameters

Return

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(0, 0, 0, 255));
  CP_Vector vec_a = CP_Vector_Set(3, 4);
  CP_Vector norm_v = CP_Vector_Normalize(vec_a);  // Returns a vector with values (.6, .8)
}

Related

CP_Vector_MatrixMultiply

Creates a CP_Vector by multiplying the given CP_Vector by the given CP_Matrix

Function

CP_Vector CP_Vector_MatrixMultiply(CP_Matrix matrix, CP_Vector vec);

Parameters

  • matrix (CP_Matrix) - The matrix to use in the multiplication
  • vec (CP_Vector) - The vector to use in the multiplication

Return

  • CP_Vector - The vector created by matrix * vec

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(0, 0, 0, 255));
  CP_Vector vec_a = CP_Vector_Set(3, 4);
  CP_Matrix matrix_a = CP_Matrix_Translate(CP_Vector_Set(10, 6));
  CP_Vector norm_v = CP_Vector_MatrixMultiply(matrix_a, vec_a); 
}

Related

CP_Vector_Length

Calculates the length of a given CP_Vector

Function

float CP_Vector_Length(CP_Vector vec);

Parameters

  • vec (CP_Vector) - The vector to find the length of

Return

  • float - the length of the given vector

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(0, 0, 0, 255));
  CP_Vector vec_a = CP_Vector_Set(3, 4);
  float vec_length = CP_Vector_Length(vec_a); // returns 5 
}

Related

CP_Vector_Distance

Calculates the distance between two given CP_Vectors

Function

float CP_Vector_Distance(CP_Vector a, CP_Vector b);

Parameters

  • a (CP_Vector) - The first point in calculation
  • b (CP_Vector) - The second point in calculation

Return

  • float - the distance between the two given points

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(0, 0, 0, 255));
  CP_Vector vec_a = CP_Vector_Set(3, 4);
  CP_Vector vec_b = CP_Vector_Set(0, 0);
  float dist = CP_Vector_Distance(vec_a, vec_b); // returns 5 
}

Related

CP_Vector_DotProduct

Calculates the dot product of two given CP_Vectors

Function

float CP_Vector_DotProduct(CP_Vector a, CP_Vector b);

Parameters

  • a (CP_Vector) - The first vector in calculation
  • b (CP_Vector) - The second vector in calculation

Return

  • float - the dot product of the two given CP_Vectors

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(0, 0, 0, 255));
  CP_Vector vec_a = CP_Vector_Set(1, 0);
  CP_Vector vec_b = CP_Vector_Set(0, 1);
  float dist = CP_Vector_DotProduct(vec_a, vec_b); // returns 0 since a and b are perpendicular 
}

Related

CP_Vector_CrossProduct

Calculates the magnitude of the cross product of two given CP_Vectors

Function

float CP_Vector_CrossProduct(CP_Vector a, CP_Vector b);

Parameters

  • a (CP_Vector) - The first vector in calculation
  • b (CP_Vector) - The second vector in calculation

Return

  • float - the length of the cross product of the two given CP_Vectors

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(0, 0, 0, 255));
  CP_Vector vec_a = CP_Vector_Set(1, 0);
  CP_Vector vec_b = CP_Vector_Set(0, 1);
  float crossPLength = CP_Vector_CrossProduct(vec_a, vec_b); // returns 1 since a x b = (0, 0, 1)
}

Related

CP_Vector_Angle

Calculates the angle between two given CP_Vectors

Function

float CP_Vector_Angle(CP_Vector a, CP_Vector b);

Parameters

  • a (CP_Vector) - The first vector in calculation
  • b (CP_Vector) - The second vector in calculation

Return

Example

void update()
{
  CP_Graphics_ClearBackground(CP_Color_Create(0, 0, 0, 255));
  CP_Vector vec_a = CP_Vector_Set(1, 0);
  CP_Vector vec_b = CP_Vector_Set(0, 1);
  float crossPLength = CP_Vector_Angle(vec_a, vec_b); // returns 90
}

Related