Discussion:
Draw Ellipse diagonally in bounding rectangle
(too old to reply)
Mike D Sutton @ Work
2004-09-10 14:48:30 UTC
Permalink
I would like to draw an ellipse diagonally in a bounding rectangle in GDI+. I
see plenty of examples of rotating an ellipse after it is created but this is
not what I want.
You'd need to set up a world transformation using SetTransform() that rotates to the orientation of your bounding area then draw the
ellipse after that.
Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: ***@mvps.org
WWW: Http://www.mvps.org/EDais/
vipin
2004-09-14 05:10:11 UTC
Permalink
Actually an ellipse is represented by a bounding rectangle.
So without knowing the bounding rectangle how do you intend to draw it at
first place?

Thanks
Vipin
Mike,
This still is not getting me what I need. I have a rectangle. I want to
draw
an ellipse vertically in in the is rectangle. The actual bounding of the
diagonal ellipse is unknown. This bounding area will be smaller then the
housing rectangle. Hope you understand what I am getting at....
Thanks in advance - Dan
Post by Mike D Sutton @ Work
I would like to draw an ellipse diagonally in a bounding rectangle in GDI+. I
see plenty of examples of rotating an ellipse after it is created but this is
not what I want.
You'd need to set up a world transformation using SetTransform() that
rotates to the orientation of your bounding area then draw the
Post by Mike D Sutton @ Work
ellipse after that.
Hope this helps,
Mike
- Microsoft Visual Basic MVP -
WWW: Http://www.mvps.org/EDais/
Mike D Sutton
2004-09-14 06:48:08 UTC
Permalink
This still is not getting me what I need. I have a rectangle. I want to draw
an ellipse vertically in in the is rectangle. The actual bounding of the
diagonal ellipse is unknown. This bounding area will be smaller then the
housing rectangle. Hope you understand what I am getting at....
See if this is what you're after:

***
void DrawRotatedEllipse(Graphics inGfx, Pen inPen,
float inAngle, int inX, int inY, int inWidth, int inHeight) {
Matrix OrigTransform, RotMatrix;

// Create new rotation transformation
RotMatrix = new Matrix();
RotMatrix.RotateAt(inAngle, new PointF(inX, inY));

// Buffer old transformation and apply new one
OrigTransform = inGfx.Transform;
inGfx.Transform = RotMatrix;

// Draw ellipse
inGfx.DrawEllipse(inPen,
inX - (inWidth / 2),
inY - (inHeight / 2),
inWidth, inHeight);

// Restore original matrix and clean up
inGfx.Transform = OrigTransform;
RotMatrix.Dispose();
}
***

Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: ***@mvps.org
WWW: Http://www.mvps.org/EDais/
Dan
2004-09-14 13:14:00 UTC
Permalink
Mike,

I'll give this a try. Here is a site that visually shows the ellipse I am
trying to draw..
http://www15.addr.com/~dscher/triangle.html

Thanks - Dan
Post by Mike D Sutton
This still is not getting me what I need. I have a rectangle. I want to draw
an ellipse vertically in in the is rectangle. The actual bounding of the
diagonal ellipse is unknown. This bounding area will be smaller then the
housing rectangle. Hope you understand what I am getting at....
***
void DrawRotatedEllipse(Graphics inGfx, Pen inPen,
float inAngle, int inX, int inY, int inWidth, int inHeight) {
Matrix OrigTransform, RotMatrix;
// Create new rotation transformation
RotMatrix = new Matrix();
RotMatrix.RotateAt(inAngle, new PointF(inX, inY));
// Buffer old transformation and apply new one
OrigTransform = inGfx.Transform;
inGfx.Transform = RotMatrix;
// Draw ellipse
inGfx.DrawEllipse(inPen,
inX - (inWidth / 2),
inY - (inHeight / 2),
inWidth, inHeight);
// Restore original matrix and clean up
inGfx.Transform = OrigTransform;
RotMatrix.Dispose();
}
***
Hope this helps,
Mike
- Microsoft Visual Basic MVP -
WWW: Http://www.mvps.org/EDais/
Loading...