Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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|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

1 Answer 1

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|improve this answer

Your Answer

 
discard

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.