Point of two intersecting lines at 90 degree Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Point of two intersecting lines at 90 degree

18 Sep 2017, 06:42

Hello guys, I am trying to write a script which asks to input A(x;y) and B(x1;y1) and it displays the end result, which is coordinates of c(a;b). I can get lengths of lines so easily because they make right triangles, but when it comes to coordinates I am lost on what to do :oops:
Could someone help me out?

This is an illustration:
Spoiler
teadrinker
Posts: 1078
Joined: 29 Mar 2015, 09:41
Contact:

Re: Point of two intersecting lines at 90 degree  Topic is solved

18 Sep 2017, 17:59

Hi, mast4rwang. It's just school mathematics. :)

We have the line passing through two points (x1, y1) and (x2, y2), and point B(x3, y3)

The general equation of line with two points is
(y1 - y2)*X + (x2 - x1)*Y + (x1*y2 - x2*y1) = 0
In our case x2 and y2 are equal 0, therefore
y1*X - x1*Y = 0

If x1 equal 0, then the intersection point x = 0, y = y3.
If y1 equal 0, then x = x3, y = 0.

Else
Y = (y1/x1)*X
y1/x1 is the line's slop, hence the perpendicular's slop is -x1/y1
Then the perpendicular's equation is
Y - y3 = -x1/y1(X - x3)

Now to get the intersection point we need to solve the set of equations:
Y - y3 = -x1/y1(X - x3)
Y = (y1/x1)*X

(y1/x1)*X - y3 = -x1/y1(X - x3)
-(y1**2/x1**2)*X + y1/x1*y3 = X - x3
X + (y1**2/x1**2)*X = y1/x1*y3 + x3

X = (y1/x1*y3 + x3)/(y1**2/x1**2 + 1)
Y = (y1/x1)*X

Code: Select all

coords := GetIntersection( {x: -2, y: 2}, {x: 1, y: 3} )

MsgBox, % "X = " . coords.x . A_Tab . "Y = " . coords.y

GetIntersection(point1, point2)  {
   if (point1.x = 0)
      Return {x: 0, y: point2.y}
   
   if (point1.y = 0)
      Return {x: point2.x, y: 0}
   
   X := (point1.y/point1.x * point2.y + point2.x)/( (point1.y**2)/(point1.x**2) + 1 )
   Y := point1.y/point1.x * X
   
   Return {x: X, y: Y}
}
BoBo
Posts: 2519
Joined: 13 May 2014, 17:15

Re: Point of two intersecting lines at 90 degree

19 Sep 2017, 12:17

:o :o :o No doubt about that: "It's tea time!" :thumbup:
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: Point of two intersecting lines at 90 degree

19 Sep 2017, 14:11

Well, one thing is certain: Teadrinker, you got a new fan 8-)

Return to “Ask For Help”

Who is online

Users browsing this forum: asad41163, Bing [Bot], boiler and 201 guests