Results 1 to 5 of 5

Thread: [RESOLVED] draw this?

  1. #1

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Resolved [RESOLVED] draw this?

    how can i draw this (attached image)?
    i'm sure there must be a mathematical formula for the radii.
    i tried to draw the arc but that isn't simple either, so any help would be appreciated...Name:  image.jpg
Views: 155
Size:  16.3 KB

  2. #2
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: draw this?

    The lines are given by endpoints of the form (0, nw), ((m-n)w, 0) for constant m and w, and for n ranging from 1 to to m-1. In the drawn case, m=16, one more than the number of lines drawn, and I'd estimate w (the width) at around 20 pixels. The curve is a little harder to figure out. Suppose instead of discrete lines we had a continuum of lines, with endpoints (0, d), (D-d, 0) for some constant D, d ranging from 0 to D. The equation of a line of that form is...

    y(d) = d - xd/(D-d)

    Imagine focusing on lines slightly to the side of y(d), say y(d+e) for e small. Intersecting these two algebraically one finds the point of intersection is ((D-d)(D-(d+e))/D, d(d+e)/D). In the limit as e goes to 0 the intersection point is ((D-d)^2 / D, d^2 / D). One can show these x and y values are on the curve

    y = (D - sqrt(Dx))^2 / D, x between 0 and D

    The limiting curve, as you take arbitrarily many points, is then like this (unfortunately the x and y axes have different spacing there, so it's a little distorted).
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  3. #3

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: draw this?

    i self resolved it, but i was guessing you'd reply.
    your mathematics is light years ahead of mine, but this is my solution:

    vb.net Code:
    1. e.Graphics.DrawArc(Pens.Black, 0, -Me.ClientSize.Height, CInt(Me.ClientSize.Width * 2), CInt(Me.ClientSize.Height * 2), 90, 90)
    2.  
    3. Dim degrees() As Integer = Enumerable.Range(1, 60).Select(Function(x) x * 6).ToArray
    4. Dim radians() As Single = Array.ConvertAll(degrees, Function(x) CSng(Math.PI * x / 180))
    5. Dim points1() As PointF = Array.ConvertAll(radians, Function(f) New PointF(CSng(Me.ClientSize.Width + Math.Sin(f) * Me.ClientSize.Width), CSng(0 - Math.Cos(f) * Me.ClientSize.Height)))
    6. Dim points2() As PointF = Array.ConvertAll(radians, Function(f) New PointF(CSng(Me.ClientSize.Width + Math.Sin(f) * (Me.ClientSize.Width + 200)), CSng(0 - Math.Cos(f) * (Me.ClientSize.Height + 200))))
    7.  
    8. For x As Integer = 31 To 44
    9.     e.Graphics.DrawLine(Pens.Black, points1(x), points2(x - 10))
    10. Next
    11.  
    12. For x As Integer = 44 To 29 Step -1
    13.     e.Graphics.DrawLine(Pens.Black, points1(x), points2(x + 10))
    14. Next

  4. #4
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: [RESOLVED] draw this?

    I'm glad it worked out. I confess I haven't fully worked through the logic behind your code. I was somewhat shocked it worked when I tried it; I can see the logic in general, but it gets closer than I'd expect to the original pattern considering how indirect the method is. In any case, I had something like the following in mind:

    vb.net Code:
    1. Dim m As Integer = 16
    2. Dim w As Integer = Me.ClientSize.Width / (m - 1)
    3. Dim points1() As PointF = Enumerable.Range(1, m - 1).Select(Function(n) New PointF(0, Me.ClientSize.Height - w * n)).ToArray
    4. Dim points2() As PointF = Enumerable.Range(1, m - 1).Select(Function(n) New PointF(w * (m - n), Me.ClientSize.Height)).ToArray
    5. For n As Integer = 0 To m - 2
    6.     e.Graphics.DrawLine(Pens.Black, points1(n), points2(n))
    7. Next

    It produces extremely similar output to both your method and your original picture.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  5. #5

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: [RESOLVED] draw this?

    thanks again jemidiah...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width