Confused on how to do this.

I am trying to make a math library and confused on how to do this.

A function that calculates the distance between two(2D) points
A function that calculates the angle between two(2D) vectors
A function that tells if a point(2D) is within a circle
A function that tells if a point(2D) is visible, given a view location and direction

These functions I got.
*A function that tells if a ray(2D) intesects with a circle
*A function that calculates the nearest distance between a ray(2D) and a point(2D)
*A function that will normalize a given vector.

Here is my code and my compiler is Microsoft Visual C++ 2008 Express Edition.

#include <stdio.h>
#include <math.h> // include math functions like sqrt()

////////////////////////////////////////////

// define our functions at the top!
bool RayIntersectsCircle( float rayX, float rayY, float rayDirX, float rayDirY, float circleX, float circleY, float radius );
float GetDistFromRay( float rayX, float rayY, float rayDirX, float rayDirY, float ptX, float ptY );
void Normalize( float x, float y, float *outX, float *outY );

////////////////////////////////////////////

int main(void)
{
// test our Normalize function
float nX = 0;
float nY = 0;
Normalize( 1, 1, &nX, &nY );
printf("Normalizing the vector ( 1, 1 )\nresult - ( %.2f, %.2f )\n\n", nX, nY);

// test the GetDistFromRay function
float dist = GetDistFromRay( 0, 0, 1, 0, 5, 3 );
printf("Finding the smallest distance between a line rayPoint(0, 0), rayDirection(1, 0) and a point (5, 3)\nresult - %.2f\n\n", dist);

// test the RayIntersectsCircle function
printf("Does the ray from above intersect a circle with a radius of 4 at the same spot as the point?\n");
if (RayIntersectsCircle( 0, 0, 1, 0, 5, 3, 4 ))
printf("result - true\n\n");
else
printf("result - false\n\n");

// return success to the system
return(1);
}

////////////////////////////////////////////

bool RayIntersectsCircle( float rayX, float rayY, float rayDirX, float rayDirY, float circleX, float circleY, float radius )
{
// find the distance of the circle from the ray
float dist = GetDistFromRay( rayX, rayY, rayDirX, rayDirY, circleX, circleY );

// and compare that distance to the radius
if (dist <= radius)
return( true );
else
return( false );
}

////////////////////////////////////////////

float GetDistFromRay( float rayX, float rayY, float rayDirX, float rayDirY, float ptX, float ptY )
{
// get the vector from the raypoint to the position of the point
float tX = ptX - rayX;
float tY = ptY - rayY;
// get the dot product of the ray direction and our temporary vector
float dot = tX*rayDirX + tY*rayDirY;
// get the point on the line
float lineX = rayX + (rayDirX * dot);
float lineY = rayY + (rayDirY * dot);

// set up variables for the distance test
float dx = lineX-ptX;
float dy = lineY-ptY;

// return the distance
return( sqrt( dx*dx + dy*dy ) );
}

////////////////////////////////////////////

void Normalize( float x, float y, float *outX, float *outY )
{
// first find the length of the vector, which is essentially the distance between( x, y ) and ( 0, 0 )
float length = sqrt( x*x + y*y );

// divide x and y by the length, so that the vector will have a length of 1, and then store the result in the out variables
*outX = x / length;
*outY = y / length;
}


.. I have no idea how or where to start. Can someone help me please?

First you need to figure out what you do know about solving the problem.
Could you perform any of the calculations using pen & paper - if so, then you know the formula to make the calculation, and the varaibles and out put of the calculation.
The variables and output define the function header, the formula defines the function body, and all you then need to do is code them.
To take a trivial example, if the problem was 'Add two numbers', you know you need 2 numbers as parameters and a third as the result, so the function would look like
float add(float x, float y);
See what you can come up with and we'll be happy to give advice along the way:-)
Topic archived. No new replies allowed.