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