Moving the Origin (转)

本文介绍了如何使用MFC的CDC类中的SetWindowOrg和SetViewportOrg函数来改变绘图上下文的坐标原点位置,实现图形在窗口中的居中显示或定位到指定位置,并探讨了设备坐标系与逻辑坐标系的区别。
Moving the Origin (转)[@more@]  

Moving the Origin

By default, a device context's origin is in the upper left corner of the display surface. Even if you change the mapping mode, the origin remains in the upper left corner. But just as you can change the mapping mode, you can also move the origin. MFC's CDC class provides two functions for moving the origin. CDC::SetWindowOrg moves the window origin, and CDC::SetViewportOrg moves the viewport origin. You'll normally use one but not both. Using both can be very confusing.

Suppose you'd like to move the origin to the center of the window so that you can center what you draw by centering your output around the point (0,0). Assuming that dc is a device context object, here's one way to do it:

CRect rect; GetClientRect (&rect); dc.SetViewportOrg (rect.Width () / 2, rect.Height () / 2);

 
 

Here's another way to accomplish the same thing, assuming that you're working in the MM_LOENGLISH mapping mode:

CRect rect; GetClientRect (&rect); CPoint point (rect.Width () / 2, rect.Height () / 2); dc.SetMapMode (MM_LOENGLISH); dc.DPtoLP (&point); dc.SetWindowOrg (-point.x, -point.y);

 
 

It's easy to get SetViewportOrg and SetWindowOrg confused, but the distinction between them is actually quite clear. Changing the viewport origin to (x,y) with SetViewportOrg tells windows to map the logical point (0,0) to the device point (x,y). Changing the window origin to (x,y) with SetWindowOrg does essentially the reverse, telling Windows to map the logical point (x,y) to the device point (0,0)—the upper left corner of the display surface. In the MM_TEXT mapping mode, the only real difference between the two functions is the signs of x and y. In other mapping modes, there's more to it than that because SetViewportOrg deals in device coordinates and SetWindowOrg deals in logical coordinates. You'll see examples of how both functions are used later in this chapter.

As a final example, suppose you're drawing in the MM_HIMETRIC mapping mode, where 1 unit equals 1/100 of a millimeter, positive x points to the right, and positive y points upward, and you'd like to move the origin to the lower left corner of the window. Here's an easy way to do it:

CRect rect; GetClientRect (&rect); dc.SetViewportOrg (0, rect.Height ());

 
 

Now you can draw with positive x and y values using coordinates relative to the window's lower left corner.

A Final on Coordinate Systems

When you talk about mapping modes, window origins, viewport origins, and other idioms related to the GDI's handling of coordinates, it's easy to get tangled up in the teRminology. Understanding the difference between the device coordinate system and the logical coordinate system might help clear some of the cobwebs.

In the device coordinate system, distances are measured in pixels. The device point (0,0) is always in the upper left corner of the display surface, and the positive x and y axes always point right and downward. The logical coordinate system is altogether different. The origin can be placed anywhere, and both the orientation of the x and y axes and the scaling factor (the number of pixels that correspond to 1 logical unit) vary with the mapping mode. To be precise, they vary with the window extents and the viewport extents. You can change these extents in the MM_ISOTROPIC and MM_ANISOTROPIC mapping modes but not in the other mapping modes.

You'll sometimes hear Windows programmers talk about "client coordinates" and "screen coordinates." Client coordinates are simply device coordinates relative to the upper left corner of a window's client area. Screen coordinates are device coordinates relative to the upper left corner of the screen. You can convert from client coordinates to screen coordinates and vice versa using the CWnd::ClientToScreen and CWnd::ScreenToClient functions. Why these functions are useful will become apparent to you the first time you call a Windows function that returns screen coordinates and you pass them to a function that requires client coordinates, or vice versa.

Getting Information About a Device

Sometimes it's helpful to get information about a device before you send output to it. The CDC::GetDeviceCaps function lets you retrieve all kinds of information about a device, from the number of colors it supports to the number of pixels it can display horizontally and vertically. The following code initializes cx and cy to the width and height of the screen, in pixels:

CClientDC dc (this); int cx = dc.GetDeviceCaps (HORZRES); int cy = dc.GetDeviceCaps (VERTRES);

 
 

If the screen resolution is 1,024 by 768, cx and cy will be set to 1,024 and 768, respectively.

The table below lists some of the parameters you can pass to GetDeviceCaps to acquire information about the physical output device associated with a device context. How you interpret the results depends somewhat on the device type. For example, calling GetDeviceCaps with a HORZRES parameter for a screen DC returns the screen width in pixels. Make the same call to a printer DC and you get back the width of the printable page, once more in pixels. As a rule, values that imply any kind of scaling (for example, LOGPIXELSX and LOGPIXELSY) return physically correct values for printers and other hardcopy devices but not for screens. For a 600 dpi laser printer, both LOGPIXELSX and LOGPIXELSY return 600. For a screen, both will probably return 96, regardless of the physical screen size or resolution.

