简体   繁体   English

如何从线角获得X,Y坐标点?

[英]How to get points X, Y coordinates from line angle?

So I have a 8x8 square. 所以我有一个8x8的方格。 There is a line in it. 它有一条线。

Line size == 8 angle == 0. 

One of line points is always on one of the top corners. 其中一个线点始终位于其中一个顶角。

What would be a formula to retrieve points coordinates where line crosses borders of square? 检索线与正方形边界相交的点坐标的公式是什么? (positive angle means one of line points is 0, 0. negative 0, 8 ) (正角度表示行点之一为0,0。负0,8)

What would be math formula for each of coordinates points? 每个坐标点的数学公式是什么? (in pseudo code if possible) (如果可能,使用伪代码)

line_end_x = line_start_x + cos(angle)*line_length

line_end_y = line_start_y + sin(angle)*line_length

if your line crosses a vertical edge: 如果你的线穿过垂直边缘:

intersection_x = edge_x
intersection_y = line_start_y + (intersection_x - line_start_x) * tan(angle)

if your line crosses a horizontal edge: 如果你的线穿过水平边缘:

intersection_y = edge_y
intersection_x = line_start_x + (intersection_y - line_start_y) * tan(angle-pi/4)

EDIT: corrected 编辑:纠正

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM