Draw a line through two points

matlab, plot

Solution

What about

  function = long_line(X,Y,sym_len)
       dir = (Y-X)/norm(Y-X);
       Yp = X + dir*sym_len;
       Xp = X - dir*sym_len;
       line(Xp,Yp);
  end

being `sym_len` one half of the expected length of the plotted line around `X`?

Problem

Using MatLab, I know how to create a line segment connecting two points using this code: ``` line([0 1],[0 1]) ``` This draws a straight line segment from the point (0,0) to the point (1,1). What I am trying to do is continue that line to the edge of the plot. Rather than just drawing a line between these two points I want to draw a line through those two points that spans the entire figure for any set of two points. For this particular line and a x=-10:10, y=-10:10 plot I could write: ``` line([-10 10], [-10 10]); ``` But I would need to generalize this for any set of points.

Original source