M_PI is a macro definition, the definition of pi
-
C + + code
- #define m_pi 3.14159265358979323846
-
This macro definition is related to the compiler, the M_PI macro in TC is defined in <math.h>.
But VC's <math.h> does not have the M_PI macro definition. As a result, there is an error at compile time, prompting: "M_pi": an undeclared identifier.
-
Workaround: Define by yourself.
Angle to radians:
#define Angletoradian (angle) (m_pi/180.0f) *angle
Calculates the coordinates of the points on the circumference of the specified angle at the positive east of the 0-degree start:
float Radian = Angletoradian (angle);
float x = center.x + cos (radian) *r;
Float y = center.y + sin (radian) *r;
Cgpoint point = Cgpointmake (x, y);
Calculates the coordinates of the points on the circumference of the specified angle at the beginning of the 0-degree point on the north side:
float Radian = Angletoradian (angle);
float x = center.x + sinf (radian) *r;
Float y = CENTER.Y-COSF (radian) *r;
Cgpoint point = Cgpointmake (x, y);
The problem of using M_PI in VS and resolving angle to Radian & method of calculating the coordinates of points on the circumference by radians