0

I'm curently implementing a circle visualization using X points in Input.

I don't know if it's the best way (do not hesitate to tell me about any other possibility) but to realize that, i'm creating a Path with these differents points and then i use the "Flatten" function to smooth the curve :

For Each Point As Point3D In ptsLocal
            graphic_points(index).X = (panel.Width / 2) + (Point.z * facteur)
            graphic_points(index).Y = (panel.Width / 2) - (Point.y * facteur)
            Draw_ringPoint(graphic, Brushes.Gray, graphic_points(index).X, graphic_points(index).Y, 4, IdsPts(index))
            index += 1
        Next
        graphic_points(index).X = graphic_points(0).X
        graphic_points(index).Y = graphic_points(0).Y
        Dim myPath As New GraphicsPath

        'Dim translateMatrix As New Matrix
        'translateMatrix.Translate(0, 10)

        myPath.AddCurve(graphic_points)
        'graphic.DrawPath(New Pen(Color.Cyan, 2), myPath)
        myPath.Flatten()
graphic.DrawPath(New Pen(Color.BlueViolet, 2), myPath)

As you can see, I add the point "0" at the end to close the curve, here is my result :

enter image description here

as you can see, the result is good, except the connection between the last point and the first point.

How can i smooth this connection ? Or there is any other solution to realize this visualization ?

EDIT :

After using the DrawClosedCurve method, the result look better, but still have a problem on the last connection as you can see (With the last connection point):

enter image description here

And without the last connection point :

enter image description here

Toto NaBendo
  • 290
  • 3
  • 26
  • 1
    GraphicsPath doesn't help you do this, use Graphics.DrawClosedCurve() instead. – Hans Passant May 28 '19 at 12:27
  • I've just tried your solution, Thanks you, ok the last segment is smooth, but the Cercle didn't look as a circle anymore... I prefer the Path rendering, is there another solution ? – Toto NaBendo May 28 '19 at 12:44
  • [GraphicsPath.AddClosedCurve](https://learn.microsoft.com/en-us/dotnet/api/system.drawing.drawing2d.graphicspath.addclosedcurve). If you want it smooth, why are you flattening it? – Jimi May 28 '19 at 12:47
  • Maybe "smooth" is not the good word (sorry) , But I would like to draw a circle from several points. If I don't Flattening it, i'll have only straight line... the visualization will not be correct. – Toto NaBendo May 28 '19 at 12:51
  • Then use `AddClosedCurve()` with a high tension and without the *connection* point. Let the GraphicsPath close it itself. The tension lets you manage the resulting curve. You can get the same result you have with `Graphics.DrawClosedCurve()` and other similar results just modifying that value. – Jimi May 28 '19 at 12:56
  • For example, `Graphics.DrawClosedCurve()` is ~equal to `GraphicsPath.AddClosedCurve()` with a tension of ~`1.1f`. With a low tension (`0.25f`), you *flatten* the curves, resulting in slightly smoothed lines. – Jimi May 28 '19 at 13:04
  • Yes, well, that's probably the half of it: `.55f`. – Jimi May 28 '19 at 13:10
  • See my edit, i'm using a tension of 1.0 – Toto NaBendo May 28 '19 at 13:11
  • Told you to remove the *connection* point. – Jimi May 28 '19 at 13:11
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/194050/discussion-between-toto-nabendo-and-jimi). – Toto NaBendo May 28 '19 at 13:15

0 Answers0