How to find the intersection points when the straight line intersect the circle

Viewed 354

I want to place a rectangle at bottom of the circle as like below,

enter image description here

But i cannot get the intersection points, to place the rectangle.

enter image description here

Example:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent(); circleHeight = (circleWidth / 3) * 2;
        this.panel1.Paint += Panel1_Paint;
    }
    int circleWidth = 314;
    int circleHeight;
    int FrameThickness = 12;
    private void Panel1_Paint(object sender, PaintEventArgs e)
    {
        e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
        e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
        GraphicsPath pth = new GraphicsPath();
        System.Drawing.Drawing2D.GraphicsPath basePath = new System.Drawing.Drawing2D.GraphicsPath();

        int x = this.circleWidth;

        int rectWidth = (int)Math.Ceiling(this.circleWidth * 0.94); // 94 % of the actual circle width            
        int rectRimWidth = rectWidth - (this.FrameThickness * 2);


        int xOffset = (this.circleWidth - rectWidth) / 2;
        int yOffset = (this.circleWidth - rectRimWidth) / 2;
        Rectangle rect; Rectangle rectrim;

        rect = new Rectangle(0 + xOffset, 0 + xOffset, rectWidth, rectWidth);
        rectrim = new Rectangle(0 + yOffset, 0 + yOffset, rectRimWidth, rectRimWidth);

        e.Graphics.FillEllipse(Brushes.Red, rect);
        e.Graphics.FillEllipse(Brushes.Yellow, rectrim);
        Point Center = new Point(circleWidth / 2, circleWidth / 2);

        e.Graphics.FillRectangle(Brushes.Red, new Rectangle(rect.X, circleHeight - FrameThickness, rectWidth, FrameThickness));
    }


    private int GetInnerWidth()
    {
        return (int)(Math.Ceiling(circleWidth * 0.94) - (FrameThickness * 2));
    }

    private int GetWidth()
    {
        return GetInnerWidth() - (int)(GetInnerWidth() * 0.14); // 14% of adjacent circle
    }

    internal int InnerRimRadius
    {
        get
        {
            return GetInnerWidth() / 2 + GetFrameThickness() / 2;
        }
    }
}

i have referred most of the stack overflow post, unfortunately that's all not help me to get what i exactly looking for. Please help me to find out the code. Thanks in advance.

0 Answers
Related