Vielleicht hilft dir folgendes Skript:
</font><blockquote><font size="1" face="Verdana, Helvetica, sans-serif">Code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">! XFORM Overview and Demo
! Karl Ottenstein, Ottenstein Consulting Services
! July 13, 2001
! karl@r...
! Sandpoint, Idaho USA
! Laurent asked about how the XFORM command is used in GDL. This object
! gives an overview, demo, and some references to textbooks at the end.
! Representing a point as a vector (x, y, z), one can apply matrix algebra
! in order to move (translate), scale, or rotate that point. According to
! Foley and van Dam (ref at end), the concept of homogeneous coordinates
! originated in geometry in 1946 by E. Maxwell at Cambridge. Homogeneous
! coordinates, and their transformations, extend a point vector with an
! additional scale factor - so (x, y, z) becomes (x, y, z, 1)
! The homogeneous transformation matrix for translation only is:
! 1 0 0 0
! 0 1 0 0
! 0 0 1 0
! dx dy dz 1
!
! So, with dx, dy, dz as 3, 6, 9, similar to ADD 2, 4, 6:
! 1 0 0 0
! 0 1 0 0
! 0 0 1 0
! 2 4 6 1
!
! Multiply a point (x, y, z, 1) in homogenous coordinate space
! (the extra 1) with the above matrix: pt * M and you get
! (x+2, y+4, z+6, 1) - a "translated" (shifted) point.
!
! Read DOWN the matrix columns as entering data for the XFORM, and
! leave off the last column of the 4x4 matrix above.
if jmp and jmp<5 then goto jmp*10
BLOCK 1, 4, 8
XFORM 1, 0, 0, 2,
0, 1, 0, 4,
0, 0, 1, 6
! Make an asymmetric block in order to see what's going on
BLOCK 1, 4, 8
DEL 1 : end
10:
! The homogeneous transformation matrix for scaling only is:
! sx 0 0 0
! 0 sy 0 0
! 0 0 sz 0
! 0 0 0 1
!
! So, with sx, sy, sz as 2, .5, .5, similar to MUL 2, 0.5, 0.5
! you have:
! 2 0 0 0
! 0 0.5 0 0
! 0 0 0.5 0
! 0 0 0 1
!
! Multiply a point (x, y, z, 1) in homogenous coordinate space
! by the above matrix: pt * M and you get
! (x*2, y*0.5, z*.05, 1)
!
! Read DOWN the matrix columns as entering data for the XFORM, and
! leave off the last column of the 4x4 matrix above.
goto 20
XFORM 2, 0, 0, 0,
0, 0.5, 0, 0,
0, 0, 0.5, 0
! Make a sphere in order to see what's going on
SPHERE 0.5
DEL 1 : end
20:
! Before we proceed to rotation - let's combine translation and scaling,
! using the same numbers as above. Notice that the XFORM below replaces
! one ADD and one MUL at this point:
goto 30:
! Translate and scale together
block 1,1,1 !SPHERE 2
XFORM 2, 0, 0, 2,
0, 0.5, 0, 4,
0, 0, 0.5, 6
! Make a sphere in order to see what's going on
block 1,1,1 !SPHERE 2
DEL 1 : end
!The transformation matrix for rotation "a" degrees about the Z axis is:
! cos(a) sin(a) 0 0
! -sin(a) cos(a) 0 0
! 0 0 1 0
! 0 0 0 1
!For "a" degrees about the X axis:
! 1 0 0 0
! 0 cos(a) sin(a) 0
! 0 -sin(a) cos(a) 0
! 0 0 0 1
!And, for "a" degrees about the Y axis:
! cos(a) 0 -sin(a) 0
! 0 1 0 0
! sin(a) 0 cos(a) 0
! 0 0 0 1
30:
! So...let's rotate a block
! about the Y axis 30 degrees...same as ROTY 30
goto 40
ang = 30
cosa = cos(ang)
sina = sin(ang)
XFORM cosa, 0, sina, 0,
0, 1, 0, 0,
-sina, 0, cosa, 0
! Make an asymmetric block in order to see what's going on
BLOCK 1, 4, 8
DEL 1 : END
40:
ang=40
XFORM 1,0,0,0,
0,1,0,0,
TAN(ang),0,1,0
block 1,1,1 !CYLIND 0.5,1
DEL 1 : end
!
! Note that the matrices are combined by multiplying them together,
! giving a new 4x4 transformation matrix. Any number of transformations
! can be combined into one final matrix - represented by a single
! GDL XFORM. Email me if you want me to post an explanation and
! example.
!
! This is probably not that useful for most GDL programmers, but
! would be very handy for API developers. (Picture an add-on where the
! user has sliders to rotate, scale and translate an object. The final
! settings could be saved as a single XFORM.)
! References
!
! These books are dated, as am I. No doubt there are newer additions,
! and even other, newer books out there now. Two of them were
! classics, and I expect still are.
!
! Foley, J. D. and van Dam, A. Fundamentals of Interactive Computer
! Graphics. Addison-Wesley (1982) 664 pages. This was THE book to
! have - there must be a newer edition.
! ISBN for this edition 0-201-14468-9.
!
! Giloi, Wolfgang K. Interactive Computer Graphics.
! Prentice-Hall (1978) 354 pages.
!
! Harrington, Steven. Computer Graphics: A Programming Approach.
! McGraw-Hill (1983) 448 pages.
!
! Newman, William M. and Sproull, Robert F. Principles of
! Interactive Computer Graphics, 2nd Edition.
! McGraw-Hill (1979) 541 pages. This was the bible for graphics
! when I was in school.
!
! Karl Ottenstein, July 2001.benötigt Parameter JMP als numerischen mit Werebereich 1 bis 4.