Lightroom / Camera Raw / DNG / XMP: What is the formula for converting crop coordinates when photo gets angled?

  • 1
  • Question
  • Updated 4 years ago
For example, lets say an un-rotated and un-flipped landscape photo has crop coordinates:

crs:CropTop=".3"
crs:CropLeft=".4"
crs:CropBottom=".8"
crs:CropRight=".9"
crs:CropAngle="0"

then one angles it by say 10 degrees. the coordinates change to:

crs:CropTop="0.36916"
crs:CropLeft="0.374965"
crs:CropBottom="0.73084"
crs:CropRight="0.925035"
crs:CropAngle="-10"

What is the formula one needs to apply to arrive at the new top, left, bottom, and right values based on the crop angle change? I assume it involves trigonometry, but so far it has eluded me?

Any mathematicians out there? Adobe??

Knowing this formula will allow me to solve a nagging problem with my XmpCrop plugin.

Thanks,
Rob
Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 379 Reply Likes

Posted 6 years ago

  • 1
Photo of Dorin Nicolaescu-Musteață

Dorin Nicolaescu-Musteață, Champion

  • 703 Posts
  • 38 Reply Likes
1) Convert from Cartesian to polar system,
2) apply a deltaθ of 10 deg to θ,
3) convert back to Cartesian.

http://en.wikipedia.org/wiki/Polar_co...
Photo of Dorin Nicolaescu-Musteață

Dorin Nicolaescu-Musteață, Champion

  • 703 Posts
  • 38 Reply Likes
Don't forget that the origin (0, 0) in crs is the upper left corner, while the origin during the transformation (i.e. user rotating the crop box) is the center of the crop box. So you must shift the corner coordinates before step 1) and back after step 3).
Photo of Steve Sprengel

Steve Sprengel, Champion

  • 2612 Posts
  • 333 Reply Likes
From: http://answers.yahoo.com/question/ind...

x' = x * Cos(theta) - y * Sin(theta) + a
y' = x * Sin(theta) + y * Cos(theta) + b

Where (a,b) is the center of the rotation.
Photo of Allan Olesen

Allan Olesen

  • 64 Posts
  • 6 Reply Likes
Rob, I sent you a complete example of such a calculation in email some months ago.

And I know it works, because I use it frequently to change the aspect ratio of crop areas in photos with a crop angle.
Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 378 Reply Likes
Conversation is being continued via private email.
Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 379 Reply Likes
XmpCrop seems to be working (with angled photos) now, but not finished testing.

A big thanks to Dorin and Steve. And a big thank you to Allan too, since he had already sent the formula to me embodied in an xls spreadsheet, which I was, at the time, unfortunately, too spreadsheet-illiterate to decipher.
Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 379 Reply Likes
This question is answered.