Hi all
I'm trying to calculate the intersection between a line and an ellipsoid, and i would like to visualize it as well. What i have so far ist this:
syms x y z s
laenge = 3;
breite = 1;
hoehe = 1;
ellipsoid(0,0,0, laenge,breite,hoehe);
axis equal
xlabel('X-Achse')
ylabel('Y-Achse')
zlabel('Z-Achse')
hold on
% Parameterequation Ellipsoid
e1 = (x^2/laenge^2) + (y^2/breite^2) + (z^2/hoehe^2) == 1;
% Parameterequation Line
g2 = [x;y;z] == [4;0;0] + s.*[-1;0;0];
E = [e1;g2]
t = solve(E, x, y, z, s);
x = t.x
y = t.y
z = t.z
s = t.s
g3 = isolate(g2(1),s)
%snew = subs(x)
%s = [2;2];
%snew = subs(g2(1),s,[2;2])
So i'm able to calculate the intersection correctly, but now i'm not sure how to plot the vector, because i can't replace s in the equations for some reason.
Thanks in advance!

 채택된 답변

Star Strider
Star Strider 2024년 11월 27일
In your isolate call, s no longer exists as a variable. You can create ‘g3’ eartlier in the code (when it does exist), and then use ‘g3’ later. At the end of the code, all the variables have been solved for, so I am not sure what you want to do with ‘g3’ at that point.
syms x y z s
laenge = 3;
breite = 1;
hoehe = 1;
ellipsoid(0,0,0, laenge,breite,hoehe);
axis equal
xlabel('X-Achse')
ylabel('Y-Achse')
zlabel('Z-Achse')
hold on
% Parameterequation Ellipsoid
e1 = (x^2/laenge^2) + (y^2/breite^2) + (z^2/hoehe^2) == 1;
% Parameterequation Line
g2 = [x;y;z] == [4;0;0] + s.*[-1;0;0];
g3 = isolate(g2(1),s)
E = [e1;g2];
t = solve(E, x, y, z, s);
x = t.x
y = t.y
z = t.z
s = t.s
%snew = subs(x)
%s = [2;2];
%snew = subs(g2(1),s,[2;2])
With respect to plotting the vector, use the hold function and the fplot3 function.
.

댓글 수: 5

What i'm wondering is, if i don't include g3 in the solve function like this:
% Parameterequation Line
g2 = [x;y;z] == [4;0;0] + s.*[-1;0;0];
g3 = x1 == 4 - s;
E = [e1;g2];
t = solve(E, x, y, z, s);
s = 2;
g3
and define s with a value, why am i not getting a result (4-2 => g3=2) when i'm printing g3?
To substitute a numerical value for a symbolic variable, use "subs":
syms x y
y = x + 5;
x = 2;
y % does not work
subs(y,x) % works
You do.
It is simply not as straightforward as that. It requires creating ‘g3’ as a function of ‘s’ and then substituting and solving.
Example —
syms x y z s
laenge = 3;
breite = 1;
hoehe = 1;
ellipsoid(0,0,0, laenge,breite,hoehe);
axis equal
xlabel('X-Achse')
ylabel('Y-Achse')
zlabel('Z-Achse')
hold on
% Parameterequation Ellipsoid
e1 = (x^2/laenge^2) + (y^2/breite^2) + (z^2/hoehe^2) == 1;
% Parameterequation Line
g2 = [x;y;z] == [4;0;0] + s.*[-1;0;0];
g3(s) = isolate(g2(1),s)
E = [e1;g2];
t = solve(E, x, y, z, s);
x = t.x, char(x)
ans = '[3; -3]'
y = t.y, char(y)
ans = '[0; 0]'
z = t.z, char(z)
ans = '[0; 0]'
s = t.s, char(s)
ans = '[1; 7]'
%snew = subs(x)
%s = [2;2];
%snew = subs(g2(1),s,[2;2])
s = 2;
g3s = solve(g3(s)) % Substitute & Solve
char(g3s)
ans = '2'
EDIT —
Added the char calls because the symbolic output of submitted posts is still not showing.
.
Carsten
Carsten 2024년 11월 27일
Thanks alot for the explanation.
Star Strider
Star Strider 2024년 11월 27일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품

릴리스

R2024a

질문:

2024년 11월 27일

댓글:

2024년 11월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by