-2

I have co-ordinates (x0,y0) and (x1,y1) that define a line of length L. I want to draw a line of length L that is perpendicular to this line such that the midpoint of the new line touches (x0,y0) - so that it forms a T. I need to obtain the co-ordinates (x3,y3) and (x4,y4) of this line.

I know that the slope of the original line is (y1-y0) / (x1-x0) and that the the slope of the new line will be -1 * the inverse of that.

This question is broadly similar (and probably quite simple) to this question:

Drawing line perpendicular to a given line

If I knew x3,y3 then I'd obviously be able to calculate x4,y4 easily, but I'm stumped at how to obtain the co-ordinates x3,y3.

  • This doesn't seem like an [on-topic](https://stackoverflow.com/help/on-topic) question. Will you be "drawing" the line programmatically? or is this just pure maths and geometry? :-) – TrebledJ Dec 12 '18 at 15:21
  • I'm voting to close this question as off-topic because it is not about programming but rather belongs on [Mathematics Stack Exchange](https://math.stackexchange.com/). – Rory Daulton Dec 12 '18 at 16:05
  • I'm voting to close this question as off-topic because it is about geometry / mathematics instead of programming / coding / programming tools / software algorithms. – Pang Dec 14 '18 at 07:02

1 Answers1

1

You can do it with similar triangles. Cant draw a pic on here but ends up:

x3 = x0 - (y1-y0)/2

y3 = y0 + (x1-x0)/2

x4 = x0 + (y1-y0)/2

y4 = y0 - (x1-x0)/2

NeilWey
  • 26
  • 1
  • Yeah! That's awesome, that's exactly it! How did you get to that? That's a lot better than what I was trying as I was getting NaN issues when the line was horizontal. – user10781552 Dec 12 '18 at 15:49
  • If you plot it on a graph you will see that the area under the line (x0,y0) to (x1,y1) is a triangle twice the size of the area to the right of the line (x0,y0) to (x3,y3) – NeilWey Dec 12 '18 at 15:56