How to draw orthogonal lines ?
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have two points, one is start and the other is end point. I have connected these two points by a straight line. Now i want to draw orthogonal lines over the line. How can i draw it? I have attached a picture for reference. As shown in the picture, i want eight orthogonal planes placed in equidistant. Please help me with this problem.
0 comentarios
Respuestas (3)
blaat
el 14 de Ag. de 2015
The line between your two points can be described by
y = a (x - x1) + b,
where
a = (y2 - y1)/(x2 - x1)
b = y1,
if we call your two points (x1, y1) and (x2, y2). Lines perpendicular to the original line will have a slope of -1/a and can be expressed as:
y = -1/a (x - x0) + y0,
where (x0, y0) is the point on the original line where it intersects the orthogonal line.
Equidistant points on the line can be easily computed using linspace():
num_orth = 8;
x_orth = linspace(x1, x2, num_orth);
y_orth = linspace(y1, y2, num_orth);
1 comentario
Mike Garrity
el 14 de Ag. de 2015
Editada: Mike Garrity
el 14 de Ag. de 2015
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); % evenly spaced parameters
t = t(2:(end-1)); % we don't need the start and end points
v = pt2 - pt1;
x = pt1(1) + t*v(1); % p(t) = p1 + t*(p2-p1)
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:
axis equal
2 comentarios
Mike Garrity
el 14 de Ag. de 2015
Mike Garrity
el 14 de Ag. de 2015
I'm afraid I don't understand the question "why am i getting negative axis".
The length of the orthogonal lines goes at the point where I divided v by norm(v). That was to get them to be unit length. Just multiply by the length you want:
start_point = [5.95 37.55]
goal_point = [35.62 5.73]
line([start_point(1), goal_point(1)],[start_point(2), goal_point(2)],'Marker','o')
n = 8;
t = linspace(0,1,n+2);
t = t(2:(end-1));
v = goal_point - start_point;
x = start_point(1) + t*v(1);
y = start_point(2) + t*v(2);
v = 5*v / norm(v);
for i=1:n
line([x(i)+v(2), x(i)-v(2)],[y(i)-v(1), y(i)+v(1)]);
end
axis equal
3 comentarios
Image Analyst
el 15 de Ag. de 2015
It's just simple 10th grade algebra. But if you want the MATLAB way, just use linspace():
xEquallySpaced = linspace(x(1), x(2), numPoints);
yEquallySpaced = linspace(y(1), y(2), numPoints);
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!