#include <math.h>
#include <iostream>

const double arrow_head_length = 3;
const double PI = 3.14159265;
const double arrow_head_angle = PI/6;

//returns the angle between two points, with coordinate1 describing the centre of the circle, starting at (theta = 0 == y=0,x>0) and progressing clockwise
double angle_between_points( std::pair<double,double> coordinate1,  std::pair<double,double> coordinate2)
{
  return atan2(coordinate2.second - coordinate1.second, coordinate1.first - coordinate2.first);
}

//calculate the position of a new point [displacement] away from an original point at an angle of [angle]
std::pair<double,double> displacement_angle_offset(std::pair<double,double> coordinate_base, double displacement, double angle)
{
	return std::make_pair
	(
		coordinate_base.first  - displacement * cos(angle),
		coordinate_base.second + displacement * sin(angle)
	);
}
	
int main()
{
  std::pair<double,double> arrow_tail( 0, 0);
  std::pair<double,double> arrow_head( 15,-15);
  
  //find the angle of the arrow
  double angle = angle_between_points(arrow_head, arrow_tail);
  
  //calculate the new positions
  std::pair<double,double> head_point_1 = displacement_angle_offset(arrow_head, arrow_head_length, angle + arrow_head_angle);
  std::pair<double,double> head_point_2 = displacement_angle_offset(arrow_head, arrow_head_length, angle - arrow_head_angle);
  
  //output the points in order: tail->head->point1->point2->head so if you follow them it draws the arrow
  std::cout << arrow_tail.first   << ',' << arrow_tail.second   << '\n'
            << arrow_head.first   << ',' << arrow_head.second   << '\n'
			<< head_point_1.first << ',' << head_point_1.second << '\n'
			<< head_point_2.first << ',' << head_point_2.second << '\n'
			<< arrow_head.first   << ',' << arrow_head.second   << std::endl;
}