How to Plot a 4D polyhedron

19 views (last 30 days)
Gilad Shaul
Gilad Shaul on 14 Jan 2023
Edited: John D'Errico on 14 Jan 2023
Hi all,
I need to perform Interpolation Control to Vehicle Lane Keeping Algorithm. I am using the MPT toolbox.
The problem is when I try to plot the Polyhedron I get an error that say, "Error using ConvexSet/plot. Cannot plot sets in 4D and higher."
Any idea if how to continue from here?
If you have an idea that not include the MPT toolbox its good to.
Attach is the code
clc, close all
clear
%% Car Parameters
m=1573;
Iz=2873;
l1=1.58;
l2=1.1;
lh=7;
Ca1=80000;
Ca2=80000;
vx=25;
%% State Space model
A_22=-2*(Ca2+Ca1)/(m*vx);
A_23= 2*(Ca2+Ca1)/m;
A_24=-2*(Ca2*l2-Ca1*l1)/(m*vx);
A_42=-2*(Ca2*l2-Ca1*l1)/(Iz*vx);
A_43= 2*(Ca2*l2-Ca1*l1)/Iz;
A_44=-2*(-Ca2*((l2)^2)+Ca1*((l1)^2))/(Iz*vx);
B2=2*Ca2/m;
B4=2*Ca2*l2/Iz;
A=[0 1 0 0; 0 A_22 A_23 A_24; 0 0 0 1; 0 A_42 A_43 A_44];
B=[0; B2; 0; B4];
n=4; % state dimention
A1=[0 1 0 0; 0 A_22 A_23 A_24];
B1=[0; B2];
%% Weighting Matrices
q11=1;
q12=0;
q21=0;
q22=0;
%q33=0;
Q=diag([q11,q12,q21,q22]);
R=1;
%% Computing P and K
[P,K] = icare(A,B,Q,R);
%% Constrains
sys = LTISystem('A', A, 'B', B);
Unrecognized function or variable 'LTISystem'.
Fx = [eye(4) ;-eye(4)]
gx = [5 0.5 pi/9 pi/20 5 0.5 pi/9 pi/20]'
Fu = [1 ;-1]
gu = [pi/4 pi/4]'
Fc = [Fx; Fu*K]
gc = [gx; gu]
C=Polyhedron('A', Fc, 'b', gc);
sys.x.with('setConstraint');
sys.x.setConstraint = C;
Omega = sys.invariantSet()
Omega.plot
X=Polyhedron('A', Fx, 'b', gx)
U=Polyhedron('A', Fu, 'b', gu)

Answers (1)

John D'Errico
John D'Errico on 14 Jan 2023
Edited: John D'Errico on 14 Jan 2023
Do you have a 4-dimensional hypermonitor? Perhaps you use a holodeck to do your plots? Oh, wait, you cannot get things like that until at least the 25th century. And Starfleet command is very poor at shipping from 500 years in the future. (And just try to get parts!) I've heard the Borg will handle the shipping, but do you really desperately want the Borg showing up at your doorstep?
Seriously, a plot is a 2-dimensional thing. Essentially, you plot x versus y. In the 3-d case, MATLAB projects what would be shown into the 2-d plane of the figure. Your mind is then able to interpret what it sees as a 3-dimensional thing, but often that visualization needs you to rotate the object around. All of this works because your brain is wired to understand 3-dimensions. Great!
Of course, if you have ever seen an MC Escher print, you will see that even something that is supposed to be 3-dimensional, when viewed in 2-d can be problematic.
But now you want to plot in 4-d. SORRY. Our brains don't really understand 4-d at all well. We are just not wired to interpret things like that. And if you tried to project a 4-dimensional object into the plane of your monitor, all you get is a mess. (Do I need to do that? UGH.)
xyzw = dec2bin(0:15) - '0';
T = orth(rand(4,2)); % a random projection into a plane from 4-d
uv = xyzw*T;
e = 0:7; edges = [e;e + 8];
e = 0:2:15; edges = [edges,[e;e + 1]];
e = [0:3,8:11]; edges = [edges,[e;e + 4]];
e = [0 1,4 5,8 9,12 13]; edges = [edges,[e;e + 2]];
plot(uv(1 + edges,1),uv(1+edges,2),'-')
I think I got that right, but as I look at it, I think I may have plotted too many edges. Anyway, can you interpret that mess as a 4-d hypercube, then projected into a plane?

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!