Filter löschen
Filter löschen

Calculating the normal of a (3D) line

11 Ansichten (letzte 30 Tage)
Kees de Kapper
Kees de Kapper am 1 Jun. 2018
Kommentiert: Kees de Kapper am 3 Jun. 2018
Hi all,
I would like to calculate the normal vector of a 3D line. This normal vector should cross the origin (0,0,0), otherwise the normal vector is undefined.
How can I do this easily?
Many thanks in advance.
/Kees
  1 Kommentar
Kaninika Pant
Kaninika Pant am 1 Jun. 2018
How is this 3D line defined? ie. By a point and a direction vector? Or 2 points?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Kaninika Pant
Kaninika Pant am 1 Jun. 2018
Note that the normal vector is only a direction (cannot pass through a point). I think what you are looking for is a line passing through the origin with a direction vector normal to the previous line.
Also, given a line in any form it is always possible to find the direction vector and a point on the line. So I will answer assuming that you have found those Consider a point (x,y,z) on this normal line. Let the direction vector of the original 3D line is (l,m,n) and a point on the line be (x1,y1,z1). To find this line you need to solve the following:
1. (x-0)l+(y-0)m+(z-0)n=0 (ie. direction vectors of both lines must be perpendicular) 2. (x-x1)/l + (y-y1)/m + (z-z1)/n = k(ie. (x,y,z) must lie on the original 3D line) So, x=l*k + x1; y=m*k + y1; z=n*k + z1
Thus you only have one variable k. Put this in the first equation and simplify to get: k=-(l*x1+m*y1+n*z1)/(l^2+m^2+n^2);
After finding k plug it back to get x,y,z. Note that (x,y,z) is a point on your normal line and also the direction vector. Now you can form the equation of your normal line.
  2 Kommentare
Kees de Kapper
Kees de Kapper am 2 Jun. 2018
Dear Kaninika,
thank you very much for your help and extensive answer. It sounds to be the solution for my problem. I'll try to implement this.
All the best, Kees
Kees de Kapper
Kees de Kapper am 3 Jun. 2018
C = [1,2,3;4,4,4];
NC=(C(2,:)-C(1,:))./norm(C(2,:)-C(1,:));
k = -(NC(1)*C(1,1)+NC(2)*C(1,2)+NC(3)*C(1,3))/(NC(1)^2+NC(2)^2+NC(3)^2);
P = [0,0,0; NC(1)*k + C(1,1), NC(2)*k + C(1,2), NC(3)*k + C(1,3)];
C2 = [C(1,:) - 20*NC; C(1,:) + 20*NC];
P2 = [[0,0,0] - 20*P(2,:); [0,0,0] + 20*P(2,:)];
figure(10); plot3(C2(:,1), C2(:,2), C2(:,3), 'k', C(:,1), C(:,2), C(:,3), 'r', P2(:,1), P2(:,2), P2(:,3), 'k', P(:,1), P(:,2), P(:,3), 'b'); axis equal;
I think it works! Great. Thanks again.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Audio I/O and Waveform Generation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by