bitlib_c  0.2.4
Classes | Typedefs | Functions
point.h File Reference
#include <stdbool.h>

Go to the source code of this file.

Classes

struct  Point
 
struct  Point_List
 

Typedefs

typedef struct Point bl_point
 
typedef struct Point_List bl_point_list
 

Functions

bl_point_listbl_make_point_list ()
 
void bl_add_point_xy (bl_point_list *list, double x, double y)
 
void bl_add_point (bl_point_list *list, bl_point *p)
 
int bl_point_list_count (bl_point_list *list)
 
void bl_point_list_destroy (bl_point_list *list)
 
bl_pointbl_make_point (double x, double y)
 
bl_pointbl_lerp_point (double t, bl_point *p0, bl_point *p1)
 
bl_pointbl_random_point (double x, double y, double w, double h)
 
bl_pointbl_random_point_in_circle (double x, double y, double r)
 
bl_pointbl_random_point_in_triangle (bl_point *p0, bl_point *p1, bl_point *p2)
 
bl_pointbl_point_from_polar (double angle, double radius)
 
double bl_point_distance (bl_point *p0, bl_point *p1)
 
double bl_point_magnitude (bl_point *p)
 
double bl_point_angle (bl_point *p)
 
void bl_point_translate (bl_point *p, double x, double y)
 
void bl_point_scale (bl_point *p, double sx, double sy)
 
void bl_point_rotate (bl_point *p, double angle)
 
double bl_dot_product (bl_point *p0, bl_point *p1, bl_point *p2, bl_point *p3)
 
double bl_angle_between (bl_point *p0, bl_point *p1, bl_point *p2, bl_point *p3)
 
bl_pointbl_bezier_point (bl_point *p0, bl_point *p1, bl_point *p2, bl_point *p3, double t)
 
bl_pointbl_quadratic_point (bl_point *p0, bl_point *p1, bl_point *p2, double t)
 
bl_pointbl_segment_intersect (bl_point *p0, bl_point *p1, bl_point *p2, bl_point *p3)
 
bl_pointbl_tangent_point_to_circle (bl_point *p, double x, double y, double r, bool anticlockwise)
 

Typedef Documentation

◆ bl_point

typedef struct Point bl_point

A struct for holding a single point in a linked list.

◆ bl_point_list

typedef struct Point_List bl_point_list

A struct holding the head and tail of a linked list.

Function Documentation

◆ bl_add_point()

void bl_add_point ( bl_point_list list,
bl_point p 
)

Adds a point to a point list.

Parameters
bl_point_list*list The list to add to.
bl_point*point The point to add.

Examples

bl_point *p = bl_make_point(100, 100);
bl_add_point(path, p);

◆ bl_add_point_xy()

void bl_add_point_xy ( bl_point_list list,
double  x,
double  y 
)

Adds an x, y point to a point list.

Parameters
bl_point_list*list The list to add to.
doublex The x value of the point to add.
doubley The y value of the point to add.

Examples

bl_add_point_xy(path, 100, 100);

◆ bl_angle_between()

double bl_angle_between ( bl_point p0,
bl_point p1,
bl_point p2,
bl_point p3 
)

Returns the angle between two lines defined by four points.

Parameters
bl_point*p0 The first point of the first line.
bl_point*p1 The second point of the first line.
bl_point*p2 The first point of the second line.
bl_point*p4 The second point of the second line.
Returns
double

Examples

bl_point *p0 = bl_make_point(100, 100);
bl_point *p1 = bl_make_point(200, 150);
bl_point *p2 = bl_make_point(100, 100);
bl_point *p3 = bl_make_point(140, 300);
double angle = bl_angle_between(p0, p1, p2, p3);

◆ bl_bezier_point()

bl_point* bl_bezier_point ( bl_point p0,
bl_point p1,
bl_point p2,
bl_point p3,
double  t 
)

Returns a point on a Bezier curve.

The t parameter is in the range of 0 to 1. 0 will return the first point. 1 will return the final point. A value between 0 and 1 will return a point along the Bezier path formed by the four points.

Parameters
bl_point*p0 The first point.
bl_point*p1 The second point.
bl_point*p2 The third point.
bl_point*p3 The fourth point.
doublet The interpolation value.
Returns
bl_point*

