11 Replies Latest reply on Nov 24, 2010 1:34 PM by sstanleyau

# Coordinates of rotated rectangle

I have a rectangle that is rotated by a script.

When outputting the geometric bounds of the rectangle, I get the coordinates of the outside rectangle that is aligned horizontally.

How can I get the actual coordinates of the rotated rectangle?

• ###### 1. Re: Coordinates of rotated rectangle

Hey!

Hope that helps.

--

tomaxxi

http://indisnip.wordpress.com/

• ###### 2. Re: Coordinates of rotated rectangle

Thanks!

• ###### 3. Re: Coordinates of rotated rectangle

The best way to do this would theoretically be using resolve(), but I have yet to find a scripter who knows how to use it effectively...

One day when I am bored and have some free time, maybe I'll try to crack that nut...

Harbs

• ###### 4. Re: Coordinates of rotated rectangle

Actually, I need more than just the width and height of the object. I need the actual coordinates of all four corners.

Not sure how the linked scripts will help me there.

• ###### 5. Re: Coordinates of rotated rectangle

Check out PageItem.resolve(). (And if you figure out how to use it, come back and let the rest of us know!)

Actually, to find out what you want, resolve() should be pretty painless (just feed in the correct anchor points), but youll have to work out which CoordinateSpace you need...

Harbs

• ###### 6. Re: Coordinates of rotated rectangle

```var doc = app.activeDocument;

var foo = doc.rectangles[0].paths[0].pathPoints;

for (var i = 0; i < foo.length; i++) {
\$.writeln(foo[i].anchor);
}
```

• ###### 7. Re: Coordinates of rotated rectangle

That'll work, but how do you work out which is the correct path point?

The paths can start at any corner and run in either direction...

Harbs

• ###### 8. Re: Coordinates of rotated rectangle

It doesn't work for me.

It gives me the same x coordinate for sets of two points which is clearly not the case.

• ###### 9. Re: Coordinates of rotated rectangle

Here's a basic example of using resolve()

Note: This will only work if your object is (directly) on a page. Generalizing it to work whether it's on a page or a spread is very hard, and I don't have the time right now to break my head over this...

```var coord = getPointCoordinates(app.selection[0],AnchorPoint.TOP_LEFT_ANCHOR);
function getPointCoordinates(obj,anchorPoint){
var page = obj.parentPage;
return [oC[0][0]-pC[0][0],oC[0][1]-pC[0][1]];
}
```

HTH

Harbs

• ###### 10. Re: Coordinates of rotated rectangle

One more thing:

This returns the values in points, so make sure to take that into account...

Harbs

• ###### 11. Re: Coordinates of rotated rectangle

Get the entirePath of the first path should give you what you want.