Results 1 to 8 of 8

Thread: [RESOLVED] Finding all X/Y points between two given points

Hybrid View

  1. #1
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    Re: Finding all X/Y points between two given points

    Quote Originally Posted by WarrenW
    Hi,

    I have two X/Y points on my form. I need to find every X/Y between the two as if you were drawing a line. I tried thinking how to do it but I'm having trouble.

    I know I need as many steps in between as possible. For example, if X1 and X2 are only one pixel apart and Y1 and Y2 are 20 pixels apart, I need 20 points in between. So I need the most depending on if the X or Y has the biggest difference.

    I should know how to do this but its been a long morning!
    I think this might give you what you need, but it I didnt really test it much
    I really dont understand how you are caculating the number of points though ... shouldnt it just be square root of the sum of the deltas squared?
    Code:
    Private Sub Command1_Click()
    Dim i As Integer, x(1) As Double, y(1) As Double
    Dim yInt As Double, slope As Double
    Dim tstY As Double
    x(0) = 1: x(1) = 200: y(0) = 1: y(1) = 200
    
    
    slope = (y(1) - y(0)) / (x(1) - x(0))
    yInt = y(1) - slope * x(1)
    Dim strResults As String
    For i = x(0) To x(1)
        tstY = slope * i + yInt
        If tstY - Fix(tstY) = 0 Then
            strResults = strResults & i & "," & tstY & vbCrLf
        End If
    Next i
    
    MsgBox strResults
    
    
    End Sub

  2. #2
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Finding all X/Y points between two given points

    Quote Originally Posted by Muddy
    I really dont understand how you are caculating the number of points though ... shouldnt it just be square root of the sum of the deltas squared?
    Think about it. The number of points will always be the larger of the two vectors (is that the right term? i.e. X2-X1 or Y2-Y1). That code I posted calculates the points from the perspective of the larger vector so that no pixels are ever left out.

  3. #3
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    Re: Finding all X/Y points between two given points

    Quote Originally Posted by Milk
    Think about it. The number of points will always be the larger of the two vectors (is that the right term? i.e. X2-X1 or Y2-Y1). That code I posted calculates the points from the perspective of the larger vector so that no pixels are ever left out.
    Im just speaking from a math point of view ... Im definitely not a graphics programmer, so there is probably something I am missing ...

    IF x and y are screen coordinates I can see where you would have to convert to pixel locations before doing the math, but as far as I know the number of integer coordinate points between two coordinates on a straight line is sqr(deltax^2 + deltay^2) ...

    but, I can see how that wouldnt work very well if there are more pixels per inch in one dimension compared to the other ...

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2000
    Posts
    1,463

    Re: Finding all X/Y points between two given points

    Thanks Milk! Can you show me how to call this? Sorry, I keep doing something wrong...

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