Examples

bl_point *p0 = bl_make_point(100, 100);
bl_point *p1 = bl_make_point(200, 150);
bl_point *p2 = bl_make_point(300, 100);
bl_point *p3 = bl_make_point(400, 300);
bl_point *p4 = bl_bezier_point(p0, p1, p2, p3, 0.2);

◆ bl_dot_product()

double bl_dot_product ( bl_point p0,
bl_point p1,
bl_point p2,
bl_point p3 
)

Returns the dot product of two angles formed by four points.

Parameters
bl_point*p0 The first point of the first line.
bl_point*p1 The second point of the first line.
bl_point*p2 The first point of the second line.
bl_point*p4 The second point of the second line.
Returns
double

Examples

bl_point *p0 = bl_make_point(100, 100);
bl_point *p1 = bl_make_point(200, 150);
bl_point *p2 = bl_make_point(100, 100);
bl_point *p3 = bl_make_point(140, 300);
double dp = bl_dot_product(p0, p1, p2, p3);

◆ bl_lerp_point()

bl_point* bl_lerp_point ( double  t,
bl_point p0,
bl_point p1 
)

Returns a new point interpolated between two other points.

Parameters
doublet The interpolation value. Usually 0 to 1.
bl_point*p0 The first point.
bl_point*p1 The second point.
Returns
bl_point*

Examples

bl_point *p0 = bl_make_point(100, 100);
bl_point *p1 = bl_make_point(200, 500);
bl_point *p2 = bl_lerp_point(0.35, p0, p1);

◆ bl_make_point()

bl_point* bl_make_point ( double  x,
double  y 
)

Creates a new point.

Parameters
doublex The x value of the point.
doubley The y value of the point.
Returns
bl_point*

Examples

bl_point *p = bl_make_point(100, 100);

◆ bl_make_point_list()

bl_point_list* bl_make_point_list ( )

Creates a linked list of point objects.

Returns
bl_point_list*

Examples

bl_point_list *path = bl_make_point_list();

◆ bl_point_angle()

double bl_point_angle ( bl_point p)

Returns the angle from the origin to a point.

Parameters
bl_point*p The point.
Returns
double

Examples

bl_point *p = bl_make_point(200, 150);
double angle = bl_point_angle(p);

◆ bl_point_distance()

double bl_point_distance ( bl_point p0,
bl_point p1 
)

Returns the distance between two points.

Parameters
bl_point*p0 The first point.
bl_point*p1 The second point.
Returns
double

Examples

bl_point *p0 = bl_make_point(200, 150);
bl_point *p1 = bl_make_point(140, 300);
double dist = bl_point_distance(p0, p1);

◆ bl_point_from_polar()

bl_point* bl_point_from_polar ( double  angle,
double  radius 
)

Returns a new point based on an angle and radius.

Parameters
doubleangle The angle from the origin.
doubleradius The distance from the origin.
Returns
bl_point*

Examples

bl_point *p = bl_point_from_polar(PI / 4, 100);

◆ bl_point_list_count()

int bl_point_list_count ( bl_point_list list)

Returns the number of points in a point list.

Parameters
bl_point_list*list The list to get a count for.
Returns
int

Examples

int count = bl_point_list_count(path);

◆ bl_point_list_destroy()

void bl_point_list_destroy ( bl_point_list list)

Frees the memory for each point in a point list and for the list itself.

Parameters
bl_point_list*list The list to destroy.

Examples

bl_point_list_destroy(path);

◆ bl_point_magnitude()

double bl_point_magnitude ( bl_point p)

Returns the magnitude (distance from origin) of a point.

Parameters
bl_point*p The point.
Returns
double

Examples

bl_point *p = bl_make_point(200, 150);
double mag = bl_point_magnitude(p);

◆ bl_point_rotate()

void bl_point_rotate ( bl_point p,
double  angle 
)

Rotates a point around the origin.

Parameters
bl_point*p The point.
doubleangle The angle to rotate by.

Examples

bl_point *p = bl_make_point(200, 150);
bl_point_rotate(p, PI / 4);

◆ bl_point_scale()

void bl_point_scale ( bl_point p,
double  sx,
double  sy 
)

