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

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.