Jak obliczyć punkt na obwodzie koła? [duplikat]

To pytanie ma już odpowiedź tutaj:

Jak można zaimplementować następującą funkcję w różnych językach?

Oblicz (x,y) punkt na obwodzie okręgu, podane wartości wejściowe:

  • promień
  • kąt
  • Pochodzenie (opcjonalny parametr, jeśli jest obsługiwany przez język)
Author: Justin Ethier, 2009-05-08

3 answers

Równanie parametryczne dla okręgu wynosi

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

Gdzie r jest promieniem, cx,cy początkiem ia kątem.

Jest to dość łatwe do dostosowania do dowolnego języka z podstawowymi funkcjami Tryg. zauważ, że większość języków używa radianów dla kąta w funkcji Tryg, więc zamiast przechodzić przez 0..360 stopni, przejeżdżasz przez 0..Radiany 2PI.

 502
Author: Paul Dixon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-08-22 10:54:04

Oto moja implementacja w 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);
    }
 44
Author: Justin Ethier,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-05-08 13:57:53

Who needs trig when you have complex numbers :

#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 ) );
}
 15
Author: Pete Kirkham,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-05-08 14:15:40