fac7orx
fac7orx

Reputation: 335

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

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?

Upvotes: 1

Views: 135

Answers (1)

adv12
adv12

Reputation: 8551

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

Upvotes: 2

Related Questions