CN102034260B - Trigonometric function calculating method in three-dimensional (3D) graphics rendering - Google Patents
Trigonometric function calculating method in three-dimensional (3D) graphics rendering Download PDFInfo
- Publication number
- CN102034260B CN102034260B CN2010106218488A CN201010621848A CN102034260B CN 102034260 B CN102034260 B CN 102034260B CN 2010106218488 A CN2010106218488 A CN 2010106218488A CN 201010621848 A CN201010621848 A CN 201010621848A CN 102034260 B CN102034260 B CN 102034260B
- Authority
- CN
- China
- Prior art keywords
- sequence number
- cos
- sin
- function
- big angle
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Abstract
The invention discloses a trigonometric function calculating method in three-dimensional graphics (3D) rendering. The method comprises the following steps of: decomposing a radian r into a big angle t and a small angle k; searching the sine function value sin(t) and the cosine function cos(t) of the big angle t according to pre-created one-to-one corresponding relation between each sequence number and the sine function value of the big angle corresponding to the sequence number, and the one-to-one corresponding relation between each sequence number and the cosine function value of the big angle corresponding to the sequence number; calculating the sine function value sin(k) and the cosine function cos(k) of the small angle k by using the power series expansion equation of the sine function value sin(t) and the cosine function cos(t); and calculating the sine function value sin(r) and the cosine function cos(r) of the radian r according to a trigonometric function and a difference formula. By the method, the trigonometric function calculation efficiency in 3D rendering can be improved.
Description
Technical field
The present invention relates to the 3D graphics rendering technology, the trigonometric function computing method in particularly a kind of 3D graph rendering.
Background technology
In the 3D graphic package, often use the computing of trigonometric function evaluation, for example cursive script generation in particIe system, Billboard algorithm, the scene, skeleton cartoon module etc.The operation efficiency of trigonometric function can influence the effect of figure, improves trigonometric function operation efficient and helps the smooth operation of program, strengthens the performance of particle effect etc.
In the prior art, according to the calculating that the math library XNAMath in the DirectX SDK kit realizes trigonometric function, introduce as follows in detail:
DirectX SDK is the SDK of the multimedia interface scheme of Microsoft; Wherein most important parts is the graph rendering interface; DirectX SDK kit provides math library XNAMath, and math library XNAMath has made a lot of efficiency optimizations to the algorithm of 3D figure.For example, XNAMath has realized the trigonometric function algorithm that the SSE instruction is optimized, and this algorithm utilizes the power series expansion of sinusoidal and cosine, is deployed into 12 values of coming the approximate treatment trigonometric function.
Wherein, the computing formula of sine function is following:
sin(V)=V-V^3/3!+V^5/5!-V^7/7!+V^9/9!-V^11/11!+V^13/13!-V^15/15!+V^17/17!-V^19/19!+V^21/21!-V^23/23!,
The computing formula of cosine function is following:
cos(V)=1-V^2/2!+V^4/4!-V^6/6!+V^8/8!-V^10/10!+V^12/12!-V^14/14!+V^16/16!-V^18/18!+V^20/20!-V^22/22!。
And other trigonometric functions can obtain through the calculating conversion of sine function and cosine function, and for example tan equals sine function divided by the cosine function value, and the cotangent function equals the cosine function value divided by sine function.
It is thus clear that the main power series expansion that passes through 12 is realized the calculating of trigonometric function in the prior art, because the item number of power series expansion is too much, so operation efficiency is lower.
Summary of the invention
In view of this, the present invention provides the trigonometric function computing method in a kind of 3D graph rendering, can improve the trigonometric function operation efficient in the 3D graph rendering.
For solving the problems of the technologies described above, technical scheme of the present invention is achieved in that
Trigonometric function computing method in a kind of 3D graph rendering, this method comprises:
Calculate the ephemeral data m=r*256/ (2* π) corresponding according to radian r,, calculate the big angle t=n*2* pi/2 56 corresponding with r according to sequence number n then to conduct of ephemeral data m round numbers part and r corresponding sequence number n with r, and the calculating little angle k=r-t corresponding with r;
Set up the one-to-one relationship of the sine function at each sequence number and this pairing big angle of sequence number in advance; And the one-to-one relationship of the cosine function value at each sequence number and this pairing big angle of sequence number, search sine function sin (t) and the cosine function value cos (t) of big angle t according to said corresponding relation and the pairing sequence number n of big angle t;
Calculate sine function sin (k) and the cosine function value cos (k) of little angle k, wherein, cos (k)=1-0.5*k*k, sin (k)=k-(1/6.0) * k*k*k;
Calculate sine function sin (r) and the cosine function value cos (r) of radian r, wherein, sin (r)=sin (t+k)=sin (t) * cos (k)+cos (t) * sin (k), cos (r)=cos (t+k)=cos (t) * cos (k)-sin (t) * sin (k).
The method of the one-to-one relationship of the said sine function of setting up each sequence number and this pairing big angle of sequence number is:
Set up sequence number 0 and sin (0*2* pi/2 56) corresponding relation, sequence number 1 and sin (1*2* pi/2 56) corresponding relation, sequence number 2 and sin (2*2* pi/2 56) corresponding relation ... and the corresponding relation of sequence number 255 and sin (255*2* pi/2 56).
The method of the one-to-one relationship of the said cosine function value of setting up each sequence number and this pairing big angle of sequence number is:
Set up sequence number 0 and cos (0*2* pi/2 56) corresponding relation, sequence number 1 and cos (1*2* pi/2 56) corresponding relation, sequence number 2 and cos (2*2* pi/2 56) corresponding relation ... and the corresponding relation of sequence number 255 and cos (255*2* pi/2 56).
This method further comprises:
Calculate tan value tg (r)=sin (r)/cos (r) according to sine function sin (r) that is calculated and cosine function value cos (r).
This method further comprises:
Calculate cotangent functional value ctg (r)=cos (r)/sin (r) according to sine function sin (r) that is calculated and cosine function value cos (r).
According to technical scheme provided by the present invention; Radian r is decomposed into big angle t and little angle k; One-to-one relationship according to the sine function at each sequence number of setting up in advance and this pairing big angle of sequence number; And the one-to-one relationship of the cosine function value at each sequence number and this pairing big angle of sequence number is searched sine function sin (t) and the cosine function value cos (t) of big angle t; Utilize two power series expansion to calculate sine function sin (k) and the cosine function value cos (k) of little angle k again, calculate sine function sin (r) and the cosine function value cos (r) of radian r at last according to trigonometric function and difference formula.It is thus clear that; The present invention adopts look-up table to calculate sine function sin (t) and the cosine function value cos (t) of big angle t; Adopt power series method to calculate sine function sin (k) and the cosine function value cos (k) of little angle k, thereby finally obtain sine function sin (r) and the cosine function value cos (r) of radian r, computing method are simple; Avoided adopting the too much power series expansion of item number in the prior art, can improve the trigonometric function operation efficient in the 3D graph rendering.
Description of drawings
Fig. 1 is the process flow diagram of the trigonometric function computing method in a kind of 3D graph rendering provided by the present invention.
Embodiment
For making the object of the invention, technical scheme and advantage clearer, below with reference to the accompanying drawing embodiment that develops simultaneously, scheme according to the invention is done to specify further.
Core concept of the present invention is: radian r is decomposed into big angle t and little angle k; One-to-one relationship according to the sine function at each sequence number of setting up in advance and this pairing big angle of sequence number; And the one-to-one relationship of the cosine function value at each sequence number and this pairing big angle of sequence number is searched sine function sin (t) and the cosine function value cos (t) of big angle t; Utilize two power series expansion to calculate sine function sin (k) and the cosine function value cos (k) of little angle k again, calculate sine function sin (r) and the cosine function value cos (r) of radian r at last according to trigonometric function and difference formula.
Fig. 1 is the process flow diagram of the trigonometric function computing method in a kind of 3D graph rendering provided by the present invention.As shown in Figure 1, this method may further comprise the steps:
Step 101; Calculate the ephemeral data m=r*256/ (2* π) corresponding according to radian r with r; To conduct of ephemeral data m round numbers part and r corresponding sequence number n, calculate the big angle t=n*2* pi/2 56 corresponding then with r according to sequence number n, and the calculating little angle k=r-t corresponding with r.
In this step, the unit of r, t, k all is a radian.
Method to this step illustrates: suppose that radian r equals pi/2, and m=r*256/ (2* π)=64 then, it is 64 that the m round numbers is partly obtained n, then obtains big angle t=n*2* pi/2 56=pi/2, then obtains little angle k=r-t=0.
Need to prove that when m does not have integral part, then being regarded as integral part is 0, similarly, when m does not have fraction part, then being regarded as fraction part is 0.
Step 102; Set up the one-to-one relationship of the sine function at each sequence number and this pairing big angle of sequence number in advance; And the one-to-one relationship of the cosine function value at each sequence number and this pairing big angle of sequence number, search sine function sin (t) and the cosine function value cos (t) of big angle t according to said corresponding relation and the pairing sequence number n of big angle t.
Since the value of radian r more than or equal to 0 and less than 2 π (radian 0 is regarded as equating with radian 2 π; Then the maximal value of radian must be less than 2 π); Then the value of ephemeral data is less than 256; The maximal value of the sequence number that the integral part that ephemeral data is got obtains is 255, and therefore, the possible value of sequence number is 0,1,2...255.
When sequence number was 0, the sine function at the big angle corresponding with this sequence number was sin (a 0*2* pi/2 56), when sequence number is 1; Sine function sin (1*2* pi/2 56) to the corresponding big angle of this sequence number; When sequence number is 2, to the sine function sin (2*2* pi/2 56) at the corresponding big angle of this sequence number ...; When sequence number is 255, to the sine function sin (255*2* pi/2 56) at the corresponding big angle of this sequence number.
Based on above-mentioned analysis, can know that the method for one-to-one relationship of the sine function of setting up each sequence number and this pairing big angle of sequence number is following:
Set up sequence number 0 and sin (0*2* pi/2 56) corresponding relation, sequence number 1 and sin (1*2* pi/2 56) corresponding relation, sequence number 2 and sin (2*2* pi/2 56) corresponding relation ... and the corresponding relation of sequence number 255 and sin (255*2* pi/2 56).
Similarly, when sequence number was 0, the sine function at the big angle corresponding with this sequence number was cos (a 0*2* pi/2 56); When sequence number is 1, to the sine function cos (1*2* pi/2 56) at the corresponding big angle of this sequence number, when sequence number is 2; Sine function cos (2*2* pi/2 56) to the corresponding big angle of this sequence number; ..., when sequence number is 255, to the sine function cos (255*2* pi/2 56) at the corresponding big angle of this sequence number.
Based on above-mentioned analysis, can know that the method for one-to-one relationship of the cosine function value of setting up each sequence number and this pairing big angle of sequence number is following:
Set up sequence number 0 and cos (0*2* pi/2 56) corresponding relation, sequence number 1 and cos (1*2* pi/2 56) corresponding relation, sequence number 2 and cos (2*2* pi/2 56) corresponding relation ... and the corresponding relation of sequence number 255 and cos (255*2* pi/2 56).
In addition; Also can be according to the sine function of same radian square equal 1 with the quadratic sum of cosine function value; Perhaps as radian a during less than pi/2; The sine function of radian a equals the cosine function value of the difference of pi/2 and a; And other mutual rules of conversion of sine and cosine functions in the prior art, the one-to-one relationship of the sine function at each sequence number of being set up and this pairing big angle of sequence number is changed, thereby obtained the one-to-one relationship of the cosine function value at each sequence number and this pairing big angle of sequence number.
Method to searching illustrates: suppose that n that step 101 is calculated is 64 and big angle t=n*2* pi/2 56=pi/2; The sine function of then in said corresponding relation, searching the big angle pi/2 corresponding with sequence number 64 is sin (a 64*2* pi/2 56), and the cosine function value of the big angle pi/2 corresponding with sequence number 64 is cos (a 64*2* pi/2 56).
Step 103 is calculated sine function sin (k) and the cosine function value cos (k) of little angle k, wherein, and cos (k)=1-0.5*k*k, sin (k)=k-(1/6.0) * k*k*k.
Above-mentioned sine function sin (k) and cosine function value cos (k) obtain according to power series expansion of the prior art, because k<(2* pi/2 56), therefore as long as launch two demands that just can reach single precision.
Need to prove that above-mentioned steps 102 and 103 execution sequencing do not have special qualification, can first execution in step 102, back execution in step 103 also can first execution in step 103, back execution in step 102, but also executed in parallel step 102 and step 103.
Step 104, sine function sin (r) and the cosine function value cos (r) of calculating radian r, wherein, sin (r)=sin (t+k)=sin (t) * cos (k)+cos (t) * sin (k), cos (r)=cos (t+k)=cos (t) * cos (k)-sin (t) * sin (k).
The foundation of aforementioned calculation is trigonometric function of the prior art and difference formula.
Further, also can calculate tan value tg (r)=sin (r)/cos (r), cotangent functional value ctg (r)=cos (r)/sin (r) according to sine function sin (r) that is calculated and cosine function value cos (r).
So far, this flow process finishes.
Through several embodiment said method is illustrated below.
For example, following code is used to set up the one-to-one relationship of the sine function at each sequence number and this pairing big angle of sequence number:
Again for example; Following code adopts C++ to realize following steps: first; Search sine function sin (t) and the cosine function value cos (t) of big angle t according to corresponding relation and the pairing sequence number n of big angle t, the second, calculate sine function sin (k) and the cosine function value cos (k) of little angle k; The 3rd, sine function sin (r) and the cosine function value cos (r) of calculating radian r.Wherein, a in the following code is equivalent to cos (k), and b is equivalent to sin (k), and x is equivalent to sin (t), and y is equivalent to cos (t), and s is equivalent to sin (r), and c is equivalent to cos (r):
Again for example, following code adopts the SSE instruction to realize and above-mentioned code identical functions that the travelling speed of only following code is more quick:
In the 3D of reality graph rendering, trigonometric function computing method provided by the present invention possess application scenarios widely.
For example, in the prior art, the Billboard technology can make in the 3D scene all the time towards the camera lens graphing.In conjunction with the present invention, step is following:
At first, according to the deflection angle of the coordinate axis of Billboard paster after, calculate the trigonometric function value of deflection angle with respect to conversion; The concrete method of calculating trigonometric function value can be with reference to above-mentioned steps 101 and 104 and embodiment; According to the trigonometric function value that is calculated confirm the Billboard paster towards, secondly, according to determined towards; Calculate the coordinate on four summits of Billboard paster, and render to rendering module and play up.
Again for example, the present invention also has application widely in the formation object at random, for example, and the cursive script in particle emitter, the scene etc.With the particle emitter is that example combines the present invention, and step is following:
At first; Generate the subobject of being launched according to trigger condition; Obtain the initial angle of subobject then at random, and calculate the trigonometric function value of initial angle, to confirm the initial transmissions direction; The concrete method of calculating trigonometric function value can be with reference to above-mentioned steps 101 and 104 and embodiment, at last according to determined initial transmissions direction TG operator object position and play up.
In a word; Trigonometric function computing method provided by the present invention can have application scenarios widely in the 3D graph rendering; Every step that relates to trigonometric function calculating all can adopt method of the present invention; The description of the foregoing description and application scenarios is not to be used to limit the present invention, is merely to illustrate.
To sum up; In the present invention; Radian r is decomposed into big angle t and little angle k; One-to-one relationship according to the sine function at each sequence number of setting up in advance and this pairing big angle of sequence number; And the one-to-one relationship of the cosine function value at each sequence number and this pairing big angle of sequence number searches sine function sin (t) and the cosine function value cos (t) of big angle t, utilizes two power series expansion to calculate sine function sin (k) and the cosine function value cos (k) of little angle k again, calculates sine function sin (r) and the cosine function value cos (r) of radian r at last according to trigonometric function and difference formula.It is thus clear that; The present invention adopts look-up table to calculate sine function sin (t) and the cosine function value cos (t) of big angle t; Adopt power series method to calculate sine function sin (k) and the cosine function value cos (k) of little angle k, thereby finally obtain sine function sin (r) and the cosine function value cos (r) of radian r, computing method are simple; Avoided adopting the too much power series expansion of item number in the prior art, can improve the trigonometric function operation efficient in the 3D graph rendering.
Adopt scheme of the present invention, compare with the C function, it is original 4 times that operation efficiency promotes, and compares with XNAMath, and it is 2.4 times that operation efficiency promotes.
And operational precision of the present invention is near 7 position effective digitals, than 6 position effective digitals of XNAMath lifting arranged also.
The above is merely preferred embodiment of the present invention, is not to be used to limit protection scope of the present invention.All within spirit of the present invention and principle, any modification of being done, be equal to replacement, improvement etc., all should be included within protection scope of the present invention.
Claims (5)
1. trigonometric function computing method in the 3D graph rendering is characterized in that this method comprises:
When needs carry out the 3D graph rendering through calculating trigonometric function,
Calculate the ephemeral data m=r*256/ (2* π) corresponding according to radian r,, calculate the big angle t=n*2* pi/2 56 corresponding with r according to sequence number n then to conduct of ephemeral data m round numbers part and r corresponding sequence number n with r, and the calculating little angle k=r-t corresponding with r;
Set up the one-to-one relationship of the sine function at each sequence number and this pairing big angle of sequence number in advance; And the one-to-one relationship of the cosine function value at each sequence number and this pairing big angle of sequence number, search sine function sin (t) and the cosine function value cos (t) of big angle t according to said corresponding relation and the pairing sequence number n of big angle t;
Calculate sine function sin (k) and the cosine function value cos (k) of little angle k, wherein, cos (k)=1-0.5*k*k, sin (k)=k-(1/6.0) * k*k*k;
Calculate sine function sin (r) and the cosine function value cos (r) of radian r, wherein, sin (r)=sin (t+k)=sin (t) * cos (k)+cos (t) * sin (k),
cos(r)=cos(t+k)=cos(t)*cos(k)-sin(t)*sin(k);
Carry out the 3D graph rendering according to said sine function sin (r) that calculates and cosine function value cos (r).
2. method according to claim 1 is characterized in that, the method for the one-to-one relationship of the said sine function of setting up each sequence number and this pairing big angle of sequence number is:
Set up sequence number 0 and sin (0*2* pi/2 56) corresponding relation, sequence number 1 and sin (1*2* pi/2 56) corresponding relation, sequence number 2 and sin (2*2* pi/2 56) corresponding relation ... and the corresponding relation of sequence number 255 and sin (255*2* pi/2 56).
3. method according to claim 2 is characterized in that, the method for the one-to-one relationship of the said cosine function value of setting up each sequence number and this pairing big angle of sequence number is:
Set up sequence number 0 and cos (0*2* pi/2 56) corresponding relation, sequence number 1 and cos (1*2* pi/2 56) corresponding relation, sequence number 2 and cos (2*2* pi/2 56) corresponding relation ... and the corresponding relation of sequence number 255 and cos (255*2* pi/2 56).
4. method according to claim 1 is characterized in that, this method further comprises:
Calculate tan value tg (r)=sin (r)/cos (r) according to sine function sin (r) that is calculated and cosine function value cos (r).
5. method according to claim 4 is characterized in that, this method further comprises:
Calculate cotangent functional value ctg (r)=cos (r)/sin (r) according to sine function sin (r) that is calculated and cosine function value cos (r).
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN2010106218488A CN102034260B (en) | 2010-12-27 | 2010-12-27 | Trigonometric function calculating method in three-dimensional (3D) graphics rendering |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN2010106218488A CN102034260B (en) | 2010-12-27 | 2010-12-27 | Trigonometric function calculating method in three-dimensional (3D) graphics rendering |
Publications (2)
Publication Number | Publication Date |
---|---|
CN102034260A CN102034260A (en) | 2011-04-27 |
CN102034260B true CN102034260B (en) | 2012-07-11 |
Family
ID=43887112
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN2010106218488A Active CN102034260B (en) | 2010-12-27 | 2010-12-27 | Trigonometric function calculating method in three-dimensional (3D) graphics rendering |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN102034260B (en) |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107783756A (en) * | 2016-08-31 | 2018-03-09 | 深圳市中兴微电子技术有限公司 | A kind of method and apparatus for obtaining angle correlation |
Family Cites Families (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20060253511A1 (en) * | 2005-05-06 | 2006-11-09 | Harris Corporation | RF broadcasting employing sinusoidal-cosine wave generation with plural look-up tables |
CN100458646C (en) * | 2006-06-15 | 2009-02-04 | 华为技术有限公司 | Trigonometric value determiner, determining method and telecommunicating apparatus therewith |
-
2010
- 2010-12-27 CN CN2010106218488A patent/CN102034260B/en active Active
Also Published As
Publication number | Publication date |
---|---|
CN102034260A (en) | 2011-04-27 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN102999910B (en) | Image depth calculating method | |
CN104103058B (en) | Image matching system and method | |
CN111612852B (en) | Method and apparatus for verifying camera parameters | |
CN107808395B (en) | Indoor positioning method based on SLAM | |
CN103592650B (en) | The three-dimensional sonar imaging system of graphic based processor and three-D imaging method thereof | |
CN104700393A (en) | Registration of multiple laser scans | |
CN104267396A (en) | Imaging method for three-dimensional diagram of radar detection range | |
CN112884902A (en) | Point cloud registration-oriented target ball position optimization method | |
CN103064565B (en) | A kind of localization method and electronic equipment | |
Boyle et al. | Performance portability strategies for grid C++ expression templates | |
CN102034260B (en) | Trigonometric function calculating method in three-dimensional (3D) graphics rendering | |
GB2571953A (en) | Single view tracking of cylindrical objects | |
CN113671523A (en) | Robot positioning method, device, storage medium and robot | |
CN102117501B (en) | Method and device for rendering three-dimensional lines | |
CN111949816B (en) | Positioning processing method, device, electronic equipment and storage medium | |
CN103940432B (en) | Posture determination method of star sensor | |
CN113034582A (en) | Pose optimization device and method, electronic device and computer readable storage medium | |
CN108268821A (en) | A kind of indoor and outdoor scene recognition method and device | |
CN104346797A (en) | Key pixel point matching method and device, and image matching method and device | |
CN113628284B (en) | Pose calibration data set generation method, device and system, electronic equipment and medium | |
CN103489212B (en) | The two-dimensional shapes corresponding method inspired based on user | |
JPS61261779A (en) | Generation of curve of second order signal | |
CN114489568A (en) | Random number generation method and device, storage medium and processor | |
CN106777640A (en) | A kind of method that Model array based on PDMS is replicated | |
CN103824310B (en) | A kind of method and device generating light literal with special effect |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C14 | Grant of patent or utility model | ||
GR01 | Patent grant |