250 likes | 278 Views
Learn about the transformation of coordinate spaces, including world-space to page-space, page-space to device-space, and more. Understand terms like scaling, translation, rotation, shearing, and reflection in the Cartesian coordinate system.
E N D
Coordinate Spaces and Transformations Jihoon.Yim 22/04/2008
Contents • Transformation of Coordinate Spaces • World-space to Page-space Transformations • Page-space to Device-space Transformations • Device-Space to Physical-Device Transformation • Default Transformations • Using Coordinate Spaces and Transformations
Transformation of Coordinate Spaces • Cartesian coordinate system • Four coordinate spaces the system supports : • Terms • Cartesian coordinate system • : 데카르트 좌표계 • Coordinate space • : 좌표공간 • scaling : 축척 • translation : 변환 • rotation : 회전 • shearing : 자르기, • 전단변형 • reflection : 투영 • origin : 원점
Transformation of Coordinate Spaces • To depict output on a physical device : • The system copies (or maps) a rectangular region from one coordinate space into the next using a transformation until the output appears in its entirety on the physical device. • Mapping begins in the application’s world space if the application has called the SetWorldTransform function; • Otherwise, mapping occurs in page space. • As the system copies each point within the rectangular region from one space into another, it applies an algorithm called a transformation. • Terms • depict • : 그리다, 묘사하다 • entirety : 전체
World-space to Page-space Transformations World-space to page-space transformations support translation and scaling. In addition, they support rotation, shear, and reflection capabilities. Following topics will be shown in this section : • Translation • Scaling • Rotation • Shear • Reflection
World-space to Page-space Transformations • Translation • By calling the SetWorldTransform function • The SetWorldTransform function receives a pointer to an XFORM structure containing the appropriate values. • The eDx and eDy member of XFORM specify the horizontal and vertical translation components, respectively. Ex) a 20- by 20-unit rectangle that was translated to the right by 10 |1 0 0| |x` y` 1| = |x y 1| * |0 1 0| |Dx Dy 1| x` = x + Dx y` = y + Dy |1 0 0| |10 10| * |0 1 0| = (20, 10) |10 0 1| • Terms • respectively : 각각
World-space to Page-space Transformations • Scaling • By calling the SetWorldTransform function • The eM11 and eM22 members of XFORM specify the horizontal and vertical scaling components, respectively. Ex) a 20- by 20-unit rectangle scaled vertically to twice its original height: x` = x * Dx y` = y + Dy |x` y`| = |x y|* |Dx 0| |0 Dy| |10 5| = |10 5| * |1 0| = (10, 10) |0 2|
World-space to Page-space Transformations • Rotation • By calling the SetWorldTransform function • The eM11, eM12, eM21, and eM22 members of XFORM specify respectively, the cosine, sine, negative sine, and cosine of the angle of rotation Ex) a 20- by 20-unit rectangle rotated 30 degrees : x` = (x * cos A) – (y * sin A) y` = (x * sin A) + (y * con A) |x` y`| == |x y| * | cos A sin A| |-sin A cos A| • Terms • angle : 각
World-space to Page-space Transformations • Rotation Algorithm Derivation • Trigonometry’s addition • Derivation x = h * cosA1 y = h * sinA1 x` = h * cos(A1 + A2) y` = h * sin(A1 + A2) x` = (h * cosA1 * cosA2) – (h * sinA1 * sinA2) y` = (h * cosA1 * sinA2) + (h * sinA1 * cosA2) x` = (x * cosA2) – (y * sinA2) y` = (x * sinA2) + (y * cosA2) sin(A1 + A2) = (sinA1 * cosA2) + (cosA1 * sinA2) cos(A1 + A2) = (cosA1 * cosA2) – (sinA1 * sinA2) • Terms • derivation : 전개 • Trigonometry’s addition : 삼각법 덧셈
World-space to Page-space Transformations • Shear • By calling the SetWorldTransform function • The eM12 and eM21 members of XFORM specify the horizontal and vertical proportionality constants, Ex) a 20- by 20-unit rectangle sheared horizontally x` = x + (Sx * y) y` = y + (Sy * x) |x` y`| == |x y| * |1 Sy| |Sx 1| |20 5| * |1 0| = (25, 5) |1 1| • Terms • proportionality • : 비례
World-space to Page-space Transformations • Reflection • By calling the SetWorldTransform function • The eM11 and eM22 members of XFORM specify the horizontal and vertical reflection components, respectively. • The reflection transformation creates a mirror image of an object with respect to either the x- or y-axis. • In short, reflection is just negative scaling. • To produce a horizontal reflection, x-coordinates are multiplied by -1. • To produce a vertical reflection, y-coordinates are multiplied by -1. |-1 0| The 2-by-2 matrix that produced horizontal reflection |0 1| |1 0| The 2-by-2 matrix that produced vertical reflection |0 -1|
World-space to Page-space Transformations • Combined World-to-page Space Transformations • The five world-to-page transformations can be combined into a single 3-by-3 matrix. • CombineTransform function • Can be used to combine two world-space to page-space transformations. • When an application calls SetWorldTransform, it stores the elements of the 3-by-3 matrix in an XFORM structure. • The members of this structure correspond to the first two columns of a 3-by-3 matrix; • The last column of the matrix is not required because it values are constant. | x11 x12 0| | x21 x22 0| | eDx eDy 1| • GetWorldTransform function • to revive the elements of the current world transformation. typedef struct _XFROM { FLOAT eM11; FLOAT eM12; FLOAT eM21; FLOAT eM22; FLOAT eDx; FLOAT eDy; } XFORM, *PXFORM;
Page-space to Device-space Transformations The page-space to device-space transformation determines the mapping mode for all graphic output associated with a particular DC. A mapping mode is a scaling transformation. Following topics will be shown in this section : • Mapping Modes and Translations • Predefined Mapping Modes • Application-Defined Mapping Modes
Page-space to Device-space Transformations • Mapping Modes and Translations • Terms • Unit : 단위 • Axis : 축 • Anisotropic : 이방성의 • Isotropic : 등방성의
Page-space to Device-space Transformations • SetMapMode & GetMapMode • To set a mapping mode and To retrieve the current mapping mode for a DC • Window & Viewport • The page space to device-space transformations consist of values calculated from the points given by the window and viewport. • Window • the logical coordinate system of the page space • Viewport • the device coordinate system of the device space (pixel) • The window and viewport each consist of an origin, a horizontal (x) extent, and a vertical (y) extent. • The system combines the origins and extents from both the window and viewport to create the transformation. • Terms • origin : 좌표의 원점 • extent : 크기, 범위
Page-space to Device-space Transformations • Maps the window to the viewport • The window and viewport extents establish a ratio or scaling factor used in the page-space to device-space transformations.
Page-space to Device-space Transformations • Maps the window to the viewport • Predefined mapping modes • MM_HIENGLISH, MM_LOENGLISH, MM_HIMETRIC, MM_LOMETRIC, MM_TEXT, and MM_TWIPS • the extents are set by the system when SetMapMode is called. • They cannot be changed. • The other two mapping modes • MM_ISOTROPIC, MM_ANISOTROPIC • the extents must be specified. • After calling SetMapMode, call the SetWindowExtEx and SetViewportExtEx functions to specify the extents. • In the MM_ISOTROPIC mapping mode, it’s important to call SetWindowExtEx before calling SetViewportExtEx.
Page-space to Device-space Transformations • Maps the window to the viewport • The window and viewport origins establish the translation used in the page-space to device-space transformations. • Set the window and viewport origins by using the SetWindowOrgEx and SetViewportOrgEx functions. • The origins are independent of the extents, and an application can set them regardless of the current mapping mode. • Changing a mapping mode does not affect the currently set origins (although it can affect the extents). • Origins are specified in absolute units that the current mapping mode does not affect. • To alter the origins, use the OffsetWindowOrgEx and OffsetViewportOrgEx functions. • Terms • regardless of • : ~에 관계없이 • affect : 영향을 미치다
Page-space to Device-space Transformations • Maps the window to the viewport • The following formula shows the math involved in converting a point from page space to device space. • Dx : x value in device units • Lx : x value in logical units (also known as page space units) • WOx : window x origin • VOx : viewport x origin • WEx : window x-extent • VEx : viewport x-extent • The same equation with y replacing x transforms the y component of a point. • The LPtoDP and DPtoLP functions may be used to convert from logical points to device points and from device points to logical points, respectively. Dx = ((Lx – WOx) * VEx / WEx) + VOx) • Terms • formula : 식 • equation : 방정식
Page-space to Device-space Transformations • Predefined Mapping Modes • Device dependent • MM_TEXT • Device independent • MM_HIENGLISH, MM_LOENGLISH, MM_HIMETRIC, MM_LOMETRIC, and MM_TWIPS • The default mapping mode is MM_TEXT • One logical unit equals one pixel. • Positive x is to the right, and positive y is down. • This mode maps directly to the device’s coordinate system. • The logical-to-physical mapping involves only an offset in x and y that is defined by the application-controlled window and viewport origins. • The viewport and window extents are all set to 1, creating a one-to-one mapping. • Applications that display geometric shapes make use of one of the device-independent mapping modes. • Terms • geometric : 기하의
Page-space to Device-space Transformations • Application-Defined Mapping Modes • MM_ISOTROPIC and MM_ANISOTROPIC) are provided for application-specific mapping modes. • MM_ISOTROPIC guarantees that logical units in the x-direction and in the y-direction are equal • MM_ANISOTROPIC mode allows the units to differ. • a CAD or drawing application can benefit from the MM_SIOTROPIC mapping mode (or MM_ANISOTROIPIC) • may need to specify logical units that correspond to the increments on an engineer’s scale(1/64 inch) • These units would be difficult to obtain with the predefined mapping modes. • The following examples shows how to set logical units to 1/64 inch : • SetMapMode(hDC, MM_ISOTROPIC); • SetWindowExtEx(hDC, 64, 64, NULL); • SetViewportExtEx(hDC, GetDeviceCaps(hDC, LOGPIXELSX), • GetDevcieCaps(hDC, LOGPIXELSY), NULL);
Device-Space to Physical-Device Transformation • Unique in several respects • It is limited to translation and is controlled by the system. • The sole purpose of this transformation is to ensure that the origin of device space is mapped to the proper point on the physical device. • There are no functions to set this transformation, nor are there any functions to retrieve related data.
Default Transformations • Default transformations • Whenever an application creates a DC and immediately begins calling GDI drawing or output functions, it takes advantage of the default page-space to device-space, and device-space to client-area transformations. • A world-to-page space transformation cannot happen until the application first calls the SetGraphicsMode function to set the mode to GM_ADVANCED and then calls the SetWorldTransform function. • Use of MM_TEXT (the default page-space to device space transformation) results in a one-to-one mapping; • That is, a given point in page space maps to the same point in device space. • The one unique aspect of MM_TEXT is the orientation of the y-axis in page space. In MM_TEXT, the positive y-axis extends downward and the negative y-axis extends upward.
Using Coordinate Spaces and Transformations • The example contains the following tasks: • Drawing graphics with predefined units. • Centering graphics in the application’s client area • Scaling graphics output to half its original size. • Translating graphics output ¾ of an inch to the right. • Rotating graphics 30 degrees. • Shearing graphics output along the x-axis. • Reflecting graphics output about an imaginary horizontal axis drawn through its midpoint.
References • MSDN 2003