AGG第二十课 agg::ellipse 方法approximation_scale()

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AGG第二十课 agg::ellipse 方法approximation_scale()相关的知识,希望对你有一定的参考价值。

 献给:任何一种方案都是一种折中的选择,任何一种替代方案都可能会实现同样的效果。而这完全取决于你是如何思考定位的。请教是学,自学是学,只不过可以站在巨人的肩膀上,你可以看的更加清楚或许走的更远。

摘自:http://franko.github.io/agg-intro/vertex-source.html

    In the previous section we have seen agg::path_storage object. While this object is very flexible and can be used to describe all kind of geometric shapes there are a few other vertex source primitive types. Actually there are not so many of them and we will just discuss the agg::ellipse object because it will be also useful to illustrate some important idea.

    The agg::ellipse does not share anything with a agg::path_storage in term of C++ class hierarchy, all the they have in common is that they implement the basic methods of a vertex source. You may wonder why the ellipse object can be useful if you can describe it with a agg::path_storage. The answer is that this latter needs to store a fixed number of vertices that approximate the ellipse for all the possible resolution of the image. The problem is that if you draw a small circle a few vertices can be enough but if the circle is big you are going to need a lot of vertices to have a decent approximation. We will see that with an agg::ellipse object the number of points will be adapted on the fly, you just need to use the approximation_scale()method. Actually the agg::ellipse does not store all the coordinates of the vertices but generetes them on the fly when needed using the mathematical equations. As a side effect you will have also a benefit in term of memory usage because an ellipse object will use a very small amount of memory indipendently of the approximation level that you may request.

    At this point we need to explain the approximation_scale() method. approximation_scale() we need to go back to the coordinates specifications. The coordinates are actually given as double precision floating point number and they may or may not map directly to pixel coordinates. For example we can map some logical coordinates ranging from 0 to 1 to an huge viewport of size 1280x1280. The problem at this point is that an agg::ellipse object does not know the mapping between logical coordinates and viewport coordinates. So the idea is that to let agg::ellipse adjust correctly the level of approximation you should call the method approximation_scale() and pass as an argument the ratio between the viewport coordinates and the logical coordinates. So in the example of the viewport of size 1280x1280 we would need to use approximation_scale() with an scale argument of 1280.

We will see later that the approximation_scale() is also important with some kind of transformation like Bezier curves that are supposed to generate smooth curves based on a few vertices and some mathematical equations.


以上是关于AGG第二十课 agg::ellipse 方法approximation_scale()的主要内容,如果未能解决你的问题,请参考以下文章

ParisGabriel:Python全栈工程师(0基础到精通)教程 第二十课(包模块 的导入)

python第二十课——math模块中常用的函数

Golang✔️走进 Go 语言✔️ 第二十课 原子操作 & 互斥体

Golang✔️走进 Go 语言✔️ 第二十课 原子操作 & 互斥体

Linux云自动化运维第二十课

AGG第二十六课 裁剪功能