假设左上角是(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;
}
Run Code Online (Sandbox Code Playgroud) 寻找最快的方法来计算位于距离线的终点给定距离的线上的点:
void calculate_line_point(int x1, int y1, int x2, int y2, int distance, int *px, int *py)
{
//calculate a point on the line x1-y1 to x2-y2 that is distance from x2-y2
*px = ???
*py = ???
}
Run Code Online (Sandbox Code Playgroud)
感谢您的回复,不是这不是家庭作业,只是一些黑客攻击我的正常专业领域.
这是下面建议的功能.它并不接近工作.如果我将圆的右上角90度部分每5度计算一次点作为起始点并调用下面的函数,圆的中心为x2,距离为4的y2则完全错误.它们位于中心的下方和右侧,长度与中心点一样长.有人有什么建议吗?
void calculate_line_point(int x1, int y1, int x2, int y2, int distance)
{
//calculate a point on the line x1-y1 to x2-y2 that is distance from x2-y2
double vx = x2 - x1; // x vector
double vy = y2 - …Run Code Online (Sandbox Code Playgroud) 我需要一个可以用来更好地理解大型C项目的工具.我希望能够看到各种C模块之间的关系,以及调用什么,最常用的函数,使用的标题等等.
我在这里和谷歌搜索过,但是所有的源代码分析工具似乎都能给你一些我不感兴趣的代码行和其他指标.我只是希望得到一个关于事物结构的高级视图.在跳入代码之前互连.
有这样的事吗?
我看过这些,但它们似乎没有做我想要的:源代码工具
自从张贴这个以来我尝试了Doxygen,它似乎给了我一些我需要的东西.还有其他人?
我正在寻找最好的C或C++代码来编码和解码从/到double/char的十进制纬度和经度值.我更喜欢将代码从double转换为char [],反之亦然而不是c ++字符串.
如果你有一个很棒的代码片段.
澄清一下:我需要将字符串Degrees/Minutes/Seconds转换为double并返回字符串.我有3亿条记录,所以速度是一个很大的问题.
请参阅:http://en.wikipedia.org/wiki/Geographic_coordinate_conversion