Line Method Function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • The Mess

    #1

    Line Method Function

    I am using VB5.
    I wish I had a function to draw a line, giving the angle and length but I do
    not have the math skills involved to do this. Does anyone have a function
    that they care to share that does this?
    I was thinking something like:
    Public Sub DrawLine(X1 as single, Y1 as single, Len as single, Angle as
    single, byref X2 as single, byref Y2 as single)
    and have X2 and Y2 assigned in the Sub (rather than just a line drawn -
    because I would like to do a little more processing first.

    The purpose of this is that I have a Square (drawn with the line method)
    that is cut in half diagonally (line method) and I would like half of it (a
    triangle) shaded in with hash mark lines (user selective in what the angle
    of these marks might be.)
    Any help would be appreciated. I tried some searches and get lots of math
    lessons but I would have a lot to learn to accomplish this. Or maybe there
    is a better way?
    Thanks.


  • Steve Gerrard

    #2
    Re: Line Method Function


    "The Mess" <email@none.com > wrote in message
    news:laFkf.210$ kt5.38944@news2 0.bellglobal.co m...
    [color=blue]
    > I wish I had a function to draw a line, giving the angle and length but I do
    > not have the math skills involved to do this. Does anyone have a function that
    > they care to share that does this?
    > I was thinking something like:[/color]
    [color=blue]
    > Public Sub DrawLine(X1 as single, Y1 as single, Len as single, Angle as
    > single, byref X2 as single, byref Y2 as single)[/color]
    [color=blue]
    > Any help would be appreciated. I tried some searches and get lots of math
    > lessons but I would have a lot to learn to accomplish this. Or maybe there is
    > a better way?[/color]

    I'm afraid that any answer is going to involve some math, but not that much...

    If your angle is in degrees, you will need to convert it to radians:
    Angle = Angle / 180 * 3.14159625

    The basic formulas you need are
    X2 = X1 + Cos(Angle) * Len
    Y2 = Y1 + Sin(Angle) * Len



    Comment

    • The Mess

      #3
      Re: Line Method Function

      Thanks very much, Steve. That should get me in the right direction! Thought
      it would be more complicated than that.


      "The Mess" <email@none.com > wrote in message
      news:laFkf.210$ kt5.38944@news2 0.bellglobal.co m...[color=blue]
      >I am using VB5.
      > I wish I had a function to draw a line, giving the angle and length but I
      > do not have the math skills involved to do this. Does anyone have a
      > function that they care to share that does this?
      > I was thinking something like:
      > Public Sub DrawLine(X1 as single, Y1 as single, Len as single, Angle as
      > single, byref X2 as single, byref Y2 as single)
      > and have X2 and Y2 assigned in the Sub (rather than just a line drawn -
      > because I would like to do a little more processing first.
      >
      > The purpose of this is that I have a Square (drawn with the line method)
      > that is cut in half diagonally (line method) and I would like half of it
      > (a triangle) shaded in with hash mark lines (user selective in what the
      > angle of these marks might be.)
      > Any help would be appreciated. I tried some searches and get lots of math
      > lessons but I would have a lot to learn to accomplish this. Or maybe there
      > is a better way?
      > Thanks.
      >[/color]


      Comment

      Working...