Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 给定角度和长度,如何计算坐标_C++_C_Math_Trigonometry - Fatal编程技术网

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

C++ 给定角度和长度,如何计算坐标,c++,c,math,trigonometry,C++,C,Math,Trigonometry,假设左上角是(0,0),给定一个30度的角度,起点是(0300),直线长度是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,

假设左上角是(0,0),给定一个30度的角度,起点是(0300),直线长度是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;
}

math.h
具有您需要的所有三角函数。您可能需要给链接器提供
-lm
,这取决于您构建的系统(有时是自动的)。

您不需要说明相对于哪个角度测量,也不需要说明轴的方向。这些将带来不同

首先需要将角度转换为弧度(乘以PI,除以180)。 然后你需要取角度的正弦和余弦,然后乘以直线的长度。现在,坐标有两个数字,但这取决于轴的方向和测量角度,这些值中的哪一个是x坐标,哪一个是y坐标,以及它们是否需要求反。

//这是一个完整的程序,其中包含C和命令行参数的解决方案
// Here is a complete program with the solution in C and command-line parameters
// Compile with the math library: 
//    gcc -Wall -o point_on_circle -lm point_on_circle.c
//
// point_on_circle.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

double inline degree2radian(int a) { return (a * 0.017453292519); }

void getEndPoint(double angle, int len, int start_x, 
    int start_y, int *end_x, int *end_y) {
        *end_x = start_x + len * cos(angle);
        *end_y = start_y + len * sin(angle);
} // getEndPoint

int main(int argc, char *argv[]) {
  double angle = atoi(argv[1]);
  int length   = atoi(argv[2]);
  int start_x  = atoi(argv[3]);
  int start_y  = atoi(argv[4]);
  int x, y;

  getEndPoint(degree2radian(angle), length, start_x, start_y, &x, &y);
  printf("end x=%d, end y=%d\n", x, y);

  return 0;
} // main
//使用数学库编译: //gcc-墙-o点在圆上-lm点在圆上。c // //圆上的点 #包括 #包括 #包括 双列直插degree2radian(inta){return(a*0.017453292519);} void getEndPoint(双角度、整数长度、整数起点x、, 整数开始,整数*结束,整数*结束){ *end_x=start_x+长度*cos(角度); *结束y=开始y+len*sin(角度); }//getEndPoint int main(int argc,char*argv[]){ 双角度=atoi(argv[1]); int length=atoi(argv[2]); int start_x=atoi(argv[3]); int start_y=atoi(argv[4]); int x,y; getEndPoint(度2弧度(角度)、长度、起点x、起点y、起点x和起点y); printf(“x末端=%d,y末端=%d\n”,x,y); 返回0; }//主要
< > >人们忘记了C++中的<代码>复数< /COD>库,它对我们来说是极坐标转换为矩形。

complex<double> getEndPoint(complex<double> const &startPoint, double magnitude, double radians)
{
    return startPoint + polar<double>(magnitude, radians);
}

int main()
{
    complex<double> startingPoint(0.0, 300.0);
    auto newPoint = getEndPoint(startingPoint, 600, 0.523598776);

    cout << newPoint << endl;
}
complex getEndPoint(复数常量和起始点,双幅值,双弧度)
{
返回起始点+极坐标(幅值、弧度);
}
int main()
{
复合起始点(0.0300.0);
自动新点=getEndPoint(起始点,600,0.523598776);

cout
cos()
sin()
取弧度,小心点。这样做很好…有时我把事情做得太难了。非常感谢!-1对于宏…请使用内联函数!无论如何,在某一点上会有一个转换,以使乘法发生…见鬼,即使你有C99编译器,生成内联函数也只是一个建议。宏是安全的这个问题是关于trig而不是宏和内联函数的。我只是简单地指出,弧度转换是微不足道的。我想你想要的是(int*)类型对于end_x和end_y,以及在函数末尾翻转你的作业。是数学还是你遇到问题的代码?如果是数学,那么这可能不是论坛,这是非常基本的;我建议你参考。但是记住,当你实现它时,C数学库使用弧度而不是度
r=d*PI/180.0
老兄,我因为回答了一半的编程问题而被否决了。哦,多么变化无常……谢谢,我想要计算出的值。编辑以反映这一点。斯波尔斯基和阿特伍德建立mathoverflow.com多久了?
complex<double> getEndPoint(complex<double> const &startPoint, double magnitude, double radians)
{
    return startPoint + polar<double>(magnitude, radians);
}

int main()
{
    complex<double> startingPoint(0.0, 300.0);
    auto newPoint = getEndPoint(startingPoint, 600, 0.523598776);

    cout << newPoint << endl;
}