Interpreting the color information returned by the NUMCOLORS, BITSPIXEL, and PLANES parameters of GetDeviceCaps is a bit tricky. For a printer or a plotter, you can usually find out how many colors the device is capable of displaying from the NUMCOLORS parameter. For a monochrome printer, NUMCOLORS returns 2.

Useful GetDeviceCaps Parameters

Parameter Returns HORZRES Width of the display surface in pixels VERTRES Height of the display surface in pixels HORZSIZE Width of the display surface in millimeters VERTSIZE Height of the display surface in millimeters LOGPIXELSX Number of pixels per logical inch horizontally LOGPIXELSY Number of pixels per logical inch vertically NUMCOLORS For a display device, the number of static colors; for a printer or plotter, the number of colors supported BITSPIXEL Number of bits per pixel PLANES Number of bit planes RASTERCAPS Bit flags detailing certain characteristics of the device, such as whether it is palettized and whether it can display bitmapped images TECHNOLOGY Bit flags identifying the device type—screen, printer, plotter, and so on

However, the color resolution of the screen (the number of colors that can be displayed onscreen simultaneously) is computed by multiplying BITSPIXEL and PLANES and raising 2 to the power of the result, as demonstrated here:

CClientDC dc (this); int nPlanes = dc.GetDeviceCaps (PLANES); int nBPP = dc.GetDeviceCaps (BITSPIXEL); int nColors = 1 << (nPlanes * nBPP);

 
 

If this code is executed on a PC equipped with a 256-color video adapter, nColors equals 256. Calling GetDeviceCaps with a NUMCOLORS parameter, meanwhile, returns not 256 but 20—the number of "static colors" that Windows programs into the video adapter's color palette. I'll have more to say about the color characteristics of screens and video adapters and also about static colors in Chapter 15.

I'll use GetDeviceCaps several times in this book to adapt the sample programs' output to the physical attributes of the output device. The first use will come later in this chapter, when the screen's LOGPIXELSX and LOGPIXELSY parameters are used to draw rectangles 1 logical inch long and 1/4 logical inch tall in the MM_TEXT mapping mode.


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-989230/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10752043/viewspace-989230/

