Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
check if a point is on the curve

Subject: check if a point is on the curve

From: Konst

Date: 8 Oct, 2010 17:59:05

Message: 1 of 9

I have x,y vectors and i plot them.Then using ginput i pick two random points of the curve.How can I check if these points are on the curve and if I didn't accidentally clicked somewhere outside the graph?

Subject: check if a point is on the curve

From: someone

Date: 8 Oct, 2010 18:30:07

Message: 2 of 9

"Konst " <konstance1@hotmail.com> wrote in message <i8nm59$ft2$1@fred.mathworks.com>...
> I have x,y vectors and i plot them.Then using ginput i pick two random points of the curve.
If you really "pick two random points of the curve" then,
by definition, the points MUST be on the curve. Right?
So, how do you pick the points?

How can I check if these points are on the curve and if I didn't accidentally clicked somewhere outside the graph?

I'm not sure about using ginput for this task.
Do you really need to do it this way?
I would test each click individually.

I would use gcbo and test if the returned
handle's Type is a line object.

doc gcbo
doc get
doc line % (and look the "Type" property for line objects)

Subject: check if a point is on the curve

From: Konst

Date: 8 Oct, 2010 21:13:04

Message: 3 of 9

Yes I really have to use ginput.I tried gcbo but I don't get what I want so any other ideas would be really nice!!

Subject: check if a point is on the curve

From: Konst

Date: 9 Oct, 2010 13:46:03

Message: 4 of 9

Ok more details might help..I have ginput in a loop and I want the loop to break if the point I selected with ginput is not on the curve.So if I want to break the loop at any time I can click anywhere beside the curve..Please anyone...I've tried almost everything..

Subject: check if a point is on the curve

From: Godzilla

Date: 10 Oct, 2010 02:10:04

Message: 5 of 9

"Konst " <konstance1@hotmail.com> wrote in message <i8prmr$h52$1@fred.mathworks.com>...
> Ok more details might help..I have ginput in a loop and I want the loop to break if the point I selected with ginput is not on the curve.So if I want to break the loop at any time I can click anywhere beside the curve..Please anyone...I've tried almost everything..

I would increase the density of the plotted point using interpolation. When I pick the point, I would then use the x coordinate in the interpolation to compute the y value. I would then check to see if this y value is within a tolerance such that it could be considered 'on' the curve.

Subject: check if a point is on the curve

From: someone

Date: 10 Oct, 2010 04:02:03

Message: 6 of 9

"Konst " <konstance1@hotmail.com> wrote in message <i8o1h0$cqr$1@fred.mathworks.com>...
> Yes I really have to use ginput.I tried gcbo but I don't get what I want so any other ideas would be really nice!!

% Sorry, I meant gco NOT gcbo.
% Try this:

plot(1:3,1:3)

% Now, click on the line and the result of:
get(gco,'Type')
% will be:
ans =

line

% Click somewhere else on the plot, and the result of:
get(gco,'Type')
% will be:
ans =

axes

% So

TF = strcmp(get(gco,'Type'),'line');

% TF will be 1 if you clicked on the line
% and 0 if you clicked somewhere else.

Subject: check if a point is on the curve

From: Konst

Date: 10 Oct, 2010 10:34:05

Message: 7 of 9

Thank you both very much.I'll try it and let you know

Subject: check if a point is on the curve

From: Konst

Date: 10 Oct, 2010 10:55:04

Message: 8 of 9

gco works just fine!!Thank you very much!!!

Subject: check if a point is on the curve

From: John D'Errico

Date: 10 Oct, 2010 12:11:03

Message: 9 of 9

"Konst " <konstance1@hotmail.com> wrote in message <i8nm59$ft2$1@fred.mathworks.com>...
> I have x,y vectors and i plot them.Then using ginput i pick two random points of the curve.How can I check if these points are on the curve and if I didn't accidentally clicked somewhere outside the graph?

I would add that this recent submission will tell you if the
point is actually on the curve itself, computing a general
Euclidean distance to a curve that may not have a true
functional form.

http://www.mathworks.com/matlabcentral/fileexchange/28797-find-the-closest-point-on-a-curvilinear-arc

John

Tags for this Thread

No tags are associated with this thread.

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.

Contact us