X,Y Coordinate value after rotation

I'm placing some text via PHP, C#, and VB applications onto a PDF.  The text position is based on a X,Y matrix with the lower left of the page being 0,0.

What I'm trying to calculate is where the end of the text string is when it is rotated, so I can add more text to it.

I do know the following works, but I need a formula to calculate all angles/rotations.

If the rotation is 0 degrees:
X = X + "width of string"
Y = Y

If the rotation is 90 degrees:
X = X
Y = Y + "width of string"

If the rotation is 180 degrees:
X = X - "width of string"
Y = Y

If the rotation is 270 degrees:
X = X
Y = Y - "width of string"
LVL 14
Who is Participating?
ozoConnect With a Mentor Commented:
If r is in degrees, and your sin and cos functions are in radians, then rotation=r*pi/180
CtrlAltDlAuthor Commented:
By the way, rotation is counter-clockwise and at zero degrees text is left to right.
X = X + cos(rotation)*"width of string"
Y = Y + sin(rotation)*"width of string"
CtrlAltDlAuthor Commented:
That isn't working for me.

Let's say:
X = 1
Y = 2
intStrWidth = 4  (this is my width of string)
r = 0 (this is rotation)

You formula comes out correct if r=0, but if it is anything else it isn't working.

If r = 90 your formula returns:
X = -0.79
Y = 5.57
but it should return:
X = 1
Y = 6

Anymore thoughts?
CtrlAltDlAuthor Commented:
That works!  I spent half the day trying to figure that out and I wasn't even close.  Thanks!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.