I need to draw a line on a globe from an anchor point to another point derfined by the cursor location. As I move the cursor to a new point I need to erase the first line and draw a new one. How do I use animated line to do this?

1 view (last 30 days)
if true
% code
end
% This used to work
% Erase old line if it exists
if (~isempty(linex));
line(linex, liney, 'Color','black', 'Erasemode','xor');
end
[linex, liney] = gcarc(lat, long, distance.lat, distance.long); % great circle arc line to be drawn

Accepted Answer

Mike Garrity
Mike Garrity on 28 Jul 2015
I'm not sure what gcarc is or what the context is, but I'm assuming that you're inside a loop here. If so, you'd want something like this:
h = animatedline;
for ...
if true
% code
end
[linex, liney] = gcarc(lat,long, ...);
addpoints(h,linex(end),liney(end))
drawnow
end
What's going on here is that you create the animatedline object once. You usually do it as I showed, outside your loop, but you could do it inside the loop if you're careful to only do it the first time.
In your loop, you just call addpoints. Note that you only need to give it the newest point. It remembers all of the ones you have already given it. This will probably let you simplify your code substantially. Also note that you don't need to worry about undrawing the previous line. The animatedline object will take care of everything for you.
You also need to call drawnow. The animatedline object doesn't do that for you because you might want to control how the drawnow is done. For example, if you had multiple animatedline objects, you might want to call addpoints on each of them and then do one call to drawnow. Also, you might want to consider using "drawnow limitrate" for the reasons I discussed in this post .

More Answers (1)

rikshapiro
rikshapiro on 13 Aug 2015
This works when you addpoints, then clearpoints followed by addpoints when you move the cursor. Draws a moving line from a fixed geographic location on a map showing bearing from the fixed point to the cursor location.

Categories

Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!