## c# drawing library calculate ranges and midpoints to draw and circle

Basically i have a menu that user choose the shape wanted to be drawn, then the user click on two points, between those two points the chosen shape will be drawn. I did the Square which is calculated this way

```// calculate ranges and mid points
xDiff = oppPt.X - keyPt.X;
yDiff = oppPt.Y - keyPt.Y;
xMid = (oppPt.X + keyPt.X) / 2;
yMid = (oppPt.Y + keyPt.Y) / 2;

// draw square
g.DrawLine(blackPen, (int)keyPt.X, (int)keyPt.Y,
(int)(xMid + yDiff / 2), (int)(yMid - xDiff / 2));
g.DrawLine(blackPen, (int)(xMid + yDiff / 2), (int)(yMid - xDiff / 2),
(int)oppPt.X, (int)oppPt.Y);
g.DrawLine(blackPen, (int)oppPt.X, (int)oppPt.Y,
(int)(xMid - yDiff / 2), (int)(yMid + xDiff / 2));
g.DrawLine(blackPen, (int)(xMid - yDiff / 2),
(int)(yMid + xDiff / 2), (int)keyPt.X, (int)keyPt.Y);
```

but i can't figure out how to draw the circle and the triangle the same way

On Same Way.

```int left = 20, top = 20
int right = 100, bot = 100;

// triangle
g.DrawLine(Pens.Red, left, bot, right, bot);
g.DrawLine(Pens.Red, right, bot, left + (right-left) / 2 /* was miss calc */, top);
g.DrawLine(Pens.Red, left + (right - left) / 2, top, left, bot);  // better looks
//g.DrawLine(Pens.Red, left, bot, left + (right-left) / 2 /* was miss calc */, top);

// circle
int len = (right - left) / 2;
int centerX = left + (right - left) / 2, centerY = top + (bot - top) / 2;
for (int i = 0; i <= 360; i++)
{
int degrees = i;
double radians = degrees * (Math.PI / 180);

int x = centerX + (int)(len * Math.Cos(radians));
int y = centerY + (int)(len * Math.Sin(radians));
e.Graphics.FillRectangle(Brushes.Red, x, y, 1, 1); // single pixel drawing
}
```

But Ellipse is more difficult

http://www.petercollingridge.co.uk/tutorials/computational-geometry/finding-angle-around-ellipse/

Upper link is help for Ellipse

Increase distance when draw a ellipse - c# - csharp, c# drawing library calculate ranges and midpoints to draw and circle. Basically i have a menu that user choose the shape wanted to be drawn, then the user click � c# drawing library calculate ranges and midpoints to draw and circle Hot Network Questions Airline schedule flights to arrive at the same time its scheduled to depart

To draw a circle, use `g.DrawEllipse`, here is a nice extension method for it:

```public static void DrawCircle(Graphics g, Pen pen, float centerX, float centerY, float radius)
{
}
```

To draw filled, simply change `DrawEllipse` to `FillElipse` and `Pen` to `Brush`:

```public static void DrawCircleFilled(Graphics g,  Brush brush, float centerX, float centerY, float radius)
{
}
```

If you insist on drawing shapes only with lines, then fear not. A trinagle is simply drawn with three lines, that's fairly easy so I won't write that here. As for a circle:

Circle is made out of a several segments, the more segments, the better the quality of a circle. You can start with a simple triangle, then add one more line and you have a square, then pentagon, hexagon and so one. With each line the shapes resembles more of a circle optically. As you can see, each line covers (360 / N) of the total angle. So you can use a for cycle to draw all segments (lines).

Bitmap/Midpoint circle algorithm, write an implementation of the midpoint circle algorithm (also known as ensure index is in range before setting (depends on your image (defn draw-circle [ draw-function x0 y0 radius] Using pure FBSL's built-in graphics functions: The program automatically shows all of the plot's points by finding the� First, it's actually drawing a polygon with 64 sides. If you increase the number of sides in the polygon, it'll draw a closer approximation of a circle, but you'll probably find that 64 is plenty in most cases. You'll also notice that before we draw the circle, we save our location and orientation, and we restore it after we've drawn the circle.

If you specify with two points((x1,y1),(x2,y2)) the diameter of the circle, then use `DrawEllipse` with x,y,w,h

x = cx-r

y = cy-r

d = w = h = sqrt((x2-x1)^2+(y2-y1)^2)

where

cx = |x2-x1|/2

cy = |y2-y1|/2

r = d/2

For triangle you really need three points though. You could restrict it to two points as in specifying the hypotenuse of a right triangle. That still isn't enough information though because there are two right triangles that could have that hypotenuse, the upper and lower side. What kind of triangle do you want? right, iso, acute, equilateral, obtuse?

Shapes and basic drawing overview, To draw a circle, specify an Ellipse whose Width and Height values are equal. XAML Copy. <Ellipse Fill� By using the mid-point subdivision algorithm, we can draw a line with close approximation between two points. The mid-point subdivision line drawing algorithm subdivides the line at its midpoints continuously. The Mid-point Subdivision algorithm helps to compute or calculate the visible areas of lines that appear in the window.

2d Raster algorithms - Computer Science, OpenGL definitions: application programmer's view of graphics; we will now look at (OpenGL) graphic library implementor's Code: draw line from (x0, y0) to (x1, y1): following works if slope < 1, and x0 < x1 midpoint algorithm derives a fast way to compute when to increase the Scan converting circles. The first two are the coordinates of the center point of the arc, the third argument is the radius of the arc, and the final two arguments define the start and end angle of the arc. All angles are defined in radians, so drawing a circle is the same as drawing an arc from 0 to 2 * M_PI radians.

Mid-Point Circle Drawing Algorithm, The mid-point circle drawing algorithm is an algorithm used to determine the points needed for rasterizing a circle. We use the Pk + 2(yk +1) + 1, when Pk <= 0 i.e the midpoint is inside the circle (xk+1 = xk) To draw a circle of radius 3 centred at (0, 0) C#. filter_none. edit close. play_arrow. link brightness_4 code � The private subroutine draw_circle_toch, which writes to a channel, is used by both draw_circle_rgb and draw_circle_sc and the interface allows to use draw_circle with rgb images and grayscale images. interface draw_circle module procedure draw_circle_sc, draw_circle_rgb end interface private:: plot, draw_circle_toch subroutine plot (ch, p, v)

Midpoint circle algorithm, In computer graphics, the midpoint circle algorithm is an algorithm used to determine the points needed for rasterizing� Draw an Ellipse rotating over a Circle in C++ graphics graphics.h library is used to include and facilitate graphical operations in the program. graphics.h functions can be used to draw different shapes, display text in different fonts, change colours and many more.