In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
1 affine affine transformation concept
Geometrically defined as an affine transformation or affine mapping between two vector spaces (from Latin, affinis, "and. Correlation") consisting of a linear transformation followed by a translation.
2 agg::trans_affine member function description 2.1 Zoom
Inline const trans_affine&trans_affine::scale (double x, double y)
The scaling factor of the parameter pair of x Abscissa and the scaling coefficient of parameter 2 pair of y ordinate
There is a problem here: after zooming the graph, it is not zooming in the original position, but the overall zoom, such as the most obvious is the circle, the position of the center of the circle has changed, so it needs to be translated and restored to the previous center of the circle.
2.2 rotation
Inline const trans_affine&trans_affine::rotate (double a)
The parameter rotates the graph, and the center of the rotation is the origin of the coordinates (0Power0), that is, the upper left corner of the display interface, which is different from the general Cartesian coordinates, the longitudinal coordinates of the Y axis are flipped, and the Y axis gradually increases downward.
Application Note: the parameters are in the form of radians. As for the difference between radians (radians) and angles (degrees), please refer to other chapters and will not repeat them. So the range of this parameter is [- pi,pi] .pi = 3.141592653. A positive value means to rotate clockwise, a negative value to rotate counterclockwise, and the central symmetry point of the rotation is (0Power0), remember! It is likely to rotate outside the interface.
Tips: angle to Radian agg::deg2rad (doubledegrees)
2.3 Translation
Inline const trans_affine&trans_affine::translate (double x, double y)
Parameter one, X-axis translation, parameter two, Y-axis translation
3 Mathematical knowledge about affine transformation
This article does not intend to describe the basic principles of trans_affine affine transformation, in which the code is defined in the agg_trans_affine.h file, and the six affine variables involved are as follows:
Double sx, shy, shx, sy, tx, ty
You can search for the basic principles of affine transformation.
4 some test examples 4.1 rotate out of the interface
The example code is as follows:
Ras.reset ()
Agg::ellipse ell (400, 400, 20, 70)
/ / coordinate conversion
Agg::trans_affine mtx
/ / mtx.scale (0.5); / / the x axis has shrunk to half of its original size
Mtx.rotate (agg::deg2rad (30)); / / rotate 30 degrees
/ / mtx.translate (200200); / / Xpenny Y coordinates are translated 100 respectively.
Typedef agg::conv_transform ell_ct_type
Ell_ct_type ctell (ell,mtx); / / Matrix transformation
Ras.add_path (ctell)
Agg::render_scanlines_aa_solid (ras,sl,renb,agg::rgba8 (255j0pl 0))
Ras.reset ()
This is the most classic example on the Internet, but it doesn't show how rotation is implemented. I changed the code a little bit:
Mtx.rotate (agg::deg2rad (60)); / / rotate 60 degrees
The result: there is nothing on the interface and the ellipse is gone!
Reason: rotate the interface clockwise.
4.2 View the process of rotation through the slider
Void RotateEclipse ()
{
/ / for the basic use of agg::slider_ctrl, please refer to other chapters
Int value = m_slider1.value (); / / value
Agg::rendering_buffer & rbuf = rbuf_window ()
Agg::pixfmt_bgr24 pixf (rbuf)
Typedef agg::renderer_base renderer_base_type
Renderer_base_type renb (pixf)
Agg::rasterizer_scanline_aa ras
Agg::scanline_u8 sl
Ren_bas.clear (agg::rgba8 (255255255))
Agg::trans_affine mtx
/ / mtx.scale (0.5, 0.5); / / the x-axis has shrunk to half of its original size
Mtx.rotate (agg::deg2rad (value)); / / rotate 30 degrees
/ / mtx.translate (100,100); / / XQuery Y coordinates translate 100,100 respectively
Agg::ellipse ell (900, 900, 20, 30)
Typedef agg::conv_transform ell_ct_type
Ell_ct_type ctell (ell,mtx); / / Matrix transformation
Ras.reset ()
Ras.add_path (ctell)
Agg::render_scanlines_aa_solid (ras,sl,renb,agg::rgba8 (255j0pl 0))
Agg::render_ctrl (ras, sl, renb, m_slider1)
}
5 version differences and specific applications 1) AGG2.3 version
At present, it is very difficult to download, early projects have been applied, did not continue to update!
The following code scales the rectangle:
Ras.reset ()
Agg::path_storage ps
Ps.move_to (30pr 30)
Ps.line_to (50 and 30)
Ps.line_to (50 and 50)
Ps.line_to (30pr 50)
Ps.line_to (30pr 30)
Agg::trans_affine mtx
/ / enlarge the Abscissa by 2 times and the ordinate by 3 times
Mtx*= agg::trans_affine_scaling (2,3)
/ / Abscissa translation 100, ordinate translation 300, positive number to right, negative number to left
Mtx*=agg::trans_affine_translation (100100)
Typedefagg::conv_transform ell_ct_type
Ell_ct_type ctell (ps,mtx); / / Matrix transformation
Typedef agg::conv_strokeell_cc_cs_type
Ell_cc_cs_typecsccell (ctell)
Ras.add_path (ctell)
2) AGG2.4/2.5 version
Agg::trans_affine mtx
Mtx.scale (0.5, 0.5); / / the x-axis is reduced to half of its original size.
Mtx.rotate (agg::deg2rad (40)); / / rotate 30 degrees
Mtx.translate (100,100); / / Xpeny coordinates are translated by 100,100 respectively.
Typedefagg::conv_transform ell_ct_type
Ell_ct_type ctell (ps,mtx); / / Matrix transformation
Typedef agg::conv_strokeell_cc_cs_type
Ell_cc_cs_type csccell (ctell)
Ras.add_path (csccell)
6. Translation from agg_trans_affine.h
In the Cartesian coordinate system (Cartesian coordinates) affine transformation (affine transformation) is a linear transformation (set at the beginning). They are free to rotate (rotation), zoom (scaling), translate (translation) and cut transform (skewing). After any affine transformation, the line segment is still a line segment, and she can never program a curve.
In a word, any matrix transformation can be realized by a series of discrete transformations.
The original text is as follows:
/ / = trans_affine
/ /
/ / See Implementation agg_trans_affine.cpp
/ /
/ / Affine transformation are lineartransformations in Cartesiancoordinates
/ / (strictly speaking not only inCartesian, but for the beginning wewill
/ / think so). They are rotation, scaling,translation and skewing.
/ / After any affine transformation a linesegment remains a linesegment
/ / and it will never become a curve.
/ /
/ / There will be no math about matrixcalculations, since it has been
/ / described many times. Ask yourself avery simple question:
/ / "why do we need to understand anduse some matrix stuff insteadof just
/ / rotating, scaling and so on ".Theanswers are:
/ /
/ / 1. Any combination of transformationscan be done by only 4multiplications
/ / and 4 additions in floatingpoint.
/ / 2. One matrix transformation isequivalent to the number ofconsecutive
/ / discrete transformations,i.e. The matrix "accumulates" alltransformations
/ / in the order of theirsettings. Suppose we have 4 transformations:
/ / * rotate by 30 degrees
/ / * scale X to 2.0
/ / * scale Y to 1.5
/ / * move to (100100)
/ / The result will depend on theorder of these transformations
/ / and the advantage of matrixis that the sequence of discret calls:
/ / rotate (30), scaleX (2.0), scaleY (1.5), move (100100)
/ / will have exactly the sameresult as the following matrixtransformations:
/ /
/ / affine_matrix m
/ / m * = rotate_matrix (30)
/ / m * = scaleX_matrix (2.0)
/ / m * = scaleY_matrix (1.5)
/ / m * = move_matrix (100100)
/ /
/ / m.transform_my_point_at_last (x, y)
/ /
/ / What is the good of it? In real life wewill set-up the matrix onlyonce
/ / and then transform many points, letalone the convenience to set any
/ / combination of transformations.
/ /
/ / So, how to use it? Very easy-literallyas it's shown above. Notquite
/ / let us write a correct example:
/ /
/ / agg::trans_affine m
/ / m * = agg::trans_affine_rotation (30.0 * 3.1415926 / 180.0)
/ / m * = agg::trans_affine_scaling (2.0pm 1.5)
/ / m * = agg::trans_affine_translation (100.0, 100.0)
/ / m.transform (& x, & y)
/ /
/ / The affine matrix is all you need toperform any lineartransformation
/ / but all transformations have originpoint (0J0). It means that we needto
/ / use 2 translations if we want to rotatesometing around (100100):
/ /
/ / m * = agg::trans_affine_translation (- 100.0); / / move to (0jue 0)
/ / m * = agg::trans_affine_rotation (30.0 * 3.1415926 / 180.0); / / rotate
/ / m * = agg::trans_affine_translation (100.0, 100.0); / / move back to (100100)
/ /-
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.