Вопрос

I have four points (x1, y1) ... (x4, y4) which describe four points in an image. They need not be in a cyclic order. I want to know the all the internal angels of the quadrilateral formed by joining these four points

so I need a function like

function [theta1, theta2, theta3, theta4] = find_angels_quadrilateral([x1,y1], [x2,y2], [x3,y3], [x4,y4])
   # Logic goes here
end 

I have tried atan2(y1-y2, x1-x2) four times and so on, but there is no guarantee that they are cyclic, so unable to proceed further.

More importantly any toolbox provides this functionality for me in MATLAB already?

Это было полезно?

Решение

A simple approach would be to compute first the convex hull of the points using convhull. It will return the points in a cyclic order (counterclockwise).

K = convhull([x1, x2, x3, x4], [y1, y2, y3, y4])

It will return something like that:

K =

     1
     3
     4
     2
     1

Meaning point [x1,y1] is the first, then comes [x3,y3], then [x4,y4] and so on (first point is duplicated at the end to close the hull, so you can ignore that).

After that you can compute the angles with no problems.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top