MrClear
MrClear

Reputation: 139

Plotting a point on straight line

The equation of a line is Y = M.X + C,

I have a point and the points facing angle, So I can work out the line equation

Slop := Tan(Rot)  // We  are passing radians to convert to gradient
C := (-Slop*X) + Y // Substitute our point XY values 

So that's the current math I am using to get our Y intercept and our slop or gradient.

However I am wanting to know how to plot a point X amount of distance in front of our starting point.

Currently, I am attempting the following where Y2 and X2 are values of our original point plus 100 units.

 NewPoint.X :=  Round( (Y2 - C) / Slop );
 NewPoint.Y := Round((slop*X2) + C);

Here a paste bin of the full function :

https://pastebin.com/8435NzYc

Thanks.

Upvotes: 0

Views: 364

Answers (2)

MBo
MBo

Reputation: 80325

To make things simpler, define your line with parametric equations:

X = X0 + UX * t
Y = Y0 + UY * t

Where X0, Y0 are coordinates of some base point, UX, UY are components of unit direction vector. Note that

UX = Cos(Phi)
UY = Sin(Phi)

where Phi is angle between line and OX axis.

On the other hand, Tan(Phi) is equal your slope.

If line is defined with two points, then

Len = Hypot(X1 - X0, Y1 - Y0)
UX = (X1 - X0) / Len
UY = (Y1 - Y0) / Len

And point at needed distance Dist from base point is just

X = X0 + UX * Dist
Y = Y0 + UY * Dist

Upvotes: 2

Pipe Runner
Pipe Runner

Reputation: 82

The problem you have defined seems like a line-circle intercept problem. From what I can gather, you have a point X,Y which lies on a line whose slope you are already aware of. Now all you need to do is use a circle with origin X,Y and radius 100 (in case you want a point 100 units away from X,Y on the line). Find the intercept of the circle on the line and you should be done. There is a straight forward formula for it.

Note: There will be two points that will satisfy the equation. You need to decide which one to pick.

enter image description here

Upvotes: -1

Related Questions