Clear Filters
Clear Filters

Move a 2D object and track its position through a gui

5 views (last 30 days)
Hey everyone, i was wondering, is there a way to move a 2D object and track its new position after you have plotted them using your mouse. I dont want to draw a rectangle over an image as in some other questions i saw. What i want is, lets say i have two 2D objects
h1 = rectangle('Position',[0.59,0.35,3.75,1.37],...
h2 = rectangle('Position',[1.59,5.35,2.75,4.37],...
and a function that calculates the distance from their centers, i want do be able to move the one or the other using my mouse and the distance to be updated while i move them.
In my case i use this method to create some rectangles
for i = 1:compnum
where compos is a matrix that stores the position of the rectangles and list is a matrix with the dimentions they have.
Finally i use this code to print the distance of the two components
for i=1:compnum
I thought it would be nice if i could merge all this into a single object and then be able to move it using my mouse.
Thanks in advance.
  1 Comment
Raldi on 10 Jul 2012
I tried some functions with the best so far being
compnum = 2;
compos = [1,1;4,3];
complist = [3,1;4,3];
point1 = [compos(1,1)+complist(1,1)/2,compos(1,2)+complist(1,2)/2];
point2 = [compos(2,1)+complist(2,1)/2,compos(2,2)+complist(2,2)/2];
D = twopointdist(point1,point2)
for i = 1:compnum
% h(i) = rectangle('Position',[compos(i,1),compos(i,2),complist(i,1),complist(i,2)],...
% 'Curvature',[0,0],...
% 'LineWidth',2,'LineStyle','-')
h(i) = impositionrect(gca, [compos(i,1),compos(i,2),complist(i,1),complist(i,2)]);
But still i need to merge the text and somehow find a way to re-compute and re-display the distance each time i move one of them.

Sign in to comment.

Answers (0)


Find more on Visual Exploration 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!