我如何计算圆周上的一个点?

以下function如何以各种语言实现?

计算圆周上的(x,y)点,给定的input值为:

  • 半径
  • angular度
  • 起源(可选参数,如果语言支持)

一个圆的参数方程是

 x = cx + r * cos(a) y = cy + r * sin(a) 

r是半径, cx,cy是原点,angular度是r

使用基本的trig函数可以很容易地适应任何语言。 请注意,大多数语言将在三angular函数中使用弧度作为angular度,所以不是循环通过0..360度,而是通过0..2PI弧度循环。

这是我在C#中的实现:

  public static PointF PointOnCircle(float radius, float angleInDegrees, PointF origin) { // Convert from degrees to radians via multiplication by PI/180 float x = (float)(radius * Math.Cos(angleInDegrees * Math.PI / 180F)) + origin.X; float y = (float)(radius * Math.Sin(angleInDegrees * Math.PI / 180F)) + origin.Y; return new PointF(x, y); } 

当您遇到复杂的数字时,谁需要触发

 #include <complex.h> #include <math.h> #define PI 3.14159265358979323846 typedef complex double Point; Point point_on_circle ( double radius, double angle_in_degrees, Point centre ) { return centre + radius * cexp ( PI * I * ( angle_in_degrees / 180.0 ) ); }