Vector graph display on Windows Mobile

Source: Internet
Author: User

Vector Graphics represent images in computer graphics using geometric elements such as points, straight lines, or polygon based on mathematical equations. Let's discuss how to implement vector graphics on mobile phones.

Take a map of the Beijing region as an example to display it on a mobile phone and implement functions such as translation, scaling, and rotation. In the GIS system, because the earth is a spherical celestial body, the Earth coordinates need to be converted into map coordinates by projection, and then to the device screen coordinates for display. In general, the map coordinate system, X axis to the right, Y axis to the up; the screen coordinate system x axis to the right, Y axis to the down. For example

To accurately display the map on the screen, we need to make a conversion. First, find a point on the map and match it with a point on the screen. For simplicity, we initially matched the map center point with the display window center point. Assume that the coordinates of the center of the displayed window are m_wscreen/2, m_hscreen/2, m_pt2dmapcenter.x, m_pt2dmapcenter.y, and m_dscale. M_pt2dmapcenter is defined as follows:
Typedef struct
{
Double X;
Double Y;
} Point2d;
Point2d m_pt2dmapcenter;

Now, refer to the coordinate system diagram above to get a conversion function from map coordinates to screen coordinates.
Void maptoclient (point & ptdst, const point2d & ptsrc)
{
Double X, Y;
X = ptsrc. X-m_pt2dmapcenter.x;
Y = ptsrc. Y-m_pt2dmapcenter.y;
Ptdst. x = (INT) (x * m_dscale) + m_wscreen/2;
Ptdst. Y = m_hscreen/2-int (y * m_dscale );
}

Let's take a look at the map Adaptation Window.

 
Let's take a look at the reduced display.

 
For the translation function, you only need to adjust the m_pt2dmapcenter position.

 
With the idea, the rotation function also came out, taking the clockwise direction as the rotation direction. Pay attention to m_angleratio as the radian rather than the angle.
Void maptoclient (point & ptdst, const point2d & ptsrc)
{
Double X, Y;
X = (ptsrc. X-m_pt2dmapcenter.x) * Cos (m_angleratio)-(ptsrc. Y-m_pt2dmapcenter.y) * sin (m_angleratio );
Y = (ptsrc. X-m_pt2dmapcenter.x) * sin (m_angleratio) + (ptsrc. Y-m_pt2dmapcenter.y) * Cos (m_angleratio );
Ptdst. x = (INT) (x * m_dscale) + m_wscreen/2;
Ptdst. Y = m_hscreen/2-int (y * m_dscale );
}

The following is a 30-degree rotation

The author also developed a 2D projection method, which depends on the position (x, y, z) of the observation point and the angle of the view. The implementation is slightly complicated and will not be shown here, if you are interested, you can discuss it. Displayed after projection

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.