`
- 浏览:
400998 次
- 性别:
- 来自:
深圳
-
转载:A Fast Algorithm for Rotating Bitmaps
A Fast Algorithm for Rotating Bitmaps By Karl Lager According to "Tricks of the Game Programming Gurus", rotating
a bitmap in real time generally isn't done because of the complex
math involved and slow speed. However, with a few optimizations
it can be done nearly as fast as bitmap scaling.
To start with, each pixel can be given x,y coordinates. To rotate
these by an angle t about the 0 axis , the new coordinates can be
plotted as (x',y') = (x cos(t) - y sin(t), y cos(t) + x sin(t)).
( for x = right, y = down, clockwise rotations. )
To convert a pixel on screen to the bitmap, the directions would be
reversed:
(x',y') = (x cos(t) + y sin(t), y cos(t) - x sin(t);
To rotate a whole bitmap, you can plot
( for y = min_y to max_y
for x = min_x to max_x
x' = (x cos (t) + y sin(t))
y' = (y cos(t) - x cos(t))
if (x', y') is in the bounds of the bitmap,
get pixel(x',y') and plot the pixel to (x,y) on screen.
)
Now, you might want to rotate the bitmap about an arbitrary pixel(x1',y1'),
and put it to an arbitrary point on screen(x1,y1), and to do this you
could get pixel(x'+ x1', y'+ y1') and put it to (x + x1, y + y1) on screen.
To speed this procedure up, you can start by taking the trig equations
out of the inner loop. The angle doesn't change, so these calculations
should only be done once.
double cosT,sinT;
cosT = cos(t);
sinT = sin(t);
for (y = min_y - y1; y <= max_y - y1; y++)
for (x = min_x - x1; x <= max_x - x1; x++)
{ x' = (x * cosT + y * sinT);
y' = (y * cosT - x * sinT);
if (x'+ x1', y'+ y1') is in the bounds of the bitmap,
get pixel(x'+ x1', y'+ y1') and plot the pixel to
(x + x1, y + y1) on screen.
}
Since x and y are incremented by a constant value, the code can be
streamlined further by removing the multiplications from the inner loop:
double cosT,sinT;
cosT = cos(t);
sinT = sin(t);
for (y = min_y - y1; y <= max_y - y1; y++)
{ x' = (min_x-x1) * cosT + y * sinT;
y' = y * cosT - (min_x-x1) * sinT;
for (x = min_x-x1; x <= max_x - x1; x++)
{ if (x'+ x1', y'+ y1') is in the bounds of the bitmap,
get pixel(x'+ x1',y'+ y1') and plot the pixel to
(x + x1,y + y1) on screen.
x' += cosT;
y' -= sinT;
}
}
Finally, remove the extra additions from the inner loops:
double cosT,sinT;
cosT = cos(t);
sinT = sin(t);
for (y = min_y; y <= max_y; y++)
{ x' = (min_x-x1) * cosT + (y-y1) * sinT + x1';
y' = (y-y1) * cosT - (min_x-x1) * sinT + y1';
for (x = min_x; x <= max_x; x++)
{ if (x', y') is in the bounds of the bitmap,
get pixel(x', y') and plot the pixel to
(x, y) on screen.
x' += cosT;
y' -= sinT;
}
}
Thus you have gone from doing 4 transcendental functions (or 4 lookups
and 4 multiplications if you are using lookup tables) per pixel to
doing 2 additions per pixel. That's going from instructions that take
a couple hundred CPU cycles with a coprocessor or thousands without
one to instructions that take one cycle.
Further gains can be made by making your max and min values exactly
fit the bounds of the bitmap and the video screen or window.
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
SMO算法是一种用于支持向量机(SVM)训练的快速算法,由John C. Platt在1998年提出,具有创新性和实用价值。此算法对处理大规模二次规划问题(QP)具有显著优势,极大地提升了SVM的学习速度与准确性,对机器学习领域...
【MaPle算法】是一种快速解决最大模式聚类问题的算法,主要针对大规模数据集中的模式挖掘。在数据挖掘领域,基于模式的聚类是一种重要技术,尤其在DNA微阵列数据分析、自动推荐系统和目标市场营销等应用中,能够发现...
在《Rete: A Fast Algorithm for the Many Pattern/Many Object Pattern Match Problem》这篇论文中,作者提出了一种名为Rete的高效算法,旨在解决在产生式规则系统中的模式匹配问题。这种算法尤其适用于处理大规模...
### Vertex Component Analysis (VCA): A Fast Algorithm for Unmixing Hyperspectral Data #### 引言 在遥感科学领域,尤其是针对高光谱成像技术的研究中,如何有效地解析混合像素中的各种物质(称为端元)及其...
《A fast learning algorithm for deep belief nets》是著名科学家Geoffrey Hinton于2006年发表的一篇具有里程碑意义的论文,它在神经网络和深度学习领域开辟了新的研究方向,对现代人工智能的发展产生了深远影响。...
### 基于交替方向法的联合稀疏向量快速恢复算法 在现代信号处理与机器学习领域,压缩感知(Compressive Sensing, CS)已成为一个活跃的研究领域,其核心目标是从测量数据中恢复稀疏信号。传统的压缩感知主要关注...
标题中的"A fast algorithm for the total variation model of image denoising"指的是一个图像去噪的快速算法,该算法基于全变差(Total Variation, TV)模型。全变差正则化是一种在图像处理领域广泛应用的技术,它...
It shows howtouse“complementarypriors”toeliminatetheexplaining- awayeffectsthatmakeinferencedifficultindenselyconnectedbeliefnets that have many hidden layers.
ASIFT_GPUd的论文PDF 演讲PPT 我们的GPU-ASIFT 实现 如下[2]。它旨在将CPU和GPU之间的流量保持在 最低水平。因此, 我们的GPU-ASIFT直接将图像输入到GPU,GPU会计算SIFT 关键点 和 描述符, 而无需返回到CPU。...
该算法相较于传统的利用快速傅里叶变换(Fast Fourier Transform, FFT)实现离散余弦变换(Discrete Cosine Transform, DCT)的方法,在计算复杂度上有了显著提高。DCT作为一种有效的信号处理工具,已经被广泛应用于...
《A Fast Learning Algorithm for Deep Belief Nets》一文由Geoffrey E. Hinton、Simon Osindero和Yee-Whye Teh撰写,发表于2006年。该论文提出了一种新的训练方法,能够有效地训练深层的信念网络。 #### 补充先验...
本资源“A fast learning algorithm for deep belief nets”很可能详细介绍了优化DBN学习速率和提高训练效率的方法。 深度信念网络的核心是层次化的概率模型,通常由多个受限玻尔兹曼机(Restricted Boltzmann ...
Pixeltrack: A fast adaptive algorithm for tracking non-rigid objects. In ICCV, pages 2480-2487, 2013 论文源代码.下载于http://u0016403263.user.hosting-agency.de/research_pixeltrack.html.非刚性跟踪算法...
The fast, greedy algorithm is used to initialize a slower learning procedure that fine-tunes the weights using a contrastive version of thewake-sleep algorithm. After fine-tuning, a networkwith three...
A Fast Greedy Algorithm for Outlier Mining,何增友,,The task of outlier detection is to find small groups of data objects that are exceptional when compared with rest large amount of data....
Sequential Minimal Optimization (SMO) Algorithm for Training Support Vector Machines SMO 算法是 John C. Platt 于 1998 年提出的一个快速算法,用于训练支持向量机(Support Vector Machines,SVM)。该算法...
以上知识点提供了对标题《A Fast Taboo Search Algorithm for the Job Shop Problem》和描述中提到的各个方面深入的理解。涉及的标签“Taboo Search”和“Nowicki”指明了算法的关键技术和主要研究者。此外,从部分...
The Kendall correlation is a non-parametric method that measures the strength of dependence between two sequences. Like Pearson correlation and Spearman correlation, Kendall correlation is widely ...
A Polynomial-time Algorithm for the Change-Making Problem Codeforces #10 E