changing color of structure which defined as object

5 views (last 30 days)
user aluser
user aluser on 23 Mar 2021
Commented: user aluser on 24 Mar 2021
CUBE = platform(sc);
CUBE.Dimensions = struct('Length',5,'Width',5,'Height',5,'OriginOffset',[0 0 0]);
I created an object called CUBE, with the specified dimensions, and it is plotted while it is rotating, i need to change the color of its faces to recognize the rotation.
thanks
  1 Comment
Walter Roberson
Walter Roberson on 23 Mar 2021
This appears to refer to Sensor Fusion
Are you using plotPlatform() ? I have not yet found a plotPlatform() approach to plot faces, only markers.

Sign in to comment.

Accepted Answer

Greg Dionne
Greg Dionne on 24 Mar 2021
Edited: Greg Dionne on 24 Mar 2021
The platformPlotter is intended to plot (possibly multiple) objects at once with a unique color.
The orientationPlotter is intended for plotting the orientation of (possibly multiple) objects using the RED, GREEN, BLUE labeling convention for the orientation of the body's x-, y-, and z-axes, respectively. For a quick example of plotting just one orientation centered at the origin, try running:
% Example: Animate a smoothly interpolated rotation from
% from -30 degrees yaw, 20 degrees pitch, 10 degrees roll
% to 60 degrees yaw, 10 degrees pitch and 5 degrees roll.
% -------
% create the endpoints of the rotation.
e = deg2rad([-30 20 10; 60 10 5]);
% convert endpoints to a quaternion.
q = quaternion(e, 'euler', 'ZYX', 'frame');
% upsample with 100 points via spherical linear interpolation
qs = slerp(q(1), q(2), linspace(0,1,100)');
% create a theater plot
tp = theaterPlot('XLimit',[-2 2],'YLimit',[-2 2],'ZLimit',[-2 2]);
% add an orientation plotter to the theater plot
op = orientationPlotter(tp,'DisplayName','body axis');
% animate the changes in rotation
for i=1:numel(qs)
plotOrientation(op, qs(i));
drawnow;
end
You can place the origin of the body axes (denoted by the black dot) via the optional third argument to the plotOrientation method. That may be easier to see the orientations when multiple objects are plotted (since they may only occupy a few pixels each when you are looking at several objects that are very far apart from eachother.
The plotters should work just fine with other typical handle graphics commands should you need finer granularity of control. You can obtain the axes that an existing theaterPlot uses via its "Parent" property. Otherwise just create an axes as you normally would (via axes). I would use a combination of hgtransform, makehgtform, and patch to achieve your desired effect. If you want to see all of these operating simultaneously you can do something like:
sc = trackingScenario;
cube = platform(sc);
cube.Dimensions = struct('Length',5,'Width',5,'Height',5,'OriginOffset',[0 0 0]);
% create a theater plot
tp = theaterPlot('XLimit',[-10 10],'YLimit',[-10 10],'ZLimit',[-10 10]);
% add an orientation plotter to the theater plot
op = orientationPlotter(tp,'DisplayName','body axis');
% find the coordinates of each face
L = cube.Dimensions.Length;
W = cube.Dimensions.Width;
H = cube.Dimensions.Height;
offset = cube.Dimensions.OriginOffset;
% vertices ordered counterclockwise observed from the outside
% forward, right, down, backward, left, up
f = [ 1 1 1; 1 -1 1; 1 -1 -1; 1 1 -1] .* [L W H]/2 - offset;
r = [ 1 1 1; 1 1 -1;-1 1 -1;-1 1 1] .* [L W H]/2 - offset;
d = [ 1 1 1;-1 1 1;-1 -1 1; 1 -1 1] .* [L W H]/2 - offset;
b = [-1 1 1;-1 1 -1;-1 -1 -1;-1 -1 1] .* [L W H]/2 - offset;
l = [-1 -1 1;-1 -1 -1; 1 -1 -1; 1 -1 1] .* [L W H]/2 - offset;
u = [ 1 1 -1; 1 -1 -1;-1 -1 -1;-1 1 -1] .* [L W H]/2 - offset;
% create a transform object and make the patches
hTransform = hgtransform(tp.Parent);
patch(hTransform, f(:,1), f(:,2), f(:,3), 'red', 'FaceAlpha',.6);
patch(hTransform, l(:,1), l(:,2), l(:,3), 'yellow', 'FaceAlpha',.6);
patch(hTransform, u(:,1), u(:,2), u(:,3), 'cyan', 'FaceAlpha',.6);
patch(hTransform, b(:,1), b(:,2), b(:,3), 'magenta','FaceAlpha',.6);
patch(hTransform, r(:,1), r(:,2), r(:,3), 'green', 'FaceAlpha',.6);
patch(hTransform, d(:,1), d(:,2), d(:,3), 'blue', 'FaceAlpha',.6);
% create the endpoints of the rotation.
e = deg2rad([-30 20 10; 60 10 5]);
% convert endpoints to a quaternion.
q = quaternion(e, 'euler', 'ZYX', 'frame');
% upsample with 100 points via spherical linear interpolation
qs = slerp(q(1), q(2), linspace(0,1,100)');
% animate the changes in rotation
for i=1:numel(qs)
position = [0 0 0];
plotOrientation(op, qs(i), position);
% hgtransform uses 'point' convention
M = eye(4);
M(1:3,1:3) = rotmat(qs(i),'point');
hTransform.Matrix = makehgtform('translate',position)*M;
drawnow;
end
You can experiment with different values for "position".
Hope this helps!
  1 Comment
user aluser
user aluser on 24 Mar 2021
Thank you very much, It is very helpful.
I Appreciate your efforts and you explained it in a wonderful way.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by