Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Rotate markers in plot

788 views
Skip to first unread message

William Slater

unread,
Oct 14, 2008, 6:00:20 PM10/14/08
to
Hey all:

Here's what I'm doing this time. I'm plotting the bird's-eye view of an aircraft's flight path, where the latitude and longitude are given as time vectors. I have a slider at the bottom of the figure that will let the user pick a point of time in the flight path. After picking this point, the figure will superimpose a marker, indicating where the plane is at the selected time.

I've got all the logic written to take care of the plotting. As an added feature, I would like to be able to rotate the marker (a triangle in this case) to reflect the heading of the plane. Does anyone know of a way to accomplish this?

Additionally, is there a way to define custom marker shapes?

TIA:
Will Slater

Scott Burnside

unread,
Oct 14, 2008, 6:31:02 PM10/14/08
to
"William Slater" <William....@LMCO.com> wrote in message <gd34pk$csg$1...@fred.mathworks.com>...

Example of rotation of triangular patch:

function rotate_triangle()
axes('units','normalized',...
'position',[0.1 0.1 0.8 0.8],...
'color',[0.5 0.5 0.5],...
'NextPlot','replacechildren',...
'tag','plot_axes');
hp = plot([1 3 2 1],[2 4 1 2]);
set(hp,'tag','tplot');
xlim([-8 8]);
ylim([-8 8]);
% define rotation button
uicontrol('units','normalized',...
'position', [0.42 .925 .15 .05],...
'style','push',...
'SelectionHighlight','off',...
'string','rotate',...
'fontweight','bold',...
'fontsize', 10,...
'fontname','arial',...
'foregroundcolor',[0 0 0],...
'callback',{@rotate_button},...
'tag','rotate_button');

function rotate_button(hload,eventdata)
% locate and delete the main figure object
ax = findobj('tag','plot_axes');
hp = findobj('tag','tplot');
hb = findobj('tag','rotate_button');
stop_flag = get(hp,'userdata');
if ~isempty(stop_flag)
if stop_flag == 0
set(hp,'userdata',1)
set(hb,'string','rotate');
elseif stop_flag == 1
set(hp,'userdata',0);
set(hb,'string','stop');
end
else
set(hp,'userdata',0)
set(hb,'string','stop');
end
t = hgtransform('Parent',ax);
set(hp,'Parent',t)
Rz = eye(4);
for r = 0:.1:2000*pi
Rz = makehgtform('zrotate',r);
set(t,'Matrix',Rz)
drawnow
pause(0.01)
stop_flag = get(hp,'userdata');
if stop_flag == 1
break
end
end
return
% end of code

hth,
Scott

Scott Burnside

unread,
Oct 14, 2008, 9:13:02 PM10/14/08
to
"Scott Burnside" <n...@spam.com> wrote in message <gd36j6$qsr$1...@fred.mathworks.com>...

Oh, its not actually a patch (just some lines) but you get the idea.

scott

William Slater

unread,
Oct 14, 2008, 9:16:01 PM10/14/08
to
"Scott Burnside" <n...@spam.com> wrote in message
> Example of rotation of triangular patch:
>
> function rotate_triangle()
>
>
> hth,
> Scott

Thanks, but this is not quite what I'm looking for. For any point in time, I can get the lat/lon of the aircraft, as well as its heading. I want to invoke a plot command on these coordinates and then rotate the marker made by the plot command. As such:

lat = 14.3948; % These three data points
lon = 160.3909; % are extracted previously
heading = 34.6543; % from data file
x = plot(axes_handle, lon, lat, 'LineStyle', 'none', ...
'Marker', '^', 'MarkerSize', 16)
Rotate_Marker(x, heading);

Where 'Rotate_Marker(x, heading)' is the code I'm seeking.

Walter Roberson

unread,
Oct 15, 2008, 12:16:06 AM10/15/08
to
William Slater wrote:
>I want to invoke a plot command on these coordinates and then rotate the marker made by
>the plot command.

That is not possible in Matlab (unless perhaps you can do it by hacking
at the java level.)

plot() always produces objects of class 'lineseries',
and markers for 'lineseries' objects (and 'line' objects) are always drawn
completely automatically. A marker for a line or lineseries object has
no independent existence in Matlab such that you could potentially grab it
and rotate it.

What you need to do is create some vertex lists that have the shape of the
marker; easiest is to do so with (0,0) as their center, When you plot(), tell plot()
to use no marker at all. Then at each (x,y) or (x,y,z) coordinate for the plot,
calculate a rotated (and scaled) version of the vertex lists, and patch() that
vertex list into existance (after adding (x,y,z) to each coordinate to get
it centered over (x,y,z))

I suggested above using patch(): you should do that if you want filled
markers. If you want unfilled markers, you have the option of using
line() instead to draw the shape into place.

There will, though, be an essential difference between "drawing the marker
yourself" and using the automatic markers supplied Matlab line or lineseries
objects: if you zoom an area containing an automatic marker, then the marker
will be drawn with the same -absolute- size in the zoomed region; if you
zoom in to an area containing a marker that you drew as a patch() or line(),
then the marker will be zoomed as well. In order to avoid this, you need
to use zoom pre and/or post callbacks, to remove the zoomed markers from
the display window and to draw them back with the preferred absolute size.

0 new messages