2

I have a line (P1, P2), and a point on that line (midpoint). What equation can I used to find the perpendicular line of line (P1, P2), that passes through midpoint. The point labelled with a '?' is unknown. I do not wish to use angles, only the 3 points given (P1, P2, midpoint). The line P1, P2 can be of any orientation/angle.

Thanks in advance.

enter image description here

Joe Morgan
  • 430
  • 2
  • 8
  • 19

2 Answers2

4

Let define vector

D = P2 - P1  (dx=x2-x1, dy = y2-y1)

and middle point

mx = (x2+x1)/2
my = (y2+y1)/2

Perpendicular to D vector

PD = (-dy, dx)

Unit (normalized) perpendicular vector

U = (-dy / L, dx / L)
where
L = Sqrt (dx * dx + dy * dy)

And coordinates of point lying at distance F from the middle are

x = mx + U.x * F
y = my + U.y * F

or (for point at another side)

x = mx - U.x * F
y = my - U.y * F
MBo
  • 77,366
  • 5
  • 53
  • 86
  • This is definitely correct. Perhaps there are some mistakes in implementation.... – MBo Nov 29 '19 at 05:31
  • my fault. I had a small issue with my code.. now the question is what needs to be done if I wanted to perform the same thing if we add z-axis value to it. – Desolator Nov 29 '19 at 06:12
  • In 3D case we have infinite number of perpendiculars (circle circumference), so it is necessary to select some direction - depends on the real task. – MBo Nov 29 '19 at 06:16
  • I know the length of the perpendicular line and I know the mid-point and I have both vertices P1, P2 in x,y,z coordinates. How can I get the coordinates of that vertex that performs the perpendicular line that I'm trying to draw. Can you elaborate more on that? – Desolator Nov 29 '19 at 06:19
  • How do you want to choose some direction from infinite number of possible directions? Randomly? Some preference? – MBo Nov 29 '19 at 06:27
  • I'll write a question with an example and will paste it here once I'm done. – Desolator Nov 29 '19 at 06:28
  • I've been looking for this calc for a while, but I need it in 3D. How is this looking in 3D space? – arnoldino Jun 08 '20 at 04:24
  • @arnoldino There is infinite number of perpendiculars in 3d without additional conditions. [Get arbitrary perpendicular](https://stackoverflow.com/questions/22340313/finding-point-of-t-distance-on-a-perpendicular-line-on-the-same-plane-as-a-given/22343809#22343809) – MBo Jun 08 '20 at 04:51
0

Coordinates of P1: (x1,y1) Coordinates of P2: (x2,y2)

Coordinates of midpoint: ( (x1+x2)/2 , (y1+y2)/2) Slope of the P1P2 line: (y1-y2)/(x1-x2) Slope of any perpendicular line to P1P2: (x2-x1)/(y1-y2)

Equation of the red line: y - (y1+y2)/2 = ((x2-x1)/(y1-y2))*(x - (x1+x2)/2)

If you have the actual values of coordinates of P1 y P2, then just make a substitution.