# How I can calculate the distance between a point and a line?

0 favourites
• 5 posts
From the Asset Store
Connect the dots in the correct order and draw happy animals!
• I really need to know how to calculate the distance between a point and a line. The expression Distance refers to the distance between two points, so it doesn't work for me.

#### Tagged:

• Ah, I love math like that. Google of course can give you the formula, but it’s fun to derive it.

Two points on the line

X0,y0

X1,y1

The point to get the distance of

Px,py

Dist = ((x0-x1)*(py-y1)-(y0-y1)*(px-x1))/distance(x0,y0,x1,y1)

Anyways that’ll give you the signed distance. It will be negative on one side of the line. Use abs() to make it positive.

• Wonderful!! But, I wonder if it has some error because the closer it gets to x0, the larger the resulting distance gets. My math is horrible. Anyway, if I can make progress on this I will be able to find the intersection point between the line and the perpendicular.

• Try the formula again. I made a typo. One of the +'s needed to be -.

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• I love math too, but I don't have your powers. Now it worked out, you saved my life. Regards.

• 5 posts