Base functions

Here are describe the geometric, base functions functions, from SDL2_gfxutils used from the differents forms generating functions.

Angles

float get_angle(int position, float scale, float orientation)
Parameters:
  • position (int) – Needed for positional purpose: number of scaling units.
  • scale (float) – Scaling of the angle.
  • orientation (float) – An additionnal offset to add.
Return type:

float

Returns:

An angle in degrees.

This function return an angle value according to the given settings,

by applying following formel:

360.0/scale * position + orientation

Distance

float get_distance_pixels(Pixel px1, Pixel px2)
Parameters:
  • px1 (float) – The start pixel from the distance.
  • px2 (Pixel) – The end pixel from the distance.
Return type:

float

Returns:

The distance between px1 and px2.

Pixel

Pixel get_pixel_coords(uint32_t position, uint32_t scale, float length, Pixel center, float orientation)
Parameters:
  • position (uint32_t) – An unsigned integer needed for positional purpose.
  • scale (uint32_t) – Scaling of the angle.
  • length (float) – radius.
  • center (Pixel) – center.
  • orientation (float) – An additionnal offset to add.
Return type:

Pixel

Returns:

The pixel initialized in relationship to the given settings.

This function return an pixel initialized in relationship to the given settings,

by first getting the angle:

float angle_degrees = get_angle(position, scale, orientation)   ;
float radians = angle_degrees / 180.0 * PI  ;

and applying the following formel to get the x and y values:

Pixel.x = cosf(radians) * length + center.x ;
Pixel.y = sinf(radians) * length + center.y ;
Pixel get_middle_from_line(Line line)
Parameters:
  • line (Line) – The line to get the middle point from.
Return type:

Pixel

Returns:

The pixel middle point from the given line.

Line

Line *generate_segment(Pixel start_point, float length, float angle)
Parameters:
  • start_point (Pixel) – The segment start point.
  • length (float) – The length of the segment.
  • angle (float) – segment incline angle.
Return type:

Line *

Returns:

An line starting at start_point from length length incline from angle.

Arc

Arc *generate_circle_arc(float radius, Pixel center, float start_pos, float circle_part)
Parameters:
  • radius (float) – the radius starting from the center argument.
  • center (Pixel) – The center from where generate the circle arc.
  • start_pos (float) – The start position given as an angle in degress.
  • circle_part (float) – An angle value, in degrees, representing the part of an entire circle of the arc and so the length of the arc in relationship to the radius.
Return type:

Arc *.

Returns:

A pointer on an Arc.

  • from radius radius.
  • from center center.
  • length from part of an circle circle_part.
  • starting at offset start_pos which will give the start point from the arc.

Table Of Contents

Previous topic

SDL2_gfxutils defined types

Next topic

Forms generating functions

This Page