wall attribute command Syntax wall attribute <facet> <vertex> keyword ... <range> Primary keywords: centrotation | conveyor | cutoffang | displacement | euler | fragment | position | spin | velocity | xcentrotation | xconveyor | xdisplacement | xeuler | xposition | xspin | xvelocity | ycentrotation | yconveyor | ydisplacement | yeuler | yposition | yspin | yvelocity | zcentrotation | zconveyor | zdisplacement | zeuler | zposition | zspin | zvelocity Set the value of wall attributes. This command is a synonym for the wall initialize command. Individual attributes can be listed with the wall list command and all attributes can be visualized. The optional vertex kewyord can be used to with the velocity, xvelocity, yvelocity, or zvelocity keywords to set the vertex velocities for vertices in the specified range. The optional facet keyword can be used with the conveyor, xconveyor, yconveyor, or zconveyor keywords to set the facet conveyor velocities for facets in the specified range. centrotation vcen Set the center of rotation for walls in the range. This is the position about which rotations occur when an angular velocity is supplied to a wall. The center of rotation translates with the wall if a translational velocity is supplied. The default center of rotation is the origin. conveyor vconcvel Set the facet conveyor velocity vector. If given with the facet keyword, then the range applies to facets. Otherwise the conveyor velocity is set for all facets in each wall in the specified range. The conveyor velocity is a fictitious velocity that is added to the wall velocity when calculating the relative velocity between a facet and another piece. A conveyor velocity cannot be active when vertex velocities are active. Setting a nonzero conveyor velocity allows one to simulate conveyance of balls or clumps along facets without moving the facets. cutoffang fang Set the cutoff angle (an angle in degrees) for walls. By default, the cutoff angle is 0. This angle controls contact state information propagation. displacement vdisp Accumulated wall displacement vector as a result of cycling. euler veuler (3D ONLY) Current orientation of Euler angles following the X,Y,Z convention (e.g., rotation about the x-axis followed by rotation about the y'-axis followed by rotation about the z''-axis) in degrees. The orientation is updated only when orientation tracking has been enabled (see set orientation command). When active, the current clump orientation can be visualized. fragment i Fragment ID (see "Fragment"). position vpos Wall location vector. This corresponds to the average position of all vertices. The center of rotation is not modified. spin fspin fspiny fspinz (y- and z- components are 3D ONLY) The wall angular velocity in radians per second. Walls rotate around their center of rotation. velocity vel Wall translational velocity vector. If given with the vertex keyword, then this corresponds to the vertex velocity and the range applies to vertices. xcentrotation fcenx Set the x-component of the center of rotation for walls in the range. This is the position about which rotations occur when an angular velocity is supplied to a wall. The center of rotation translates with the wall if a translational velocity is supplied. The default center of rotation is the origin. xconveyor fconcvelx Set the x-component of the facet conveyor velocity. If given with the facet keyword, then the range applies to facets. Otherwise the conveyor velocity is set for all facets in each wall in the specified range. The conveyor velocity is a fictitious velocity that is added to the wall velocity when calculating the relative velocity between a facet and another piece. A conveyor velocity cannot be active when vertex velocities are active. Setting a nonzero conveyor velocity allows one to simulate conveyance of balls or clumps along facets without moving the facets. xdisplacement fdispx The x-component of the accumulated wall displacement as a result of cycling. xeuler feulerx (3D ONLY) The x-euler angle (in degrees) of the current wall orientation. See the euler keyword for further details. xposition fposx The x-component of the wall location. This corresponds to the average position of all vertices. The center of rotation is not modified. xspin fspinx (3D ONLY) The x-component of the wall angular velocity in radians per second. Walls rotate around their center of rotation. xvelocity fvelx The x-component of the wall translational velocity. If given with the vertex keyword, then this corresponds to the x-component of the vertex velocity and the range applies to vertices. ycentrotation fceny Set the y-component of the center of rotation for walls in the range. This is the position about which rotations occur when an angular velocity is supplied to a wall. The center of rotation translates with the wall if a translational velocity is supplied. The default center of rotation is the origin. yconveyor fconcvely Set the y-component of the facet conveyor velocity. If given with the facet keyword, then the range applies to facets. Otherwise the conveyor velocity is set for all facets in each wall in the specified range. The conveyor velocity is a fictitious velocity that is added to the wall velocity when calculating the relative velocity between a facet and another piece. A conveyor velocity cannot be active when vertex velocities are active. Setting a nonzero conveyor velocity allows one to simulate conveyance of balls or clumps along facets without moving the facets. ydisplacement fdispy The y-component of the accumulated wall displacement as a result of cycling. yeuler feulery (3D ONLY) The y-euler angle (in degrees) of the current wall orientation. See the euler keyword for further details. yposition fposy The y-component of the wall location. This corresponds to the average position of all vertices. The center of rotation is not modified. yspin fspiny (3D ONLY) The y-component of the wall angular velocity in radians per second. Walls rotate around their center of rotation. yvelocity fvely The y-component of the wall translational velocity. If given with the vertex keyword, then this corresponds to the y-component of the vertex velocity and the range applies to vertices. zcentrotation fcenz (3D ONLY) Set the z-component of the center of rotation for walls in the range. This is the position about which rotations occur when an angular velocity is supplied to a wall. The center of rotation translates with the wall if a translational velocity is supplied. The default center of rotation is the origin. zconveyor fconcvelz (3D ONLY) Set the z-component of the facet conveyor velocity. If given with the facet keyword, then the range applies to facets. Otherwise the conveyor velocity is set for all facets in each wall in the specified range. The conveyor velocity is a fictitious velocity that is added to the wall velocity when calculating the relative velocity between a facet and another piece. A conveyor velocity cannot be active when vertex velocities are active. Setting a nonzero conveyor velocity allows one to simulate conveyance of balls or clumps along facets without moving the facets. zdisplacement fdispz (3D ONLY) The z-component of the accumulated wall displacement as a result of cycling. zeuler feulerz (3D ONLY) The z-euler angle (in degrees) of the current wall orientation. See the euler keyword for further details. zposition fposz (3D ONLY) The z-component of the wall location. This corresponds to the average position of all vertices. The center of rotation is not modified. zspin fspinz (3D ONLY) The z-component of the wall angular velocity in radians per second. Walls rotate around their center of rotation. zvelocity fvelz (3D ONLY) The z-component of the wall translational velocity. If given with the vertex keyword, then this corresponds to the z-component of the vertex velocity and the range applies to vertices. Usage Example Be aware of the distinction between attributes and properties! The tutorial example "Attributes and Properties" discusses this issue in detail. © Copyright 2015, Itasca Consulting Group Inc. Last updated on Jun 24, 2016. 学习这些资料研磨球形wall坐标为[grind_x = 0.2e-5][grind_y = 0.2e-5][grind_z = 12e-7],写出球形wall绕着z轴以一角速度旋的PFC命令流,
07-08
Exercise 3.16 In terms of the ˆxs, ˆys, ˆzs coordinates of a fixed space frame {s}, frame {a} has its ˆxa-axis pointing in the direction (0, 0, 1) and its ˆya-axis pointing in the direction (1, 0, 0), and frame {b} has its ˆxb-axis pointing in the direction (1, 0, 0) and its ˆyb-axis pointing in the direction (0, 0, 1). The origin of {a} is at (3, 0, 0) in {s} and the origin of {b} is at (0, 2, 0) in {s}. (a) Draw by hand a diagram showing {a} and {b} relative to {s}. (b) Write down the rotation matrices Rsa and Rsb and the transformation matrices Tsa and Tsb. (c) Given Tsb, how do you calculate T 1 sb without using a matrix inverse? Write T 1 sb and verify its correctness using your drawing. (d) Given Tsa and Tsb, how do you calculate Tab (again without using matrix inverses)? Compute the answer and verify its correctness using your drawing. (e) Let T = Tsb be considered as a transformation operator consisting of a rotation about ˆx by 90 and a translation along ˆy by 2 units. Calculate T1 = TsaT. Does T1 correspond to a rotation and translation about ˆxs and ˆys, respectively (a world-fixed transformation of Tsa), or a rotation and translation about ˆxa and ˆya, respectively (a body-fixed transformation of Tsa)? Now calculate T2 = T Tsa. Does T2 correspond to a body-fixed or world-fixed transformation of Tsa? (f) Use Tsb to change the representation of the point pb = (1, 2, 3) in {b} coordinates to {s} coordinates. (g) Choose a point p represented by ps = (1, 2, 3) in {s} coordinates. Calculate p0 = Tsbps and p00 = T 1 sb ps. For each operation, should the result be interpreted as changing coordinates (from the {s} frame to {b}) without moving the point p, or as moving the location of the point without changing the reference frame of the representation? (h) A twist V is represented in {s} as Vs = (3, 2, 1, 1, 2, 3). What is its representation Va in frame {a}? (i) By hand, calculate the matrix logarithm [S]✓ of Tsa. (You may verify your answer with software.) Extract the normalized screw axis S and rotation amount ✓. Find a {q, s, h ˆ } representation of the screw axis. Redraw the fixed frame {s} and in it draw S.
10-15
同步定位与地图构建(SLAM)技术为移动机器人或自主载具在未知空间中的导航提供了核心支撑。借助该技术,机器人能够在探索过程中实时构建环境地图并确定自身位置。典型的SLAM流程涵盖传感器数据采集、数据处理、状态估计及地图生成等环节,其核心挑战在于有效处理定位与环境建模中的各类不确定性。 Matlab作为工程计算与数据可视化领域广泛应用的数学软件,具备丰富的内置函数与专用工具箱,尤其适用于算法开发与仿真验证。在SLAM研究方面,Matlab可用于模拟传感器输出、实现定位建图算法,并进行系统性能评估。其仿真环境能显著降低实验成本,加速算法开发与验证周期。 本次“SLAM-基于Matlab的同步定位与建图仿真实践项目”通过Matlab平台完整再现了SLAM的关键流程,包括数据采集、滤波估计、特征提取、数据关联与地图更新等核心模块。该项目不仅呈现了SLAM技术的实际应用场景,更为机器人导航与自主移动领域的研究人员提供了系统的实践参考。 项目涉及的核心技术要点主要包括:传感器模型(如激光雷达与视觉传感器)的建立与应用、特征匹配与数据关联方法、滤波器设计(如扩展卡尔曼滤波与粒子滤波)、图优化框架(如GTSAM与Ceres Solver)以及路径规划与避障策略。通过项目实践,参与者可深入掌握SLAM算法的实现原理,并提升相关算法的设计与调试能力。 该项目同时注重理论向工程实践的化,为机器人技术领域的学习者提供了宝贵的实操经验。Matlab仿真环境将复杂的技术问题可视化与可操作化,显著降低了学习门槛,提升了学习效率与质量。 实践过程中,学习者将直面SLAM技术在实际应用中遇到的典型问题,包括传感器误差补偿、动态环境下的建图定位挑战以及计算资源优化等。这些问题的解决对推动SLAM技术的产业化应用具有重要价值。 SLAM技术在工业自动化、服务机器人、自动驾驶及无人机等领域的应用前景广阔。掌握该项技术不仅有助于提升个人专业能力,也为相关行业的技术发展提供了重要支撑。随着技术进步与应用场景的持续拓展,SLAM技术的重要性将日益凸显。 本实践项目作为综合性学习资源,为机器人技术领域的专业人员提供了深入研习SLAM技术的实践平台。通过Matlab这一高效工具,参与者能够直观理解SLAM的实现过程,掌握关键算法,并将理论知识系统应用于实际工程问题的解决之中。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值