Why polyxpoly does not work?

16 ビュー (過去 30 日間)
Faez Alkadi
Faez Alkadi 2018 年 1 月 29 日
コメント済み: Faez Alkadi 2018 年 4 月 27 日
I have the data points for tow polylines as attached. Where A1 is X-data for polyline 1, B1 is Y-data for polyline 1 and,A2 is X-data for polyline 2 and B1 is Y-data for polyline 2. (as plotted)
I tried to get the intersection point between the two polylines using polyxpoly. But the the result for [xi, yi] are empty !!!
Does anyone has an idea what would be the problem ? Thank you so much...
[xi, yi] = polyxpoly(A1, B1,A2, B2);
plot(A1,B1)
hold on
plot(A2,B2)
hold on
plot(xi, yi, 'bo')
  3 件のコメント
Faez Alkadi
Faez Alkadi 2018 年 1 月 30 日
編集済み: Faez Alkadi 2018 年 1 月 30 日
I used the function intersections by Douglas Schwarz for the same exact data and it worked perfect. But its a little slow!!!!
That's why i prefer polyxpoly
Matt J
Matt J 2018 年 4 月 24 日
編集済み: Matt J 2018 年 4 月 24 日

I used the function intersections by Douglas Schwarz for the same exact data and it worked perfect. But its a little slow!!!!

I imagine speed performance of any tool would vastly improve once you get rid of the non-vertex points in your A,B data.

サインインしてコメントする。

採用された回答

Matt J
Matt J 2018 年 4 月 24 日
編集済み: Matt J 2018 年 4 月 24 日
I suspect the problem has to do with the fact that you are entering superfluous additional points, which are not actually vertices. A vertex technically should lie only at the end points of the polygon edges.
Regardless, the attached version of polyxpoly by Bruno Luong is working fine for me, but has a different syntax.
>> ab = polyxpoly([A1, B1].',[A2, B2].')
ab =
-5.1172
-5.5302
  1 件のコメント
Faez Alkadi
Faez Alkadi 2018 年 4 月 27 日
Thank you Matt

サインインしてコメントする。

その他の回答 (1 件)

Steven Lord
Steven Lord 2018 年 4 月 24 日
If you're using release R2017b or later, consider creating polyshape objects and using the intersect function on those objects.
% Load data
D = load('A1', 'A1'); A1 = D.A1;
D = load('A2', 'A2'); A2 = D.A2;
D = load('B2', 'B2'); B2 = D.B2;
D = load('B1', 'B1'); B1 = D.B1;
% Create two polyshape objects
P1 = polyshape(A1, B1, 'Simplify', true);
P2 = polyshape(A2, B2, 'Simplify', true);
% Plot the two polyshape objects so later we can check that the intersection is correct
h1 = plot([P1, P2]);
ax1 = ancestor(h1(1), 'axes');
% Determine the intersection of the two polyshape objects
C = intersect(P1, P2);
% Plot the intersection
figure;
h2 = plot(C);
ax2 = ancestor(h2, 'axes');
% Make the two axes have the same limits for easy comparison
axis(ax2, axis(ax1));
If you flip back and forth between the two figures, you can see that the polyshape C plotted on the second figure is exactly the intersection between the two polyshape objects P1 and P2. If you want coordinates, use the Vertices property.
C.Vertices
If you want to determine if an arbitrary point is inside the intersection, use isinterior.
  1 件のコメント
Faez Alkadi
Faez Alkadi 2018 年 4 月 27 日
Hi Steven, Thank you for stepping in. the thing is this, this will not help with my application.
Thank you

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeElementary Polygons についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by