Thread Subject: Obtaining Coordinates From Screen

Subject: Obtaining Coordinates From Screen

From: Nicky

Date: 7 Feb, 2010 02:05:06

Message: 1 of 11


Dear all,

I am having troubles obtaining coordinates from the axis automatically and inserting them into a matrix. I have read that there are two functions that access the input of the screen? Namely ginput and datacursor.

Problem 1:
The problem is the following. For example. I have a 3D cube. The cube therefore has 8 known Points that have already been drawn in matlab's axis. I used datacursor in conjuction with wait for mouse input to select these known points. However the wait for mouse input requires a Press of its own and the datacursor also requires another press with the mouse but on the first press the code runs and thus leaving 0 in the array matrix and not the coordinate information.

Problem 2:
Assuming the first problem is solved. I would like to be able to select any point along the front surface of the cube. what if the shape is not a cube? what if it is sphere? how can we select points along this surface?

Comments
I do not know how to use ginput for xyz information. Maybe someone can enlighten me. I am assuming that data cursor cannot solve problem 2. Is this a limitation of matlab or is there any possiblity to program this. Regarding problem 1. I have managed to obtain the coordinates a different way by using its update text function but i was not successful in using them within the function of update.

Please any help would be great regarding retreaving coordinate information from input using mouse.

Nick

Subject: Obtaining Coordinates From Screen

From: Nicky

Date: 7 Feb, 2010 03:20:05

Message: 2 of 11


This may help.

l=figure;
x = [1 2 3 4 5];
y = [1 2 3 4 5];
z = [1 2 3 4 5];
plot3(x,y,z,'o')
 datacursormode on
 dcmObj = datacursormode(l);
loop = 1
while loop == 1

    waitforbuttonpress;
    point1 = getCursorInfo(dcmObj);
    x1 = point1.Position(1)
    y1 = point1.Position(2)
    z1 = point1.Position(3)
end

On encountering waitforbuttonpress. I press the mouse however it then continues the code and point1 = 0 because i have not yet selected the point as it does not let me. Is there another way instead of waitforbuttonpress. i have tried to preassign Point1 but it loses the information when it goes into waitforbuttonpress function.

Subject: Obtaining Coordinates From Screen

From: Nicky

Date: 7 Feb, 2010 03:28:03

Message: 3 of 11

following to this i have tried Pause(10) and this lets me select the point in time lol. Not an ideal way but it works.

Subject: Obtaining Coordinates From Screen

From: Praveen

Date: 7 Feb, 2010 07:19:09

Message: 4 of 11

On Feb 7, 8:28 am, "Nicky " <n...@mytrashmail.com> wrote:
> following to this i have tried Pause(10) and this lets me select the point in time lol. Not an ideal way but it works.

Try this utility:
http://www.mathworks.com/matlabcentral/fileexchange/13857

HTH,
Praveen

Subject: Obtaining Coordinates From Screen

From: Nicky

Date: 7 Feb, 2010 14:00:05

Message: 5 of 11


Hi,

That application doesn't return Z coordinate?

Subject: Obtaining Coordinates From Screen

From: Steven Lord

Date: 8 Feb, 2010 15:44:05

Message: 6 of 11


"Nicky " <nick@mytrashmail.com> wrote in message
news:hklbh5$pfb$1@fred.mathworks.com...
>
> This may help.
>
> l=figure;
> x = [1 2 3 4 5];
> y = [1 2 3 4 5];
> z = [1 2 3 4 5];
> plot3(x,y,z,'o')
> datacursormode on
> dcmObj = datacursormode(l);
> loop = 1
> while loop == 1
>
> waitforbuttonpress;
> point1 = getCursorInfo(dcmObj);
> x1 = point1.Position(1)
> y1 = point1.Position(2)
> z1 = point1.Position(3)
> end
>
> On encountering waitforbuttonpress. I press the mouse however it then
> continues the code and point1 = 0 because i have not yet selected the
> point as it does not let me. Is there another way instead of
> waitforbuttonpress. i have tried to preassign Point1 but it loses the
> information when it goes into waitforbuttonpress function.

From the looks of your application, you don't want to use a datacursor but
instead you want to use GINPUT.

But if your object is a 2-D representation of a 3-D object, when you click
on the screen the "point" on which you click may be the image of multiple
different points on the object. For example, take a transparent glass and
look at it from the side. Now "click" on a point on the glass. How is the
program supposed to know whether you intended to "click" on the side of the
glass closest to you or the point on the other side of the glass that makes
a straight line with your eye and the nearer intersection point?

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: Obtaining Coordinates From Screen

From: Jane

Date: 9 Feb, 2010 21:39:04

Message: 7 of 11


Hi,

Can you please explain how to use Ginput to obtain coordinates from the 2d screen and output them to a matrix. I have tried datacursor. I believe you are right regarding how the system knows which is the front and the back but when I tested it using surfaces it wont let me pick the back only what is visible, i think!! This is great help thanks.

Jane

Subject: Obtaining Coordinates From Screen

From: Jane

Date: 9 Feb, 2010 21:41:20

Message: 8 of 11


Hi,

Can you please explain how to use Ginput to obtain coordinates from the 2d screen and output them to a matrix. I have tried datacursor. I believe you are right regarding how the system knows which is the front and the back but when I tested it using surfaces it wont let me pick the back only what is visible, i think!! This is great help thanks.

Jane

Subject: Obtaining Coordinates From Screen

From: Jane

Date: 9 Feb, 2010 21:53:04

Message: 9 of 11


Sorry for the double post. I ask this because I have read the help regarding Ginput and it only talks about selecting specific points on the screen and not picking points which are already there???

Subject: Obtaining Coordinates From Screen

From: TideMan

Date: 9 Feb, 2010 22:13:23

Message: 10 of 11

On Feb 10, 10:53 am, "Jane " <J...@mytrashmail.com> wrote:
> Sorry for the double post. I ask this because I have read the help regarding Ginput and it only talks about selecting specific points on the screen and not picking points which are already there???

I reckon that what you're trying to do cannot be done.
plot3 does not produce a 3D plot, but the projection of the 3D plot
onto your 2D screen.
So when you try to use ginput, you are getting the projection, not the
actual data.

IMHO, your only hope is to plot your shape using contour or contourf.
Now, you have a 2D shape, so you can find the x,y position using
ginput and the corresponding z value by interpolation of the surface.

Subject: Obtaining Coordinates From Screen

From: Jane

Date: 9 Feb, 2010 23:01:08

Message: 11 of 11

Hi, I am not too such about your comment but I understand your meaning. Now lets define the problem slightly differently. You have a list of xyz coordinate information for many points. First you plot these points onto the screen.

Datacursor is a tool which can recieve these xyz coordinates back by selection and write them to the screen in an information box. Therefore it must be possible to write a program to retrieve this information but store the information in a matrix instead of writing it to an information box. I think i did however see a slight rounding in the coordinate information when clicking on the screen using this function. I am not sure if you can get it to display "format long g" etc.

It could be that the program written will snap to the closest point where clicked on the screen this would be great. And disable the back points. this can be done with the actual depth information even though it is displayed in 2D? I hope this is clear.
What I really want to know is if Ginput can be used to retrieve points on a screen as i think what is needed is the reverse of Ginput. There must be an internal function that accesses the screen. If someone can explain that function it could be used directly?

Thank you.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com