المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Hot to draw ellipse line intersection



C# Programming
12-30-2010, 01:51 PM
Hi, guys http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif .
I write a simple application for drawing a vector primitives such a ellipse, line, rectangle, polygon, etc. I want to add a class for a new shape - ellipse with two lines in it, but I'm stuck on this http://www.barakasoft.com/script/Forums/Images/smiley_frown.gif . Can you give me some help?

This is the code of my Ellipse class:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;


namespace _2D_Vector_Graphics
{
[Serializable]
class EllipseShape : Shape
{
public RectangleF Set********
{
set {
this.******** = value.********;
this.ModelSize = value.Size;
}
}

public EllipseShape()
{
this.ModelSize = new SizeF(0, 0);
this.******** = new PointF(-10, -10);
this.selectionUnit = new CoveringRectangle(Rectangle.Round(ReturnBounds()));
}

public EllipseShape(Color newFillColor, Color newBorderColor, int newBorderWidth, SizeF newModelSize, PointF new********)
{
this.FillColor = newFillColor;
this.BorderColor = newBorderColor;
this.BorderWidth = newBorderWidth;
this.ModelSize = newModelSize;
this.selectionUnit = new CoveringRectangle(Rectangle.Round(ReturnBounds()));
}
public override void DrawYourSelf(Graphics graphics)
{

GraphicsPath path=new GraphicsPath();
path.AddEllipse(new RectangleF(********, ModelSize));
path.Transform(this.TMatrix.TransformationMatrix);

Pen pen = new Pen(this.BorderColor, this.BorderWidth);

if (IS_FILLED)
{
SolidBrush brush = new SolidBrush(this.FillColor);
graphics.FillPath(brush, path);
}
graphics.DrawPath(pen,path);
if (this.Selected)
{
this.selectionUnit = new CoveringRectangle(Rectangle.Round(ReturnBounds()));
this.selectionUnit.DrawYourSelf(graphics);
}
}

public override RectangleF ReturnBounds()
{
GraphicsPath path = new GraphicsPath();
path.AddEllipse(new RectangleF(********, ModelSize));
path.Transform(this.TMatrix.TransformationMatrix);
return path.GetBounds();
}
}
}

And this is the code of my Line class:

using System;
using System.Collections.Generic;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace _2D_Vector_Graphics
{
[Serializable]
class LineShape : Shape
{
protected Point begin,end;
public Point SetBegin
{
set {
begin= value ;
}
}
public Point SetEnd
{
set {
end = value;
}
}
public LineShape()
{
this.selectionUnit = new CoveringRectangle(Rectangle.Round(ReturnBounds()));
}
public LineShape(Point begin, Point end)
{

this.begin = begin;
this.end = end;
this.selectionUnit = new CoveringRectangle(Rectangle.Round(ReturnBounds()));
}
public LineShape(Point begin, Point end, Color newBorderColor, int newBorderWidth)
{
this.begin = begin;
this.end = end;
this.BorderColor = newBorderColor;
this.BorderWidth = newBorderWidth;
this.selectionUnit = new CoveringRectangle(Rectangle.Round(ReturnBounds()));
}

public override void DrawYourSelf(Graphics graphics)
{
GraphicsPath path = new GraphicsPath();
path.AddLine(begin,end);
path.Transform(this.TMatrix.TransformationMatrix);
Pen pen = new Pen(this.BorderColor, this.BorderWidth);
graphics.DrawPath(pen, path);
if (this.Selected)
{
this.selectionUnit = new CoveringRectangle(Rectangle.Round(ReturnBounds()));
this.selectionUnit.DrawYourSelf(graphics);
}
}

public override RectangleF ReturnBounds()
{
GraphicsPath path = new GraphicsPath();
path.AddLine(begin, end);
path.Transform(this.TMatrix.TransformationMatrix);
return path.GetBounds();
}
}
}