简体   繁体   English

C#使行高调整为椭圆

[英]C# make line height adjust to ellipse

There is an ellipse drawn with the following code: 用以下代码绘制一个椭圆:

graphGraphics = e.Graphics;

graphGraphics.FillEllipse(new SolidBrush(Color.White), this.graphBoundries);
graphGraphics.DrawEllipse(graphPen, this.graphBoundries);

I have a line on this graph and it currently just passes right through it. 我在这张图上有一条线,它现在正好通过它。 I want to change the lines height to adjust to the ellipse's boundaries as follows so it wont pass through the ellipse: 我要更改线条高度,以适应椭圆的边界,如下所示,这样它就不会穿过椭圆:

http://i1379.photobucket.com/albums/ah134/fac7orx2/circlewithlinehelp_zps280d9e76.png http://i1379.photobucket.com/albums/ah134/fac7orx2/circlewithlinehelp_zps280d9e76.png

Does anyone know an algorithm to do this? 有人知道执行此操作的算法吗? Or maybe even how to just get the ellipse's boundaries and not just the rectangular boundaries? 也许甚至如何仅获取椭圆的边界,而不仅仅是矩形边界?

To expand on my comment, try something like this (untested) code: 要扩展我的评论,请尝试以下代码(未经测试):

graphGraphics = e.Graphics;

graphGraphics.FillEllipse(new SolidBrush(Color.White), this.graphBoundries);
graphGraphics.DrawEllipse(graphPen, this.graphBoundries);

GraphicsPath clipPath = new GraphicsPath();
clipPath.AddEllipse(this.graphBoundaries);

graphGraphics.SetClip(clipPath, CombineMode.Replace);

// draw your line

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

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