Circumference Points

In Category Geometry
Article published 29/09/2009 10:44:56pm
Circumference PointsCircumference Points

Finding and plotting points on the circumference of a circle: This article explains how to write a simple function that provides cartesian co-ordinates for a point based on a circles centre co-ordinates, its radius, and the degree of rotation.

Finding a point on the circumference of a circle can be a pleasantly easy affair. To find any point, we will need the following information:
  • The co-ordinates of the centre of the circle (nXpos,nYpos)
  • The radius of the circle (nRadius), and
  • The offset of the point, in degrees of rotation (dDegrees)
First of all, we should check that the degrees of rotation is in the range zero to 360, and reduce it by 90° to allow for the fact that by default, zero degrees will fall on the horizontal axis.
dDegrees = ( dDegrees - 90 ) % 360;
We can now easily find the x,y co-ordinates of the point we want using sine and cosine:
x = nRadius x cos( dDegrees x π / 180 );
y = nRadius x sin( dDegrees x π / 180 );
Easy! A quick example of this function written in Javascript would work as follows:
function GetPoint(nRadius,dDegrees,nXpos,nYpos) {
  dDegrees = (dDegrees-90)%360; // Account for 90.deg. offset
  x = nRadius*Math.cos(dDegrees*Math.PI/180);
  y = nRadius*Math.sin(dDegrees*Math.PI/180);

  x = Math.round(x);
  y = Math.round(y);

  return Array((x+nXpos),(y+nYpos));