# Get a point with given distance to a line segment

Suppose I have 3 points. A and B and C. I want the line segment through C, parallel to the line AB. I want the D with the given distance of d on the line which connects C to the AB line with the slope of 90 degrees (vertical). Basically I want to move the point C, closer to the AB line (half the distance in my case).

I know how to get a point between 2 points but I don't know how to get the point on the AB line.

### Edit:

I have A, B and C points. I want the bold line below: It's at half the distance between the AB and C and has the same slope as AB.

### How I solved it

I didn't quite use the distance. I got the parallel line through the C point and got the line between the 2 lines by calculating the mid point between A and A' and B and B'. Then connected the 2 new points.

• Sorry , but your questions seems unclear for me! what do you need exactly ? equation of st line ? or just the point of the orthogonal projection of C on AB ? Sep 25, 2015 at 13:17

Alright so here is one way of going about it (if I understood you correctly). So let $Z = (z_1,z_2)$ be the point lying on the line through $A,B$ such that the line passing through $C,Z$ is perpendicular to the line through $A,B$. You can find this point as follows.

We can find that $d(A,C) = \sqrt{104}$, $d(C,D) = \sqrt{(z_1-12)^2 + (z_2-10)^2}$, and $d(A,D) = \sqrt{(z_1-10)^2 + (z_2-20)^2}$.

So Pythagorean's theorem gives us the equation: $$(d(C,D))^2 + (d(A,D))^2 = 104.$$

But we also know that $(z_1,z_2)$ is a solution to the equation of the line through $A,B$, namely the line $y= -\frac{13}{25}x + \frac{630}{25}$.

So now you have two equations and two unknowns. Give that a try and see if you can find $Z$. Once you have $Z$ you should be able to figure out whatever else you were wondering about.

• Please see my edit. I added a picture showing what I need. Thanks. Sep 25, 2015 at 14:26
• @AlirezaNoori Alright well the same idea works to find $A'$. You don't need to find both $A'$ and $B'$ since you know $C$. So using Pythagorean's theorem you can find one equation in terms of the coordinates of $A' = (a_1,a_2)$. Then using point slope form, you can find the equation for the line through $A'$ and $C$ in terms of $a_1,a_2$. Again, two equations, two unknowns. Sep 25, 2015 at 14:39
• Thanks again. I'm really not that great at math. So could you give me the final formula or an example? I'm trying to create a software and it's urgent. I'd appreciate your help Sep 25, 2015 at 14:54
• I solved this with another method (you can see my solution at the end of my question) but I choose this as the answer. Thanks. Sep 28, 2015 at 23:18

Maybe it can be of help knowing that the line you want passes through the midpoint of $AC$. So I think the simplest way to solve your problem is finding the midpoint $M=(A+C)/2$ and then drawing the line through $M$ having the same slope as $AB$.