1 /* makerotation - Construct rotation from x to y by alpha. */
2 /* XLISP-STAT 2.1 Copyright (c) 1990, by Luke Tierney */
3 /* Additions to Xlisp 2.1, Copyright (c) 1989 by David Michael Betz */
4 /* You may give out copies of this software; for conditions see the */
5 /* file COPYING included with this distribution. */
9 static double inner_product(n
, x
, y
)
15 for (; n
> 0; n
--, x
++, y
++) result
+= *x
* *y
;
19 #define NORM(n, x) (sqrt(inner_product(n, x, x)))
21 make_rotation(n
, rot
, x
, y
, use_alpha
, alpha
)
27 double nx
, ny
, xy
, c
, s
;
30 for (i
= 0; i
< n
; i
++) {
31 for (j
= 0; j
< n
; j
++) rot
[i
][j
] = 0.0;
37 if (nx
== 0.0 || ny
== 0.0) return;
39 for (i
= 0; i
< n
; i
++) x
[i
] /= nx
;
40 for (i
= 0; i
< n
; i
++) y
[i
] /= ny
;
42 xy
= inner_product(n
, x
, y
);
43 c
= (use_alpha
) ? cos(alpha
) : xy
;
44 s
= (use_alpha
) ? sin(alpha
) : sqrt(1 - c
* c
);
46 for (i
= 0; i
< n
; i
++) y
[i
] -= xy
* x
[i
];
49 if (ny
== 0.0) return;
50 for (i
= 0; i
< n
; i
++) y
[i
] /= ny
;
52 for (i
= 0; i
< n
; i
++) {
53 for (j
= 0; j
< n
; j
++)
54 rot
[i
][j
] = x
[j
] * ( x
[i
] * (c
- 1.0) + y
[i
] * s
)
55 + y
[j
] * (- x
[i
] * s
+ y
[i
] * (c
- 1.0));