Plot a quadrilateral having 8 points (each side passes through two points)

I have 8 points and need to plot a quadrilateral using those. Each side of it passes through two of these points, which are defined. How can I plot such a shape?

4 件のコメント

KSSV
KSSV 2023 年 4 月 18 日
USe plot. Or show us your data.
DGM
DGM 2023 年 4 月 18 日
If you have 8 points, and four edges intersecting exactly two points each, that implies that none of the points lie on a vertex of the quadrilateral. This also suggests that there is either no unique solution:
Or there may be no solution.
So what are the constraints on the point locations? If solutions exist, which one is chosen?
Mohammad Javad Asgari Pirbalouti
Mohammad Javad Asgari Pirbalouti 2023 年 4 月 18 日
編集済み: Mohammad Javad Asgari Pirbalouti 2023 年 4 月 18 日
@DGM Thanks for the comment, these are not random points. These ment to show the deviation of a known square, so the order of connceting the dots is defined in a way that maches the refernce square. I was looking for an easier solution rather than solving 4 equations for 8 squares to plot it with matlab:-/.
John D'Errico
John D'Errico 2023 年 4 月 19 日
I will guess (from the vague things you have said) that you have 8 points, so pairs of two points define one side of the quadrilateral. But the points are no on a vertex. So you are hoping to find where the lines INTERSECT, and that defines the quadrilaterl? This is just a complete guess from what you have said. But you did mention having to solve equations, and that is the only thing that makes sense.

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

 採用された回答

x = [10.0001 10 30 70 90 90.1 30 70];
y = [-45 -65 -25 -25.1 -45 -65 -105 -105.1];
[cornerX, cornerY] = cornerFinder(x,y);
plot(cornerX,cornerY,'r', 'LineWidth',2)
function [cornerX, cornerY] = cornerFinder(x,y)
% Pre-allocate memory for a and b arrays
a = zeros(1,4);
b = zeros(1,4);
% Compute slopes and y-intercepts using array indexing
for i = 1:2:8
j = (i+1)/2;
a(j) = (y(i+1)-y(i))/(x(i+1)-x(i));
b(j) = y(i)-a(j)*x(i);
end
% Pre-allocate memory for cornerX and cornerY arrays
cornerX = zeros(1,4);
cornerY = zeros(1,4);
syms xx yy
% Compute corner points using array indexing
for i = 1:4
if i == 4
j = 1;
else
j = i+1;
end
sol = solve(a(i)*xx + b(i) - yy, a(j)*xx + b(j) - yy);
cornerX(i) = double(sol.xx);
cornerY(i) = double(sol.yy);
end
% Append the first corner point to the end of arrays
cornerX = [cornerX, cornerX(1)];
cornerY = [cornerY, cornerY(1)];
end

その他の回答 (1 件)

Torsten
Torsten 2023 年 4 月 18 日
編集済み: Torsten 2023 年 4 月 19 日
P1 = [0 0 0];
P2 = [1 0 0];
P3 = [0 1 0];
P4 = [0 0 1];
P5 = [1 1 0];
P6 = [0 1 1];
P7 = [1 0 1];
P8 = [1 1 1];
hold on
plot3([P1(1),P2(1)],[P1(2),P2(2)],[P1(3),P2(3)],'b')
plot3([P1(1),P3(1)],[P1(2),P3(2)],[P1(3),P3(3)],'b')
plot3([P1(1),P4(1)],[P1(2),P4(2)],[P1(3),P4(3)],'b')
plot3([P2(1),P5(1)],[P2(2),P5(2)],[P2(3),P5(3)],'b')
plot3([P2(1),P7(1)],[P2(2),P7(2)],[P2(3),P7(3)],'b')
plot3([P3(1),P5(1)],[P3(2),P5(2)],[P3(3),P5(3)],'b')
plot3([P3(1),P6(1)],[P3(2),P6(2)],[P3(3),P6(3)],'b')
plot3([P4(1),P6(1)],[P4(2),P6(2)],[P4(3),P6(3)],'b')
plot3([P4(1),P7(1)],[P4(2),P7(2)],[P4(3),P7(3)],'b')
plot3([P5(1),P8(1)],[P5(2),P8(2)],[P5(3),P8(3)],'b')
plot3([P6(1),P8(1)],[P6(2),P8(2)],[P6(3),P8(3)],'b')
plot3([P7(1),P8(1)],[P7(2),P8(2)],[P7(3),P8(3)],'b')
hold off
view([45 45])
If your quadrilateral is 2d, use "plot" instead of "plot3" in a similar way.

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by