aboutsummaryrefslogtreecommitdiff
path: root/sys/mwcs/mwrotate.x
blob: 2797265901925159edbbbd4efce28c6e1d514737 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<syserr.h>
include	"mwcs.h"

define	LTM	Memd[ltm+(($2)-1)*pdim+($1)-1]

# MW_ROTATE -- Front end to mw_translate, used to perform simple rotations
# of the logical system by specifying the rotation angle in degrees, and the
# center of rotation.  Since only one rotation angle can be specified, this
# routine is useful only for 2-dim rotations (between any two axes).  Note
# that the transformation is performed in double precision even though the
# rotation angle and center are specified in single precision, preserving
# the full internal precision of the Lterm.

procedure mw_rotate (mw, theta, center, axbits)

pointer	mw			#I pointer to MWCS descriptor
real	theta			#I rotation angle, degrees
real	center[ARB]		#I center of rotation
int	axbits			#I bitflags defining axes to be rotated

double	d_theta
pointer	sp, ltm, ltv_1, ltv_2
int	axis[MAX_DIM], naxes, ax1, ax2, axmap, pdim, nelem
errchk	syserr

begin
	# Convert axis bitflags to axis list.
	call mw_gaxlist (mw, axbits, axis, naxes)
	if (naxes != 2)
	    call syserr (SYS_MWROT2AX)

	pdim = MI_NDIM(mw)
	nelem = pdim * pdim
	axmap = MI_USEAXMAP(mw)
	MI_USEAXMAP(mw) = NO
	d_theta = theta
	ax1 = axis[1]
	ax2 = axis[2]

	call smark (sp)
	call salloc (ltm, nelem, TY_DOUBLE)
	call salloc (ltv_1, pdim, TY_DOUBLE)
	call salloc (ltv_2, pdim, TY_DOUBLE)

	# Initialize the translation matrix and vectors.
	call mw_mkidmd (Memd[ltm], pdim)
	call aclrd (Memd[ltv_1], pdim)
	call aclrd (Memd[ltv_2], pdim)

	# Set up a 2-dim rotation between the specified axes.
	LTM(ax1,ax1) =  cos(d_theta)
	LTM(ax2,ax1) =  sin(d_theta)
	LTM(ax1,ax2) = -sin(d_theta)
	LTM(ax2,ax2) =  cos(d_theta)

	# Set the rotation center.
	Memd[ltv_1+ax1-1] = center[1]
	Memd[ltv_1+ax2-1] = center[2]

	# Set the back translation vector.
	Memd[ltv_2+ax1-1] = center[1]
	Memd[ltv_2+ax2-1] = center[2]

	# Perform the translation.
	call mw_translated (mw, Memd[ltv_1], Memd[ltm], Memd[ltv_2], pdim)

	MI_USEAXMAP(mw) = axmap
	call sfree (sp)
end