From: ImageAnalyst on
On Mar 25, 6:47 pm, "pipa " <balwindersi...(a)gmail.com> wrote:
> Not sure but I think u can use convex hull to see if that is what u were looking for.
> Look into the documentation for help on convex hull.

-----------------------------------------------------------------------------------------------
pipa:
The convex hull won't do it, unless you're willing to potentially
ignore some of the points, which would happen for certain location
sets such as the example he gave.

Patrick Hull:
One way to do it Patrick (maybe you could call it the "Patrick Hull")
could be to find the centroid and reorder the points so that it's like
you're sweeping though all angles (0-360), like going around the
clock. That would order the points so that you'd never have to
"backtrack" and cross lines. Understand? But better would be to just
say what you want to do, since as you've learned, there can be many
solutions.
-ImageAnalyst
From: John D'Errico on
Walter Roberson <roberson(a)hushmail.com> wrote in message <hogpoh$nb3$1(a)canopus.cc.umanitoba.ca>...
> John D'Errico wrote:
> > "patrick hull" <pabaholic.nospam(a)yahoo.com> wrote in message
> > <hogn1n$5pt$1(a)fred.mathworks.com>...
> >> Given 'x' and 'y' data below, does anyone know how to connect the
> >> points without any lines crossing over, in other words create a single
> >> area? Polyarea often creates shapes with lines that cross-over each
> >> other.
> >>
> >> x=[ 1.4459
> >> 4.2018
> >> 0.7925
> >> 0.1146
> >> 2.9969
> >> 3.2423
> >> 1.4459]
> >>
> >> y=[ 2.4448
> >> 4.9663
> >> 2.5656
> >> 1.9146
> >> 2.7304
> >> 0.3700
> >> 2.4448]
>
> > It is impossible to solve, since only you know how
> > those points are connected.
>
> I _speculate_ that the points are joined in the order specified, possibly with
> closure back to the first point. And I _speculate_ that the original poster
> wants the outline of the union of the areas. For example, the pentagram,

If you were to speculate that, then you would be wrong.

Try plotting the points in the example posted by the OP.
They form a self-crossing polygon, if the order they
are given is used.

John
From: Walter Roberson on
John D'Errico wrote:
> Walter Roberson <roberson(a)hushmail.com> wrote in message

>> I _speculate_ that the points are joined in the order specified,
>> possibly with closure back to the first point. And I _speculate_ that
>> the original poster wants the outline of the union of the areas. For
>> example, the pentagram,

> If you were to speculate that, then you would be wrong.
>
> Try plotting the points in the example posted by the OP.
> They form a self-crossing polygon, if the order they
> are given is used.

I see no conflict between my speculation and the figure the points form.

If one did not know that the vectors were drawn in a crossing manner, and were
only looking at the resulting figure, then one would typically infer that
there was a specific vertex at the point at which the two apparent areas
touch. It would then be reasonable to ask for a program which converted the
self-crossing polygon into the non-self-crossing concave polygon that an
onlooker would visually infer, tracing along the apparent outside edges.
From: Bruno Luong on
> x=[ 1.4459
> 4.2018
> 0.7925
> 0.1146
> 2.9969
> 3.2423
> 1.4459]
>
> y=[ 2.4448
> 4.9663
> 2.5656
> 1.9146
> 2.7304
> 0.3700
> 2.4448]

Travelling salesman approach:

xy=[x y];
tsp_ga(xy) % available here http://www.mathworks.com/matlabcentral/fileexchange/13680

Bruno
From: patrick hull on
"patrick hull" <pabaholic.nospam(a)yahoo.com> wrote in message <hogn1n$5pt$1(a)fred.mathworks.com>...
> Given 'x' and 'y' data below, does anyone know how to connect the points without any lines crossing over, in other words create a single area? Polyarea often creates shapes with lines that cross-over each other.
>
> x=[ 1.4459
> 4.2018
> 0.7925
> 0.1146
> 2.9969
> 3.2423
> 1.4459]
>
> y=[ 2.4448
> 4.9663
> 2.5656
> 1.9146
> 2.7304
> 0.3700
> 2.4448]


Thanks for all the replie...

What do I want do? Ans: generate a "single" non-cross over area from a random set of xy points

I looked at the traveling salesman example, great work by the way!. This example does work for this application, though takes some time to converge. This is largely do to the pop size and needed generations to find a solution.

2 - How did I solve it? The "Patrick Hull" as ImageAnalyst so stated? Though it is his idea and the code could be cleaned up a lot. Basically I generated the random points, found the centroid, calculated the angle and finally reordered and plotted. An yes, to complete the shape I appended the xy point with the first one. Again, this string is NOT clean and I propose it be called teh 'ImageAnalyst' or suitable real name.


close all
clear all
n=100;
xy = rand(n,2)

%Centroid Calculation
xy_avg = [sum(xy(:,1)/n) sum(xy(:,2)/n)];
% Find angle between lines - Centroid to points
for j=1:n
b = xy_avg-xy(j,:);
a = [1 0];
abs_a = sqrt(dot(a,a));
abs_b = sqrt(dot(b,b));
theta(j) = acos( (dot(a,b)/(abs_a*abs_b)))*180/pi;

%Fixing any angles from points in 3rd and 4th quadrant
if b(1)<0 & b(2)<0 | b(1)>0 & b(2)<0
theta(j) = 360-theta(j);
end
end

% Order points according to ascending angle
[theta ix] = sort(theta);
for j=1:n
xy_new(j,:) = xy(ix(j),:);
end
%appending the first point to the end
xy_new(end+1,:) = xy_new(1,:);

% Plot Area
A = polyarea(xy_new(:,1),xy_new(:,2));
plot(xy_new(:,1),xy_new(:,2));
title(['Area = ' num2str(A)]); axis equal


Thanks for all the replies...

Patrick
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: need Source Code
Next: connection between Gui's