Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to render ellipses and polygons by agg::ellipse in AGG

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you AGG agg::ellipse how to render ellipses and polygons, I believe that most people do not understand, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

8.1 introduction

A circle is a kind of ellipse, but the radius of the major axis and the minor axis is equal. In AGG, the radius of the major and minor axes of the ellipse must be given before the ellipse can be drawn. The Abscissa radius is called rx and the ordinate radius is called ry. And you can specify whether to draw clockwise or counterclockwise. Provides a parameter for rendering inscribed polygons.

8.2 function definition

Class definition file: include/agg_ellipse.h

Class constructor: ellipse (double x, double y, double rx, double ry)

Unsigned num_steps=0, boolcw=false)

Parameter description: X is the X coordinate of the center, y is the Y coordinate of the center, rx is the X radius of the circle, ry is the Y radius of the circle, when rx is not equal to ry, what is rendered is actually an ellipse, the specific adjustable parameters according to the third and fourth parameters can understand that the circle can be a flat circle, not necessarily a well-behaved circle. If you specify a num_ tes value, you are building a circle enclosing polygon. Whether cw is rendered clockwise or counterclockwise.

8.3 example playback 1) render solid circle

Description: in the process of rendering, skip the agg::conv_stroke display extension line (that is, the boundary, which is illustrated by an example below), and draw a solid circle.

The code is as follows:

Agg::ellipse ell (200550100)

Ras.add_path (ell)

Agg::render_scanlines_aa_solid (ras,sl,renb,agg::rgba8 (255j0pl 0))

Ras.reset ()

2) render hollow circle

Agg::ellipse ell (200550100)

Typedef agg::conv_stroke

< agg::ellipse >

Ell_stroke

Ell_stroke stroke (ell)

Ras.add_path (stroke)

Agg::render_scanlines_aa_solid (ras,sl,renb,agg::rgba8 (255j0pl 0))

Ras.reset ()

3) render the hollow circle of the dashed line

Agg::ellipseell (200550100)

Typedef agg::conv_dash ell_cd_type

Ell_cd_type cdccell (ell)

Cdccell.add_dash (5 and 5)

Typedef agg::conv_stroke ell_cc_cs_type

Ell_cc_cs_type csccell (cdccell)

Ras.add_path (csccell)

Rensl.color (agg::rgba8 (255j0pl 0))

Agg::render_scanlines (ras,sl,rensl)

Ras.reset ()

The drawing of dotted lines is realized by building an agg::conv_dash template and then creating it for agg::conv_stroke.

4) affine transformation

Mainly for rotation, translation, scaling, center offset, if you need to return to the original position, translation must be necessary, which is different from the agg::conv_contour extension contour.

The code is as follows:

Agg::ellipse ell (200550100)

/ / coordinate conversion

Agg::trans_affine mtx

Mtx.scale (0.5); / / the x axis has been reduced to half of its original size.

Mtx.rotate (agg::deg2rad (30)); / / rotate 30 degrees

Mtx.translate (200200); / / XPerry Y coordinates are translated 100 respectively.

Typedef agg::conv_transform ell_ct_type

Ell_ct_type ctell (ell,mtx); / / Matrix transformation

Typedef agg::conv_dash ell_cd_type

Ell_cd_type cdccell (ctell)

Cdccell.add_dash (5 and 5)

Typedef agg::conv_stroke ell_cc_cs_type

Ell_cc_cs_type csccell (cdccell)

Extracted from: http://www.cnblogs.com/CoolJie/archive/2011/04/27/2030122.html

5) render circle inscribed polygon

Description: specify that the fifth parameter of the constructor is 12 to build a dodecagon.

The code is as follows:

Agg::ellipse ell (300, 300, 130, 130, 130, 130, 12)

Agg::conv_stroke stroke (ell)

Ras.add_path (stroke)

Agg::render_scanlines_aa_solid (ras,sl,renb,agg::rgba8 (255j0pl 0))

8.4Perplexity of approximation_scale

Description: many classes have this function, but the actual meaning of this function is not understood!

Example inline void ellipse::approximation_scale (double scale):

Agg::ellipse ell (300300240240)

Ell.approximation_scale (0.0001); / / straight line

Ell.approximation_scale (0.001); / / rectangle

Ell.approximation_scale (0.005); / / regular heptagon

Ell.approximation_scale (0.0025); / / regular Pentagon

Agg::conv_strokestroke2 (ell)

Agg::render_scanlines_aa_solid (ras,sl,renb,agg::rgba8 (255j0pl 0))

Ras.reset ()

These are all the contents of the article "how agg::ellipse renders ellipses and polygons in AGG". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report