|
-
Feb 6th, 2002, 04:18 AM
#1
Thread Starter
Addicted Member
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 
-
Feb 6th, 2002, 05:07 AM
#2
PowerPoster
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:
Private Sub Command1_Click()
Randomize
Picture1.Scale (0, 1000)-(1000, 0)'Any scaling will work
With Line1
.X1 = Int(Rnd * 1001)'Set initial line coords
.X2 = Int(Rnd * 1001)
.Y1 = Int(Rnd * 1001)
.Y2 = Int(Rnd * 1001)
End With
'Find quarter way position from x1
With Line1: Line2.X1 = (.X2 - .X1) \ 4 + .X1: End With
With Line2: .X2 = .X1: .Y1 = 0: .Y2 = 1000: End With
'Get angle of line and add y coords ie Y = mx + b
With Line1: Line3.Y1 = (.Y2 - .Y1) / (.X2 - .X1) * (Line2.X1 - .X1) + .Y1: End With
With Line3: .Y2 = .Y1: .X1 = 0: .X2 = 1000: End With
End Sub
-
Feb 6th, 2002, 05:31 AM
#3
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|