# Finding a perpedicular segmet

Given two points $$p_0 = (x_0, y_0), p_1 = (x_1, y_1) \in \mathbb{R}^2$$, regarding the segment connecting the two points, call it $$Q$$, how can we find the perpendicular segment $$P$$ which contains the point $$p_0$$ at its middle and is $$2d$$ units long (by euclidean distance)?

The slope of $$Q$$ is given by $$\frac{y_1-y_0}{x_1-x_0}$$, hence the slope of $$P$$ is its negative inverse $$\frac{x_0-x_1}{y_1-y_0}$$. From here we can find the line with the slope of $$P$$ using the slope and the coordiates of $$p_0$$ though i'm not sure how to calculate the points on this line that are $$d$$ units away.

How can we find these points?

• The problem is not clearly defined. You can have any segment along that line that is $2d$ long. Does it have to be symmetric with respect to the middle of $Q$? Or is one end on the middle (in this case you have two solutions, since the other end is at $2d$ on either side)? Commented Aug 24, 2023 at 16:59
• To clarify: $d$ is the distance between $p_0$ and $p_1$ and you would like to find the coordinates of the points $d$ units away from $p_0$ and perpendicular to the segment $\overline{p_0p_1}$? Commented Aug 24, 2023 at 17:55
• @Andrei Yes the point $p_0$ must be in the middle of the segment $P$. $S$ and $P$ are the same, I accidently changed the name. Commented Aug 25, 2023 at 10:41

Define the $$x$$-displacement $$X$$ between $$p_0$$ and $$p_1$$: $$X = x_1 - x_0,$$ and similarly for $$y$$-displacement $$Y$$: $$Y = y_1 - y_0.$$ By the Pythagorean theorem, $$d^2 = X^2 + Y^2,$$ although we don't actually need to calculate $$d$$ explicitly.

Rotating the point $$p_1$$ counterclockwise by a right angle about the center $$p_0$$ yields the new point $$p_+ = (x_0 - Y, y_0 + X),$$ and after a clockwise rotation, we get the new point $$p_- = (x_0 + Y, y_0 - X).$$

You can verify that:

1. Rotation point $$p_0$$ is the midpoint of $$p_+$$ and $$p_-$$.

2. New points $$p_+$$ and $$p_-$$ are each $$d$$ units away from $$p_0$$.

3. New segment $$\overline{p_+p_-}$$ is perpendicular to $$\overline{p_0p_1}$$.

Here's an interactive visualization to see this in action. You can drag the points themselves or modify their coordinates in the left margin. Drag the parameter $$s$$ to rotate the segments.

• $d$ is given, and is not necessarily equal to the distance from $p_0$ to $p_1$ Commented Aug 24, 2023 at 21:49
• Do you think so? I asked about this in the comments. OP doesn't explain $d$. I can modify my answer to incorporate an arbitrary value of $d$ if OP clarifies. Commented Aug 24, 2023 at 22:01