pBook‎ > ‎Matlab‎ > ‎

Drawline

posted Aug 29, 2014, 5:14 AM by Javad Taghia   [ updated Aug 29, 2014, 5:14 AM ]
For drawing line between two points use the function below:
function [] = drawline(p1, p2 ,color)
theta = atan2( p2(2) - p1(2), p2(1) - p1(1));
r = sqrt( (p2(1) - p1(1))^2 + (p2(2) - p1(2))^2);
line = 0:0.01: r;
x = p1(1) + line*cos(theta);
y = p1(2) + line*sin(theta);
plot(x, y , color)

and call it in your program as:
drawline([fx(i) fy(i)] ,[y(i,1) y(i,2)],'red')
Comments