nagymafla
nagymafla

Reputation: 267

Define bounding rectangle of an array of points

I have a set of points in an array. All points have x and y coordinates. How can I get the bounding rectangle of this set? The "rectangle" object should have properties like x, y, width, height. Any ideas?

Upvotes: 4

Views: 1007

Answers (2)

YXD
YXD

Reputation: 32521

Find max x in set, find min x in set. Find max y in set, find min y in set. There's your bounding rectangle...

Upvotes: 1

Adam Dymitruk
Adam Dymitruk

Reputation: 129782

Store the min and max of x and do the same to y. Now you have your rectangle.

Upvotes: 3

Related Questions