linasster
linasster

Reputation: 149

How to calculate x1, y1, x2, y2, x3, y3, x4, y4 for rectangle

I need to find the position of a rectangle on the image. Rectangle points positions are fallowing [X1, Y1, X2, Y2] [7608,1638,7663,1680] also I know Image Height: 4096 and Width: 8192 on which I need to plot the rectangle. The rectangle will be hosted in GeoServer as a WFS layer. However, to visualize the shape I need to calculate x1, y1, x2, y2, x3, y3, x4, y4, x5, y5 somethink like this [[7047,2451],[7021,2266],[6749,2231],[6777,2392],[7047,2451]] from above-given values. How can I do that? I know that x5 ,y5 will be the same as x1, y1 as it is a closing one.

I believe for many of you this is a very basic question but for me it is complicated.

Upvotes: 0

Views: 2193

Answers (1)

Rufus L
Rufus L

Reputation: 37020

If you have the points minX, maxX, minY, maxY, and if we're talking about a right-angled, level rectangle, then the four points would typically be:

(minX, minY)-► ■ ═════════════════ ■ ◄-(maxX, minY)
               ║                   ║
               ║                   ║
               ║                   ║  Height = maxY - minY
               ║                   ║
               ║                   ║
(minX, maxY)-► ■ ═════════════════ ■ ◄-(maxX, maxY) 

                Width = maxX - minX

This assumes that we're dealing with rectangles where (0, 0) is the top-left corner, which is typical in windowed applications. Adjust accordingly if GeoServer rectangles are laid out differently.

Upvotes: 3

Related Questions