c++ - 给定角度和长度,如何计算坐标

标签 c++ c math trigonometry

假设左上角为(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);

关于c++ - 给定角度和长度,如何计算坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1638437/

相关文章:

c++ - 编译器是否假定 "this"在 Debug模式下不是 nullptr?

理解计算 char 变量的 C++ 问题

C++:getline() 是否读取了整行?

c# - Visual Studio 停止运行我的程序

c - C 中函数指针的原子读/写?

c - 在C中绘制多边形

matlab - 矩阵和数组有什么区别?

c - 使用单声道运行 .NET 二进制文件时出现 SIGSEGV 和单声道崩溃问题

c# - 如何在Unity3d中测量两条线段之间的距离

c# - 从范围内的起始索引向上和向下计数的循环