Let's say we have the following line:
pt1 = 10*randn(1,2);
pt2 = 10*randn(1,2);
line([pt1(1), pt2(1)],[pt1(2),pt2(2)])
The points where four equally spaced orthogonal lines cross it are:
n = 4;
t = linspace(0,1,n+2);
t = t(2:(end-1));
v = pt2 - pt1;
x = pt1(1) + t*v(1);
y = pt1(2) + t*v(2);
h = line(x,y);
h.LineStyle = 'none';
h.Marker = 'o';
Next we need to normalize that vector:
delete(h)
v = v / norm(v);
And then we rotate it by 90 degrees. That's just swapping the X & Y components of v, and changing the sign of one:
for i=1:n
line([x(i)+v(2), x(i)-v(2)],[y(i)-v(1), y(i)+v(1)]);
end
The one catch at this point is that the axes might be using different scale factors for the X & Y. This will make the lines look like they're not orthogonal, even if they are mathematically. We can fix this by calling:
0 Comments
Sign in to comment.