Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a program I'm writing that requires a line drawn in SVG to be rotatable, and I'm having trouble with the math behind that. If I were to have a line at the beginning that has a start point of (40, 40) and an endpoint of (40, 240), and I want to be able to rotate that line in increments of one degree without changing the length of the line, what math would I need to look into? I'm familiar with basic slope and y-intercept math, but I'm not sure how to predict the replots of the start and end points along a rotation.

share|cite|improve this question
Perhaps a little off topic, but doesn't SVG have operators for letting you rotate an object around a point? Also, you haven't specified which point you wish to rotate your line segment about. Finally, I think many beginning texts on computer graphics will include the necessary mathematics, which includes some very elementary linear algebra including rotation matrices. Sorry I can't be more specific. – Harald Hanche-Olsen May 10 '13 at 8:36
Unfortunately, the "transform" attribute doesn't work on lines. – Fibericon May 10 '13 at 9:01

The canonical approach is using a rotation matrix to rotate the two endpoints of the line segment. The Wolfram article I linked to describes rotation about the origin. If you wish to rotate about another point, you need to:

  1. Translate the points so that the rotation point is coincident with the origin
  2. Rotate the geometry
  3. Translate the rotation point back to it's original position.

This is handled typically using a 4x4 (or 4x3) matrix in computer graphics.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.