c – 给定一个角度和长度,我如何计算坐标 - 代码日志

c – 给定一个角度和长度,我如何计算坐标

假设左上角是(0,0),我被赋予一个30度的角度,起点为(0,300),线长为600,那么我如何计算线的终点呢
该线代表给定的角度。

C伪代码是

main() {
  int x,y;

  getEndPoint(30, 600, 0, 300, &x, &y);
  printf("end x=%d, end y=%d", x, y);
}

// input angle can be from 0 - 90 degrees

void getEndPoint(int angle, int len, int start_x, int start_y, int *end_x, int *end_y) 
{

    calculate the endpoint here for angle and length

    *end_x = calculated_end_x;
    *end_y = calculated_end_y;
}
// edit to add conversion
    #define radian2degree(a) (a * 57.295779513082)
    #define degree2radian(a) (a * 0.017453292519)

        x = start_x + len * cos(angle);
        y = start_y + len * sin(angle);
http://stackoverflow.com/questions/1638437/given-an-angle-and-length-how-do-i-calculate-the-coordinates

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:c – 给定一个角度和长度,我如何计算坐标