简体   繁体   English

在两个正方形之间绘制平行线

[英]Drawing parallel lines between two squares

I need to draw parallel lines between two squares. 我需要在两个正方形之间绘制平行线。 They can be placed at angle. 它们可以倾斜放置。 I need to find out 6 points (3 on square A and 3 on square B) so that lines drawn between them are equally spaced. 我需要找出6个点(正方形A上为3点,正方形B上为3点),以便在它们之间绘制的线等距分布。 Thanks 谢谢 在此处输入图片说明

Best you get acquainted with a bit of vector math. 最好您熟悉一些矢量数学。

Ideally the lines would orient themselves to the vector between the centers of the two squares (x0, y0) - (x1, y1). 理想情况下,直线应使自己朝向两个正方形(x0,y0)-(x1,y1)的中心之间的向量。

The direction of the three lines is: 三行的方向是:

x = (x1 - x0)
y = (y1 - y0)

A vector 90° to (x, y), and with size 1: 与(x,y)呈90°且方向为1的向量:

vn = (y, - x) / sqrt(x² + y²)

So a line 10 px from the center would be 所以距中心10 px的线是

(x0, y0) + 10.vn + µ.(x, y)

Use -10.vn, 0, +10.vn for the three lines. 三行使用-10.vn,0,+ 10.vn。

Determine intersection points with square's edges (µ > 0 for first square). 确定具有正方形边缘的交点(第一个正方形的µ> 0)。

As it is rewarding for ones self-consciousness, I leave the solution to you. 因为这对于一个人的自我意识是有益的,所以我将解决方案留给您。 It also is not as readable anymore. 它也不再可读。

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

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