Scales a point from the origin.

Parameters
bl_point*p The point.
doublesx How much to scale on the x-axis.
doublesy How much to scale on the y-axis.

Examples

bl_point *p = bl_make_point(200, 150);
bl_point_scale(p, 2, 3);

◆ bl_point_translate()

void bl_point_translate ( bl_point p,
double  x,
double  y 
)

Translates a point.

Parameters
bl_point*p The point.
doublex How much to translate on the x-axis.
doubley How much to translate on the y-axis.

Examples

bl_point *p = bl_make_point(200, 150);
bl_point_translate(p, 100, 50);

◆ bl_quadratic_point()

bl_point* bl_quadratic_point ( bl_point p0,
bl_point p1,
bl_point p2,
double  t 
)

Returns a point on a quadratic Bezier curve.

The t parameter is in the range of 0 to 1. 0 will return the first point. 1 will return the final point. A value between 0 and 1 will return a point along the quadratic Bezier path formed by the three points.

Parameters
bl_point*p0 The first point.
bl_point*p1 The second point.
bl_point*p2 The third point.
doublet The interpolation value.
Returns
bl_point*

Examples

bl_point *p0 = bl_make_point(100, 100);
bl_point *p1 = bl_make_point(200, 150);
bl_point *p2 = bl_make_point(300, 100);
bl_point *p4 = bl_quadratic_point(p0, p1, p2, p3, 0.2);

◆ bl_random_point()

bl_point* bl_random_point ( double  x,
double  y,
double  w,
double  h 
)

Returns a random point withint a defined rectangle.

Parameters
doublex The x position of the rectangle.
doubley The y position of the rectangle.
doublew The width of the rectangle.
doubleh The height of the rectangle.
Returns
bl_point*

Examples

bl_point *p = bl_random_point(0, 0, 500, 500);

◆ bl_random_point_in_circle()

bl_point* bl_random_point_in_circle ( double  x,
double  y,
double  r 
)

Returns a random point within a defined circle.

Parameters
doublex The x position of the circle.
doubley The y position of the circle.
doubler The radius of the circle.
Returns
bl_point*

Examples

bl_point *p = bl_random_point_in_circle(100, 100, 50);

◆ bl_random_point_in_triangle()

bl_point* bl_random_point_in_triangle ( bl_point p0,
bl_point p1,
bl_point p2 
)

Returns a random point that will be within a triangle defined by three points.

Parameters
bl_point*p0 The first point of the triangle.
bl_point*p1 The second point of the triangle.
bl_point*p2 The third point of the triangle.
Returns
bl_point*

Examples

bl_point *p0 = bl_make_point(100, 100);
bl_point *p1 = bl_make_point(200, 150);
bl_point *p2 = bl_make_point(140, 300);
bl_point *p3 = bl_random_point_in_triangle(p0, p1, p2);

◆ bl_segment_intersect()

bl_point* bl_segment_intersect ( bl_point p0,
bl_point p1,
bl_point p2,
bl_point p3 
)

Returns whether or not too line segments intersect.

Parameters
bl_point*p0 The first point of the first line.
bl_point*p1 The second point of the first line.
bl_point*p2 The first point of the second line.
bl_point*p4 The second point of the second line.
Returns
bool

Examples

bl_point *p0 = bl_make_point(100, 100);
bl_point *p1 = bl_make_point(200, 150);
bl_point *p2 = bl_make_point(300, 100);
bl_point *p3 = bl_make_point(400, 300);
bool intersect = bl_segment_intersect(p0, p1, p2, p3);

◆ bl_tangent_point_to_circle()

bl_point* bl_tangent_point_to_circle ( bl_point p,
double  x,
double  y,
double  r,
bool  anticlockwise 
)

Given the specified point and circle, finds another point on the circle that will form a line tangent to the circle.

Parameters
bl_point*p The initial point.
doublex The x position of the circle.
doubley The y position of the circle.
doubler The radius of the circle.
boolanticlockwise Which side of the circle to find the tangent point on.

Examples

bl_point *p0 = bl_make_point(100, 100);
bl_point *tangent = bl_tangent_point_to_circle(p, 200, 100, 50, false);