Results 1 to 3 of 3

Thread: Drawing a Line

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    67
    I am trying to make a basic shape drawing utility on my prog.

    Currently it's for darwing a triangle.

    The user puts in the 3 sides(lengths) and they are drawn on a form.

    All I have done so far is Drawn 3 lines on a form and match there length labels to the text input from the user. To adjust the lengths of the lines I assume I need to work off some kind of scale.
    Right now I have this for side A:

    Line1.y1 = txtSideA.text
    line1.y2 = txtSideA.text

    obviously this is no good

    Any tips? Ideas on a scale?

    Thanks Much!

  2. #2
    Guest
    First, you need a Base point for your triangle. Lets just
    say it is 100, 100. Ok, now, lets assume that your sides
    are 1, 1, and 1. We will multiply each by 100, so that it
    would show up in VB. Now, what you need to do, is
    plot two of the lines from 100, 100, so that their end
    points are <length #3> apart. This is a real pain in the
    arse. The method I would use (probably isnt very
    good), involves plotting one line, then something like
    this:
    Code:
    for i = 0 to 359
      if FIGetDist(line1.x2, line1.y2, 100 + line2length * cos(i * 3.14159), 100 + line2length * sin(i * 3.14159)) = line3length then
        line2.x2 = 100 + line2legth * cos(i)
        line2.y2 = 100 + line2legth * sin(i)
        exit for
    end if
    next i
    in that code, line#legth is the legth of the line, FIGetDist
    is a Distance between 2 points function, the 100 +
    line#lenght * cos() is the X coordinate (the 100 is the X
    coordinate of the start point), the 100 + line#legth * sin
    () is the Y coordinate (again, the 100 is the Y coordinate
    of the start point). That should help you out, i think.

    Id also like to mention that that code wont cut and
    paste. FIGetDist should return a single, and, in the
    case of point distances, you will almost NEVER come out
    with a whole number. You will have to modify it so that
    it can be +- some amount of the line (say 5 twips).

    Z.

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    The analytical solution:
    Code:
      /|\
    c/ |h\b
    /  |  \
    _d__d-a_
       a
    h=sqr(c2+d2)=sqr(b2+(d-a)2)
    c2+d2=b2+(d-a)2
    c2+d2=b2+d2-2da+a2
    d=(a2+b2-c2)/(2a)
    h=sqr(c2-d2)


    if you position your a-line, the base of your triangle, horizontal with the c-d corner in origo, you will have your c-b corner in x=d and y=h. The third corner will be in y=0 and x=a

    set scalemode to User and change the scale properties so that you can place your triangle where you want, you could also scale and add offsets to the corner coordinates too if you want.

    place all lines with respective coordinate 1 and 2 in the given coordinates to form your triangle.

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