for a really long time, i tried to get a program that did rotation to work and found this difficult as nearly all of the info provided on the subject assume knowledge of matrices. thus, here are the formulas for rotation in simple algebra in cartesian coordinate space:

x axis:
y' = y * cos(a) - z * sin(a)
z' = z * cos(a) + y * sin(a)

y axis:
z' = z * cos(a) - x * sin(a)
x' = x * cos(a) + z * sin(a)

z axis:
x' = x * cos(a) - y * sin(a)
y' = y * cos(a) + x * sin(a)

remember that if you are using these formulas as part of a programming exercise, z' is NOT the same as z so if you say something like:

z' = z * cos(a) - x * sin(a)
x' = x * cos(a) + z' * sin(a)

you will wind up with really wacked out results.

Here is another method for achieving a rotational effect, based on having only distances, not angles:

                 ,.onOK|||||HQme., (x,y) 
            ,.szF'``           ``'Tux.,
    (u,v) ,z'``       ____,..---*''/``'c,
        ,x'`_,..---*'`            /    `'w,
      .u'\,            d         /       `'n.
     dy`  `\,                   /          `qb
    /7      `\,                /             VA
   4y         `\,             /               KD,
  ,I'           `\,          /                `VA
  dp              `\,       /                  qb
 ,j'                `\,    /                   `t,
 AV                   `\, /          r          VA
 69                      O----------------------96
 VA                    (w,z)                    AV
 `t,                                           ,j'
  qb                                           dp
  `I,                                         ,U'
   \D                                         4y'
    VA                                       /7'
     qb,                                   ,dy
      `'n.                               .u'`
        `'w,                           ,x'`
          `'c,,                     ,,z'`
            `'Tux.,,           ,,.szF'`
                 `'TTOKQQQQQH@TT'`

From the above points, let (x,y) be the starting point, (w,z) the center of rotation, and d the distance to the new point. In other words, the rotation is counterclockwise from (x,y) to a point d in distance from (x,y) about (w,z).

Let r be the distance from (x,y) to (w,z) (i.e., the radius of rotation) and define c=sqrt(r2-(d/2)2) (a helpful constant). Since r is a distance, r=sqrt((x-w)2+(y-z)2).

From this we get:

u = w+((x-w)⋅(c2-(d/2)2)-(y-z)⋅d⋅c)/r2
v = z+((y-z)⋅(c2-(d/2)2)+(x-w)⋅d⋅c)/r2

Thanks to jrn for noticing that supplying a negative number for d will cause a clockwise rotation.


Below is my LISP code to achieve such a rotation. Note that the rotation function will return nil if abs(d) is more than twice as big as the distance from the starting point to the center of rotation (i.e., c is not a real number).

(defun distance (p1 p2)
  "Takes two points and finds the distance between them."
  (when (and (consp p1)
             (consp p2)
             (> (length p1) 1)
             (> (length p2) 1)
             (every 'numberp p1)
             (every 'numberp p2))
    (sqrt (+ (expt (- (first p1) (first p2)) 2)
             (expt (- (second p1) (second p2)) 2)))))

(defun distance-rotate (p c d)
  "Takes a point p, a center of rotation c, and a distance d.
Rotates counter-clockwise about c to a point d away from p.
Use a negative number for d to get a clockwise rotation."
  (when (and (numberp d) (distance p c))
    (let* ((r (distance p c))
           (k (sqrt (- (expt r 2) (expt (/ d 2) 2))))
           (dx (- (first p) (first c)))
           (dy (- (second p) (second c))))
      (when (< (abs d) (* 2 r))
        `(,(+ (first c)
              (/ (- (* dx (- (expt k 2) (expt (/ d 2) 2)))
                    (* dy k d)) (* r r)))
          ,(+ (second c)
              (/ (+ (* dy (- (expt k 2) (expt (/ d 2) 2)))
                    (* dx k d)) (* r r))))))))

Ro*ta"tion (?), n. [L. rotatio: cf. F. rotation.]

1.

The act of turning, as a wheel or a solid body on its axis, as distinguished from the progressive motion of a revolving round another body or a distant point; thus, the daily turning of the earth on its axis is a rotation; its annual motion round the sun is a revolution.

2.

Any return or succession in a series.

Moment of rotation. See Moment of inertia, under Moment. -- Rotation in office, the practice of changing public officers at frequent intervals by discharges and substitutions. -- Rotation of crops, the practices of cultivating an orderly succession of different crops on the same land.

 

© Webster 1913.


Ro*ta"tion (?), a.

Pertaining to, or resulting from, rotation; of the nature of, or characterized by, rotation; as, rotational velocity.

 

© Webster 1913.

Log in or register to write something here or to contact authors.