如何计算座标 [英] How to Calculate Coordinates

查看:106
本文介绍了如何计算座标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!

Hello!



#include <graphics.h>
#include <conio.h>

main()
{
   int gd=DETECT,gm,points[]={320,150,420,300,250,300,320,150};

   initgraph(&gd, &gm, "C:\\TC\\BGI");

   drawpoly(4, points);

   getch();
   closegraph();
   return 0;
}



他是如何计算这些点的?

谢谢.



How did he calculate those points ?

Thanks.

推荐答案

好吧,只是看一下数字,它看起来像是一个正方形,旋转了一下,使其角朝上/朝下,向左和向右;对.

您可以使用三角函数(和+-进行平移)将对象旋转任意角度,尽管您已经展示了这种情况,但可以使用简单的几何图形来完成.

即使用毕达哥拉斯,我们知道从一个角到对角对角的距离是sqrt(1 ^ 2 + 1 ^ 2)= sqrt(2)乘以边长.
因此,如果您决定任何一个点,就可以计算其他点的位置.
+)固定第一个点(存储到数组pos 0,1)
+)对角是sqrt(2)*垂直或水平距离的边长

+)通过取此sqrt(2)* sidelength
的1/2可以找到剩余点 然后,您可以使用此值来补偿上/下和&左右确定其他2个点.

Well, just looking at the numbers, it looks to be a square, rotated so that it''s corners are pointing up/down, left & right.

You can use trig functions (and + - for translation) to rotate an objet about an arbitrary angle, though for this case you''ve presented, it could be done with simple geometry.

I.e using pythagoras, we know that the distance from one corner to the diagonally oposite one is sqrt(1^2 + 1^2) = sqrt(2) times the side length.

So, if you decide on any one of the points, you can calculate the position of the others.
+) Fix the first point (store to array pos 0,1)
+) The opposite corner is sqrt(2)*sidelength away either vertically or horizontally

+) The remaining points are found by taking 1/2 of this sqrt(2)*sidelength
You can then use this value to offset both up/down & right/left to determine the other 2 points.

..........................................  
..........................................  
..........................................  
..........................................  
...................X......................  
..........................................  
..........................................  
..........................................  
..........................................  
..........................................  
.....Z...........................Y........  
..........................................  
..........................................  
..........................................  
..........................................  
..........................................  
..........................................  
..........................................  
...................W......................  
1. Fix point W
                         [X.x = W.x], [X.y = W.y + sqrt(2)*sideLength]
[Y.x = W.x + sqrt(2)*sideLength*0.5], [Y.y = (W.y + X.y) * 0.5]
    [Z.x = Y.x - sqrt(2)*sideLength], [Z.y = Y.y]


这篇关于如何计算座标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