How can I calculate the length of the longest side of a rectangle and the slope of an imaginary rectangle parallel to the longest side of the first?
5 次查看(过去 30 天)
显示 更早的评论
I need a suggestion for this easy but confusing dilemma.
I have a rectangle formed by 4 points (x2,y1) (x1,y2) (x3,y4) (x4,y3). The maximum and minimum are respectively (x4,y4) and (x1,y1).
I need to create a script to obtain the length of the longest side of the rectangle and the slope of an imaginary rectangle parallel to the longest side of the rectangle.
The problem is not so easy taking into account that the rectangle could be in many different positions. I have an idea about the slope, using Pythagoras and the maximum and minimum values, but...the length...I'm stuck on that.
2 个评论
Sean de Wolski
2011-10-17
What have you tried thus far? Show us with code (by editing your question).
采纳的回答
the cyclist
2011-10-17
I don't understand the part about the slope, but there is an easy way to find the longest side. The distance between each pair of points is
>> dij = sqrt((xi-xj)^2+(yi-yj)^2);
Calculate this for all pairs. You should get three unique length values, corresponding to:
- short side
- long side
- diagonal
The middling value will be the long side of the rectangle.
(You might need to be careful about floating point inexactitudes.)
4 个评论
Sean de Wolski
2011-10-17
-use atand to calculate the angle in degrees
-use the second output of max/min to identify which vertex corresponds to max/min.
-use hypot() to calculate ddg
更多回答(1 个)
Image Analyst
2011-10-19
Sorry - I gave you a more extensive answer than the Cyclist but for some reason you (or someone) deleted your first posting of this. I gave you the slope, and told you how to find the various lengths. I'm not inclined to repeat my prior waste of time.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!