简体   繁体   English

两种形状的交点之间的画线

[英]Drawing line between intersection of two shapes

I am playing around with graphics, specifically the intersection and union of primitive shapes. 我在玩图形,特别是原始形状的交集和并集。

Given the following: 给定以下内容:

Elipse2D e1 = new Elipse2D.Double(120, 80, 80, 80);
Elipse2D e2 = new Elipse2D.Double(180, 80, 80, 80);

Area a1 = new Area(e1);
a1.add(new Area(e2));

gfx.draw(a1); // gfx is a Graphics2D object 

This gives a very nice shape that looks like a 1st-person eye-view from binoculars in some 90's action movie. 这提供了非常好的形状,看起来像90年代动作电影中双筒望远镜的第一人称视角。

However, I was wondering if it was possible to draw a line between the two intersection points so that is looks almost like two cells busy dividing. 但是,我想知道是否有可能在两个相交点之间画一条线,这样看起来几乎就像两个单元正在忙于划分。 After doing this with two circles, is this possible with multiple circles, perhaps? 用两个圆圈完成此操作之后,也许可以使用多个圆圈吗?

I know this can be done by finding the intersection points between the two circles and drawing the lines manually, however, I do not want to reinvent the wheel. 我知道这可以通过找到两个圆之间的交点并手动绘制线来完成,但是,我不想重新发明轮子。

Any suggestions? 有什么建议么?

Given the parameterization of these Ellipse2D , the equations can be written as: 给定这些Ellipse2D的参数后,这些等式可以写成:

x(r) = X + W (cos(r) + 1)/2
y(r) = Y + H (sin(r) + 1)/2

x(s) = X + W' (cos(s) + 1)/2
y(s) = Y + H  (sin(s) + 1)/2

The y equations allow to conclude that the angles r and s have the same sine and are supplementary (equal angles would not satisfy the x equations), so that cos(s)=-cos(r) . y方程可以得出结论,角度rs具有相同的正弦值,并且是互补的(相等的角度将不满足x方程),因此cos(s)=-cos(r)

After elimination, we have (W'+W) cos(r) = W'-W . 消除后,我们有(W'+W) cos(r) = W'-W In the given case, cos(r)=1/5 and r=78.463° . 在给定的情况下, cos(r)=1/5r=78.463°

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

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