Effacer les filtres
Effacer les filtres

How to calculate normal to a line?

102 vues (au cours des 30 derniers jours)
Shivakumar
Shivakumar le 27 Août 2013
Commenté : ddd ppp le 4 Mai 2018
I plot a line in MATLAB using the points. Please tell me how to obtain the normal of that line? Can I get these plots in a single plot?
  2 commentaires
tala
tala le 3 Oct 2016
hi i have a 2D image of echocardiography. is there any solution to compute the normal vector of this image?
ddd ppp
ddd ppp le 4 Mai 2018
normal vector to image?

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 27 Août 2013
It is easier to answer, if you explain any details. At first I assume you mean 2D-lines, because for 3D-lines a normal line is not defined.
If you have a vector with the coordinates [x, y], the vectors [y, -x] and [-y, x] are orthogonal. When the line is defined by the coordinates of two points A and B, create the vector B-A at first, determine the orientation by the above simple formula, decide for one of the both vectors, and the midpoint between the points (A+B) * 0.5 might be a nice point to start from. Adjusting the length of the normal vector to either 1 or e.g. the distance norm(B-A) might be nice also.
  12 commentaires
Shivakumar
Shivakumar le 20 Sep 2013
@Jan Simon: My question is similar to the one you answered before. For the values I gave you already(A = [-0.6779,-0.7352]; B = [0.7352,-0.6779];), you helped me in finding normal to the line at the mid-point. Now, I am trying to find normal to the same line at the origin. Please help me. Thank you.
Jan
Jan le 21 Sep 2013
@Shivakumar: The normal of a line is a vector. Vectors can be move freely in the space, because they have a direction and a length. but no start point. Therefore the normal of the line at the midpoint is the normal at any other point also. If you want to draw the normal, it looks nice, when you start it at the midpoint of the line segment. but in a mathematical sense it is correct to start it from any other point of the X-Y-plane as well, e.g. at the origin.

Connectez-vous pour commenter.

Plus de réponses (2)

Image Analyst
Image Analyst le 27 Août 2013
A perpendicular line has a negative inverse slope. So if you used polyfit
coeffs = polyfit(x, y, 1);
then coeffs(1) is the slope. The new slope is -1/coeffs(1). Now you simply use the point-slope formula of a line to draw it. Obviously you need to know at least one point that that line goes through since there are an infinite number of lines at that slope (all parallel to each other of course).
  5 commentaires
Image Analyst
Image Analyst le 29 Août 2013
You gave the two endpoints of the original line. Those do not have to be on the new, perpendicular line, though they could. Where do you want the perpendicular line to cross/intersect the first line? At the end? In the middle? Somewhere else?
Shivakumar
Shivakumar le 30 Août 2013
I want the perpendicular line to cross in the middle. Thank you.

Connectez-vous pour commenter.


Shashank Prasanna
Shashank Prasanna le 28 Août 2013
Modifié(e) : Shashank Prasanna le 28 Août 2013
If this is a homework, please spend some time familiarizing yourself with basics of MATLAB. You can start by going through the Getting Started guide
There are several ways you could do this and all of the already suggested approaches are good. Here is how you can think about it in terms of linear algebra.
Answer: Normal lies in the null space of the the matrix A-B
A = [-0.6779, -0.7352]; B = [0.7352, -0.6779];
null(A-B)
Proof:
(A-B)*null(A-B) % Should yield a number close to zero
If you are looking to plot:
x = [A(1);B(1)];
y = [A(2);B(2)];
line(x,y,'color','k','LineWidth',2)
normal = [mean(x),mean(y)] + null(A-B)';
line([mean(x),normal(1)],[mean(y),normal(2)],'color','r','LineWidth',2)
  2 commentaires
Shivakumar
Shivakumar le 29 Août 2013
Modifié(e) : Shivakumar le 29 Août 2013
This is not my homework but It is a part of my project work. I thank you for the answer you provided.
ddd ppp
ddd ppp le 4 Mai 2018
is the null space a vector or line? does it have direction?

Connectez-vous pour commenter.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by