locked
Vectors RRS feed

  • Question

  • Hi

    I am wanting to create a rectangle for two points (vector). I need a function that takes two points and a length and calculates a perpendicular point from line (vector) AB, to a given length.

    I found this code, however it doesn't seem to work.

            Private Function doit(ByVal a As PointF, ByVal b As PointF, ByVal l As Double) As PointF
                Dim lfraction, dx, dy As Double
                dx = b.X - a.X
                dy = b.Y - a.Y
                If dx = 0 And dy = 0 Then Exit Function
                lfraction = l / Math.Sqrt(dx * dx + dy * dy)
                Return New Point(b.X + lfraction * dy, b.Y + lfraction * dx)
            End Function
    

    Is there any easy or other methods i can use to create a rectangle from a line

    Maybe a line stroke method or something.

    Thanks

    Gary

    Tuesday, November 15, 2011 3:26 PM

Answers

  • Gary,

    In my opinion, there is only a small typo in your code :

    Return New Point(b.X - lfraction * dy, b.Y + lfraction * dx)

    • Marked as answer by garusher Tuesday, November 15, 2011 3:52 PM
    Tuesday, November 15, 2011 3:42 PM

All replies

  • Gary,

    In my opinion, there is only a small typo in your code :

    Return New Point(b.X - lfraction * dy, b.Y + lfraction * dx)

    • Marked as answer by garusher Tuesday, November 15, 2011 3:52 PM
    Tuesday, November 15, 2011 3:42 PM
  • Gary,

    In my opinion, there is only a small typo in your code :

    Return New Point(b.X - lfraction * dy, b.Y + lfraction * dx)


    Thanks

    Sygrien

    Tuesday, November 15, 2011 3:52 PM