0

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.

MrClear
  • 129
  • 1
  • 6
  • You should clarify (edit) your question. You have a point at coordinates (X1, Y1) and you have an angle, let call it Alpha. But an angle is not "facing" a point. An angle is between two intersecting line segments. Where are those line segments? And you are looking for a second point (X2, Y2). You should create agraphic showing axis X and axis Y, The point (X1, Y1), the angle with his two line segments and the second point (X2, Y2) along with what you know about the second point relative to the first or the axis. – fpiette Jan 12 '21 at 06:23
  • I what you are looking the equation of the line passing by the two points (X1, Y1) and (X2, Y2)? – fpiette Jan 12 '21 at 06:25
  • 1
    And by the way, StackOverflow rules tells that a question must be self contained. If you have code or drawing or whatever, include it in your question, not on another website. – fpiette Jan 12 '21 at 06:26

2 Answers2

2

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
MBo
  • 77,366
  • 5
  • 53
  • 86
  • Tried this method, Here are my results [Graph](https://imgur.com/a/rEEoA3H) _the point out of order is the result of the following_ Code : `Slop := Tan(Rot) -- In this case Rot is in radians` `Rot := RadToDeg(Rot) -- Converting to degrees for use in cos/sin` `NewPoint.X := Round(X + Cos(Rot) * Distance);` `NewPoint.Y := Round(Y + Sin(Rot) * Distance);` – MrClear Jan 12 '21 at 12:19
  • Cos and Sin require **radians** argument, so remove RadToDeg – MBo Jan 12 '21 at 14:19
  • ![Graph](https://imgur.com/n9DiRzg). -- Results without using RadToDeg – MrClear Jan 12 '21 at 14:41
  • @MrClear And what should I see there? Formula is correct. You can check it with known angle - for example, `Pi/4` radians (45 degrees) – MBo Jan 12 '21 at 16:42
-1

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

Pipe Runner
  • 82
  • 2
  • 6