5 Replies Latest reply on Mar 25, 2014 10:06 PM by Marc Autret

# create rectangle proportionally

Hi Forum,

Any help would be much appreciated.

I would like to create a rectangle proportionally in width and height, starting from the Graphic Line.

The Height of the graphic Line would be PageHeight/2. and width would be PageWidth.

Please see the attached snapshot. After fixing the graphic Line to PageHeight/2 in height and width to page width, I want to draw a rectangle,,
which should be proportionally, equally in size both widht and height - touch the graphic Line till the page width and height.

thanks a tonne to helping on this.

• ###### 1. Re: create rectangle proportionally

Hi,

use resize() method like this:

```mRectangle.resize(
CoordinateSpaces.INNER_COORDINATES,
AnchorPoint.BOTTOM_RIGHT_ANCHOR,
ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY,
[wFactor, hFactor]);
```

where wFactor and hFactor are calculated regarding to page resize

Jarek

• ###### 2. Re: create rectangle proportionally

HI Jarek,

Thanks for immediate stepin and suggestion.

But the thing is, the rectangle proportionate is not same. whenever the page width and height is changed the proportionate changes.

Thanks so much Jarek for the support.

• ###### 3. Re: create rectangle proportionally

How is your math? http://en.wikipedia.org/wiki/Line-line_intersection tells you all you need to know (Or, it does after logically figuring out your construction.)

```with (app.layoutWindows[0].activePage)
x1 = Math.min(bounds[1],bounds[3]),
y1 = Math.max(bounds[0],bounds[2]),
x2 = Math.max(bounds[1],bounds[3]),
y2 = .5*(bounds[0]+bounds[2]),
x3 = x2,
y3 = Math.max(bounds[0],bounds[2]),
x4 = x3-1,
y4 = y3-1;
px = ((x1*y2-y1*x2)*(x3-x4)-(x1-x2)*(x3*y4-y3*x4))/((x1-x2)*(y3-y4)-(y1-y2)*(x3-x4));
py = ((x1*y2-y1*x2)*(y3-y4)-(y1-y2)*(x3*y4-y3*x4))/((x1-x2)*(y3-y4)-(y1-y2)*(x3-x4));
```
• ###### 4. Re: create rectangle proportionally

Hi,

It changed, right, but by same factor as pages, I guess.

Check this with below code:

```var
changedPageSize = [130,170],
lastPage = app.activeDocument.pages[-1],
currentPageSize = [
lastPage.bounds[3] - lastPage.bounds[1],
lastPage.bounds[2] - lastPage.bounds[0]
],
k,
wFactor = changedPageSize[0]/currentPageSize[0],
hFactor = changedPageSize[1]/currentPageSize[1],
mPage = lastPage.duplicate(),
mItems = mPage.pageItems.everyItem().getElements();

mPage.resize(
CoordinateSpaces.INNER_COORDINATES,
AnchorPoint.BOTTOM_RIGHT_ANCHOR,
ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY,
[wFactor, hFactor]);

for (k = 0; k < mItems.length; k++)
mItems[k].resize(
CoordinateSpaces.INNER_COORDINATES,
AnchorPoint.BOTTOM_RIGHT_ANCHOR,
ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY,
[wFactor, hFactor]);
```

Place your shapes at the last page and set new size in 1st line.

Compare it with new last page added by the code.

Jarek

• ###### 5. Re: create rectangle proportionally

Hi people,

Unique wrote:

After fixing the graphic Line to PageHeight/2 in height and width to page width, I want to draw a rectangle,,

which should be proportionally, equally in size both widht and height - touch the graphic Line till the page width and height.

I'm afraid I didn't clearly understand the question but, according to your screenshots you seem to just want to draw a square (?) below the GraphicLine—with respect to size constraints.

Let W denotes the page width, H the half of the page height, and x the square edge.

The Intercept theorem (Thales) leads to x = ( W × H ) / ( W + H ).

From then you could easily create this shape at the bottom right corner. Here is a raw implementation (assuming uniform measurement units and no weird transformations applied):

```var pg = app.layoutWindows[0].activePage,
bs = pg.bounds,
w = (bs[3]-bs[1]),      // page width
h = (bs[2]-bs[0])/2,    // half of the page height
x = (w*h)/(w+h);

bs[0]=bs[2]-x;
bs[1]=bs[3]-x;