Results 1 to 3 of 3

Thread: Co-ordinates of a point on a line [resolved by beachbum]

  1. #1

    Thread Starter
    Addicted Member Guru's Avatar
    Join Date
    May 2000
    Location
    sulking in the cupboard under the stairs
    Posts
    237

    Co-ordinates of a point on a line [resolved by beachbum]

    I've got a line (control) on a form

    The line can be anywhere and at any angle. ie x1 can be > or < x2 and y1 can be > or < y2.

    I want to calculate the co-ordinates of a point on the line 1/4 of the way along from the x1,y1 end.

    I reckon the easiest way is to convert to polar co-ordinates and back again.

    any other suggestions?
    Last edited by Guru; Feb 6th, 2002 at 05:31 AM.
    Another light-hearted post from Guru

  2. #2
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Hi
    Finding a position on a line is simply a matter of using y = mx + b. Here is some code for u to play around with

    Form contains
    Picture1 picture box
    Line1, Line2, Line3 inside of Picture 1 'For effect change colour of Line1
    Command1 button outside of picture1
    VB Code:
    1. Private Sub Command1_Click()
    2.     Randomize
    3.     Picture1.Scale (0, 1000)-(1000, 0)'Any scaling will work
    4.     With Line1
    5.         .X1 = Int(Rnd * 1001)'Set initial line coords
    6.         .X2 = Int(Rnd * 1001)
    7.         .Y1 = Int(Rnd * 1001)
    8.         .Y2 = Int(Rnd * 1001)
    9.     End With
    10.    
    11.     'Find quarter way position from x1
    12.     With Line1: Line2.X1 = (.X2 - .X1) \ 4 + .X1: End With
    13.     With Line2: .X2 = .X1: .Y1 = 0: .Y2 = 1000: End With
    14.     'Get angle of line and add y coords ie Y = mx + b
    15.     With Line1: Line3.Y1 = (.Y2 - .Y1) / (.X2 - .X1) * (Line2.X1 - .X1) + .Y1: End With
    16.     With Line3: .Y2 = .Y1: .X1 = 0: .X2 = 1000: End With
    17. End Sub
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  3. #3

    Thread Starter
    Addicted Member Guru's Avatar
    Join Date
    May 2000
    Location
    sulking in the cupboard under the stairs
    Posts
    237
    Thanks beachbum

    perfect!
    Another light-hearted post from Guru

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