Solved

# The tale of two lines

Posted on 2001-08-07
138 Views
If I have two lines on a graphic, and for each line I have two coordiantes.

How can I get the coordinates of the intersection between the two in the most efficiant way possible ?
0
Question by:Pennywisdom

LVL 18

Accepted Solution

bobbit31 earned 100 total points
ID: 6361318
0

LVL 3

Expert Comment

ID: 6361321
0

LVL 3

Expert Comment

ID: 6361466
Formula for a Line
x = ay + b

line 1:
x = 3y + 1

line 2:
x = 2y + 3

therefore:

3y + 1 = 2y + 3

((3y - 2y) = (3 - 1))

y = 2

x = 3(2) + 1
x = 7

The coordinates are x = 7, y = 2

The number beside the y controls the pitch.  And the other number controls the height above the x-axis (or y?).

In terms of programming, you'll probably be able to do it all in one or two lines.  All you really need is the a and b and do some formula against it to get y, then get x.
0

LVL 5

Expert Comment

ID: 6361568
Hi Pennywisdom,

If your lines are controls, try this:

Private Sub Command1_Click()
k1 = (Line1.Y2 - Line1.Y1) / (Line1.X2 - Line1.X1)
c1 = Line1.Y1 - k1 * Line1.X1
k2 = (Line2.Y2 - Line2.Y1) / (Line2.X2 - Line2.X1)
c2 = Line2.Y1 - k2 * Line2.X1
x = (c2 - c1) / (k1 - k2)
y = k1 * x + c1
Print x, y
End Sub
0

LVL 3

Expert Comment

ID: 6361588
Formula for a Line
x = ay + b

line 1:
x = 3y + 1

line 2:
x = 2y + 3

therefore:

3y + 1 = 2y + 3

((3y - 2y) = (3 - 1))

y = 2

x = 3(2) + 1
x = 7

The coordinates are x = 7, y = 2

The number beside the y controls the pitch.  And the other number controls the height above the x-axis (or y?).

In terms of programming, you'll probably be able to do it all in one or two lines.  All you really need is the a and b and do some formula against it to get y, then get x.
0

Author Comment

ID: 6365156
Thanks alot thats exacly what I needed
0

LVL 18

Expert Comment

ID: 6365276
0

## Featured Post

### Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…