Finding coordinates of a point on a line

Kiran

This should be an easy one. I am trying to find the coordinates of a point on a straight line. I am implementing in MATLAB. I know, the coordinates of the endpoints and the distance from one of the point.

I am using the following formula for calculating the coordinates (please note, I cannot use mid-point formula, as the distance can vary).

enter image description here

I am getting the wrong results when the slope is negative. Can you please suggest, what are the conditions, that needs to be considered for using this formula? Am not aware of any other formula as well.

Rody Oldenhuis

Nothing wrong with your solution, but you need to take care of quadrant ambiguities when you take the arctangent to compute the angle θ.

There is a nice solution for that in most programming languages: atan2. Thus:

%// Your points (fill in any values)
A = [-10 0];
B = [-1 -1];

%// Use atan2!
th = atan2( B(2)-A(2) , B(1)-A(1) );

%// Distance from A to the point of interest
AP = sqrt( (B(2)-A(2))^2 + (B(1)-A(1))^2 ) / 2;

%// The point of interest
C = [
    A(1) + AP*cos( th )
    A(2) + AP*sin( th )];

%// Verify correctness with plots
figure(1), clf, hold on
line([A(1); B(1)], [A(2); B(2)])
plot(...
    A(1), A(2), 'r.',... 
    B(1), B(2), 'b.',...
    C(1), C(2), 'k.', 'markersize', 20)

In general, whenever and wherever you need to take an arctangent, use atan2 and not atan. The normal atan is only for cases where you don't know the individual components of the division y/x.

Note that your solution is not extensible to 3D, whereas the vector solutions proposed by the others here are. So in general I would indeed advise you to start working with vectors. Not only is it a lot simpler in many circumstances, it is also more versatile.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Finding the coordinates on the image knowing the center point and slope of a line

From Dev

Finding x,y coordinates of a point on an Archimedean spiral

From Dev

get coordinates of arrow of a line point

From Dev

Finding the angle made by a line in mathematical coordinates?

From Dev

Animate a point alongside a line from known coordinates

From Dev

Finding Coordinates of Line-Line Intersection in C#

From Dev

Finding point on a 3D line in C

From Dev

Finding the point of intersection on a 3D line perpendicular to a target point

From Dev

Point picker event_handler drawing line and displaying coordinates in matplotlib

From Dev

finding point on a line which is equidistant from 2 other points

From Dev

Finding the point of intersection of two line graphs drawn in matplotlib

From Dev

finding point on a line which is equidistant from 2 other points

From Dev

R - Finding closest neighboring point and number of neighbors within a given radius, coordinates lat-long

From Dev

Finding coordinates of a character?

From Dev

Finding a square in a group of coordinates

From Dev

Finding Location / Coordinates in Dart

From Dev

Finding coordinates of a character?

From Dev

Finding Closest Points to a certain Point Given its Coordinates and Maximum Distance - Query Result Undefined using Mongoose with MEAN Stack

From Dev

Get Coordinates around a point

From Dev

Getting Coordinates of a Point in a circle

From Dev

Getting Coordinates of a Point in a circle

From Dev

Get the point coordinates of a CombinedGeometry

From Dev

Get Coordinates around a point

From Dev

coordinates point is in jmapviewer polygon?

From Dev

SQL Finding the coordinates that belong to a circle

From Dev

Finding coordinates of rectangle on a curved surface

From Dev

Finding coordinates of the circumference of circle in pygame

From Dev

Make a function that makes line segment coordinates centered at point (x y) with slope m

From Dev

finding point of intersection in R

Related Related

  1. 1

    Finding the coordinates on the image knowing the center point and slope of a line

  2. 2

    Finding x,y coordinates of a point on an Archimedean spiral

  3. 3

    get coordinates of arrow of a line point

  4. 4

    Finding the angle made by a line in mathematical coordinates?

  5. 5

    Animate a point alongside a line from known coordinates

  6. 6

    Finding Coordinates of Line-Line Intersection in C#

  7. 7

    Finding point on a 3D line in C

  8. 8

    Finding the point of intersection on a 3D line perpendicular to a target point

  9. 9

    Point picker event_handler drawing line and displaying coordinates in matplotlib

  10. 10

    finding point on a line which is equidistant from 2 other points

  11. 11

    Finding the point of intersection of two line graphs drawn in matplotlib

  12. 12

    finding point on a line which is equidistant from 2 other points

  13. 13

    R - Finding closest neighboring point and number of neighbors within a given radius, coordinates lat-long

  14. 14

    Finding coordinates of a character?

  15. 15

    Finding a square in a group of coordinates

  16. 16

    Finding Location / Coordinates in Dart

  17. 17

    Finding coordinates of a character?

  18. 18

    Finding Closest Points to a certain Point Given its Coordinates and Maximum Distance - Query Result Undefined using Mongoose with MEAN Stack

  19. 19

    Get Coordinates around a point

  20. 20

    Getting Coordinates of a Point in a circle

  21. 21

    Getting Coordinates of a Point in a circle

  22. 22

    Get the point coordinates of a CombinedGeometry

  23. 23

    Get Coordinates around a point

  24. 24

    coordinates point is in jmapviewer polygon?

  25. 25

    SQL Finding the coordinates that belong to a circle

  26. 26

    Finding coordinates of rectangle on a curved surface

  27. 27

    Finding coordinates of the circumference of circle in pygame

  28. 28

    Make a function that makes line segment coordinates centered at point (x y) with slope m

  29. 29

    finding point of intersection in R

HotTag

Archive