QB64 Phoenix Edition
Line Points - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Prolific Programmers (https://qb64phoenix.com/forum/forumdisplay.php?fid=26)
+---- Forum: Petr (https://qb64phoenix.com/forum/forumdisplay.php?fid=52)
+---- Thread: Line Points (/showthread.php?tid=3078)



Line Points - Petr - 09-25-2024

Small utility for calculating points in line.

Code: (Select All)

Type LinePoints
    X As Integer
    Y As Integer
End Type
ReDim Shared LP(0) As LinePoints

Screen _NewImage(800, 600, 32)

Line (40, 399)-(100, 199)
GETPOINTS 40, 399, 100, 199, LP()
Sleep
'if all points in array are calctulated correctly, all points in LINE are draw yellow


For D = 0 To UBound(LP)
    PSet (LP(D).X, LP(D).Y), &HFFFFFF00
Next D


Sub GETPOINTS (x1, y1, x2, y2, A() As LinePoints)
    Dim lenght As Integer
    lenght = _Hypot(x1 - x2, y1 - y2) 'Fellippe Heitor show me using this great function.
    ReDim A(lenght) As LinePoints
    For fill = 0 To lenght
        If x1 > x2 Then A(fill).X = x1 - fill * ((x1 - x2) / lenght)
        If x1 < x2 Then A(fill).X = x1 + fill * ((x2 - x1) / lenght)
        If x1 = x2 Then A(fill).X = x1
        If y1 > y2 Then A(fill).Y = y1 - fill * ((y1 - y2) / lenght)
        If y1 < y2 Then A(fill).Y = y1 + fill * ((y2 - y1) / lenght)
        If y1 = y2 Then A(fill).Y = y1
    Next
End Sub



RE: Line Points - TerryRitchie - 09-25-2024

Hey that's handy. Thank you.


RE: Line Points - Dav - 09-26-2024

Nice snippet.  Thanks.

- Dav