JPH0478973A - Method for calculating cosine value from vector - Google Patents
Method for calculating cosine value from vectorInfo
- Publication number
- JPH0478973A JPH0478973A JP2193697A JP19369790A JPH0478973A JP H0478973 A JPH0478973 A JP H0478973A JP 2193697 A JP2193697 A JP 2193697A JP 19369790 A JP19369790 A JP 19369790A JP H0478973 A JPH0478973 A JP H0478973A
- Authority
- JP
- Japan
- Prior art keywords
- value
- coordinate
- square
- cosine
- vector
- 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.)
- Pending
Links
Landscapes
- Complex Calculations (AREA)
- Image Analysis (AREA)
Abstract
(57)【要約】本公報は電子出願前の出願データであるた
め要約のデータは記録されません。(57) [Summary] This bulletin contains application data before electronic filing, so abstract data is not recorded.
Description
この発明は、画像回転における回転角のコサイン値を算
出する方法に関する。The present invention relates to a method for calculating a cosine value of a rotation angle in image rotation.
ビットマツプシステムを構成するパーソナルコンピュー
タ等において、ビットマツプ画像の回転表示を行う場合
における回転角のコサイン値を算出する方法としては、
従来、以下に示すような方法がある。
■第7図(a )に示すような方向ベクトル(a 、b
)が与えられている場合に、
cosθ=a / Va工+b” ・(1)
の値を、浮動小数点表示を用い、ニュートンラプソン法
等の数値計算アルゴリズムを利用して計算する方法。
■上記(1)式の計算を固定小数点表示を用いて、第7
図(b)に例示するような開へい計算等の方法を用いて
行う方法。
■第7図(c )に示すように各方向毎にコサイン値の
テーブルを用意し、与えられた方向ベクトルに対するコ
サイン値をそのテーブルを参照して求める方法。
これらの方法の特徴としては、■は高精度の計算が可能
であり、■は中精度の計算が可能であり、■は■、■よ
りも高速にコサイン値の導出が可能であるという点があ
げられる。The following is a method for calculating the cosine value of the rotation angle when rotating and displaying a bitmap image in a personal computer that constitutes a bitmap system.
Conventionally, there are methods as shown below. ■Directional vectors (a, b) as shown in Figure 7 (a)
) is given, cosθ=a/Va+b” ・(1)
A method of calculating the value of by using a floating point representation and a numerical calculation algorithm such as the Newton-Raphson method. ■Calculating the above formula (1) using fixed-point representation,
A method using a method such as a spread calculation as exemplified in Figure (b). (2) A method in which a table of cosine values is prepared for each direction as shown in FIG. 7(c), and the cosine value for a given direction vector is determined by referring to the table. The characteristics of these methods are that ■ is capable of high-precision calculations, ■ is capable of medium-precision calculations, and ■ is capable of deriving cosine values faster than ■ and ■. can give.
ところで、上記■、■の方法は計算が複雑であるため大
きな実行モジュールを必要とし、計算に時間がかかると
いう欠点がある。また、■の方法は大きなデータ領域を
必要とし、しかも、算出可能なコサイン値はテーブルに
載せられた特定の方向のものに限られるという欠点があ
る。
そのため、比較的小さなビットマツプ画像(文字、アイ
コン等)を高速に回転する必要がある場合、例えば、建
築CADシステム等のアプリケーションにおいてしばし
ば見られる文字列の斜め表示を行うような場合には、上
記従来のいずれの方法も適していない。
そこで、この発明の目的は、回転角のコサイン値の算出
を、大きなデータ領域を必要とせず、小さな実行モジュ
ールで高速に行うことができるベクトルからのコサイン
値算出方法を提供することにある。By the way, the above methods (1) and (2) have the drawback that the calculations are complicated and require a large execution module, and the calculations take a long time. Furthermore, method (2) requires a large data area, and furthermore, the cosine values that can be calculated are limited to those in a specific direction listed in the table. Therefore, when it is necessary to rotate relatively small bitmap images (characters, icons, etc.) at high speed, for example when displaying character strings diagonally, which is often seen in applications such as architectural CAD systems, the above-mentioned conventional Neither method is suitable. SUMMARY OF THE INVENTION An object of the present invention is to provide a method for calculating a cosine value of a rotation angle from a vector, which does not require a large data area and can be performed at high speed with a small execution module.
上記目的を達成するため、この発明のベクトルからのコ
サイン値算出方法は、画像表示装置において画像を回転
表示するために、ベクトルで与えられた方向の基準座標
軸に対する角度のコサイン値を算出する方法であって、
算出精度を与えるための数値を設定し、上記ベクトルで
与えられた方向に基づきブレーゼンハムのアルゴリズム
に従って順次座標点を求めると共に、求めた座標点の座
標原点からの距離の二乗値を求め、その二乗値を上記設
定値の二乗値と比較して、その二乗値が上記設定値の二
乗値以上になったときに、その二乗値とその座標点の一
つ前に求めた座標点の座標原点からの距離の二乗値のう
ちのいずれか上記設定値の二乗値に近いかを求め、近い
ほうの二乗値を与える座標点の上記基準座標軸に対応す
る座標値と上記設定値とから上記コサイン値を算出する
ようにしたことを特徴としている。In order to achieve the above object, a method of calculating a cosine value from a vector according to the present invention is a method of calculating a cosine value of an angle in a direction given by a vector with respect to a reference coordinate axis in order to rotate and display an image on an image display device. There it is,
Set a numerical value to give the calculation accuracy, calculate the coordinate points sequentially according to Bresenham's algorithm based on the direction given by the vector above, calculate the square value of the distance of the calculated coordinate point from the coordinate origin, and calculate the square value. is compared with the square value of the above set value, and when the square value is greater than or equal to the square value of the above set value, the square value and the coordinate origin of the coordinate point calculated one point before that coordinate point are calculated. Find which of the squared values of the distance is closer to the square of the above set value, and calculate the above cosine value from the coordinate value corresponding to the above reference coordinate axis of the coordinate point that gives the closer square value and the above set value. It is characterized by the fact that it is made to do so.
以下、この発明を図示の実施例により詳細に説明する。
第1図はこの発明の一実施例のコサイン値算出方法を実
現するためのシステム構成図である。
この第1図において、lは入力装置であり、この入力装
置1により、方向ベクトル(a 、b )と、計算精度
を与えるための数値M(以下、精度Mと呼ぶ)が入力さ
れる。また、2は、上記入力データに基づいて、第3図
に示すように、ブレーゼンハムのアルゴリズムに従って
、座標原点(0,0)から座標点(a 、b )の方向
に向かって、離散的な直線上を進行し、進行方向の離散
座標値(図の黒丸で示す点の座標値)を計算する装置で
あり、3は、進行距離(のの2乗、すなわち上記離散座
標値を与える座標点と座標原点との距離の2乗を計算す
る装置である。上記装置2は後述するように、上記装置
3によって計算され1ニI22かM2に最も近くなった
座標点のX座標値を出力装置4により出力する。このX
座標値はMcosθの近似値を与える。
第2図は本実施例の手順を示すフローチャートである。
ステップS1において入力ベクトル(a 、b )と精
度Mを入力し、ステップS2でブレーゼンハムのアルゴ
リズムに必要とされる各制御パラメータの初期化を行う
。そして、ステップS3において計算開始座標(Xa、
Yo)を(0,0)に設定し、進行距離gの2乗を0に
設定する。
次に、ステップS4からステップs6に進む。
ステップS4では、ブレーゼンハムのアルゴリズムに従
って、一連の離散的直線上の座標(xo、yo)。
(X r、Y +)、・−、(Xn、Yn)、=−を生
成する(第3図参照)。ステップS5では、ステップS
4で求めた座標値に基づいてCの計算を行う。この(”
の計算は一つ前の座標値を用いて行う。すなわち、(X
n。
Yn)の次の点(Xn+、、Yn++)を導出したとき
、(Xn−。
Yn+、)と(0,0)との距M 1 n +、の計算
は、(Xn、Yn)と(0,0)との距離I2nを用い
て行う。第4図(a )に示すようにX方向に進行した
場合は、Qn”1′・ρn′÷2Xn+1となり、第4
図(b )に示すようにY方向に進行した場合は、ln
+12・ln2+ 2 Yn〒1となる。また、第4図
(c )に示すように斜め方向に進行した場合は、(l
n+、2=Qn’+ 2 (Xn+ Yn+ 1 )と
なる。ステップS6では、ステップs5で求めたln
+ 、 2がMl+に最も近くなったかどうかを判定す
る。すなわち、(ln”15M2かどうかを判定し、1
2n”H”<M’であればステップS4に戻り、In+
、12M”になれば、i2n 4 、 !とQn2のい
ずれがM2に近いかを比べてその近いほうの2乗値を与
える座標点のX座標値をステップS7で出力する。
上記ステップS7で出力されたX座標値はMc。
Sθの近似値を与えるものであり、この値をLcとする
と、
Lc=Mcosθ−EC−(2)
但し、j Ec 1< 1
と表すことができる。そして、コサイン値はLc/Mに
より求めることができるか、コサイン値はIより小さい
ために、2進数計算で行う回転画像の座標値の計算には
そのまま用いることかできず上記Lcの値を用いる。こ
の場合、原画像を縦および横にM倍に拡大したものを回
転し、その結果得られた座標値をMて除すことにより回
転画像の座標値を得ることができる。例えば、第5図に
示すようにサイズがWXHの2値画像をθだけ左に回転
する場合を考えると、第6図に示すように、拡大した画
像の格子間隔はMとなり、X方向のn番目の点を回転し
て得られた点のX座標値(Xn)は、Xn=n XLc
/M −・・c3)となる。なお、上記回
転して得られた点のY座標値(Yn)は、第2図のアル
ゴリズムでX座標値と同時に得られるY座標値をサイン
値とし、これをLsとすると、
Yn=n xLs/M −(4)となる
。
また、回転画像のサイズをWrXHrとすると、上記(
2)式と(3)式とから、
Wr=W(Mcosθ−Ec)/M
=Wcosθ−WEc/M
Hr=H(Mcosθ−EC)/M
=Hcosθ−HEc/M
となる。従って、原画像のW、F(がM以下であれば、
回転画像のWr、Hrは1ドツトの誤差で求まることが
わかる。
また、回転画像の方向は平均的には約45°/M単位で
決定されることがわかる。従って、例えば、M=64=
2@とすると、約0.7′単位で回転することができる
。この角度は人間の目では区別できない程の角度であり
、実用に十分絶えうる精度である。 なお、Mを大きく
すればするほど精度はあがるが、あまり大きくすると計
算速度が遅くなるので、用途に応じて妥当な数値に設定
することが望ましい。なお、Mが64程度であれば、従
来例で述べた他の方法に比べてかなり速い計算速度を得
ることが確認されている。
【発明の効果]
以上より明らかなように、この発明のベクトルからのコ
サイン値算出方法は、算出精度を与えるための数値を設
定し、ベクトルで与えられた方向に基づきブレーゼンハ
ムのアルゴリズムに従って順次座標点を求めると共に、
求めた座標点の座標原点からの距離の二乗値を求め、そ
の二乗値を上記設定値の二乗値と比較して、その二乗値
が上記設定値の二乗値以上になったときに、その二乗値
とその座標点の一つ前に求めた座標点の座標原点からの
距離の二乗値のうちのいずれが上記設定値の二乗値に近
いかを求め、近いほうの二乗値を与える座標点の上記基
準座標軸に対応する座標値と上記設定値とから上記コサ
イン値を算出するようにしているので、入力データに基
づき四則計算によりコサイン値を算出することができ、
従来例の■、■のように複雑な計算をする場合に比べて
計算速度を速くすることができ、また、従来例の■のよ
うに大きなデータ領域を必要とせず、算出可能なコサイ
ン値がテーブルに載せられた特定の方向のらのに限られ
るということもないため、文字やアイコン等の比較的小
さなビットマツプ画像を用いたヒットマップノステム上
のアブリケーンヨンに有効であり、特にCAD、CAM
、CAIには非常に有効である。Hereinafter, the present invention will be explained in detail with reference to illustrated embodiments. FIG. 1 is a system configuration diagram for realizing a cosine value calculation method according to an embodiment of the present invention. In FIG. 1, l is an input device, through which a direction vector (a 1 , b 2 ) and a numerical value M for giving calculation accuracy (hereinafter referred to as accuracy M) are input. In addition, 2 is a discrete straight line drawn from the coordinate origin (0, 0) toward the coordinate point (a, b) according to Bresenham's algorithm, as shown in FIG. 3 is a device that calculates discrete coordinate values in the traveling direction (coordinate values of points indicated by black circles in the figure), and 3 is a device that calculates the traveling distance (the square of This is a device that calculates the square of the distance from the coordinate origin.As will be described later, the device 2 outputs the X coordinate value of the coordinate point that is calculated by the device 3 and is closest to 1, I22 or M2. This is output by
The coordinate values give an approximate value of Mcosθ. FIG. 2 is a flowchart showing the procedure of this embodiment. In step S1, input vectors (a 1 , b 2 ) and precision M are input, and in step S2, each control parameter required for Bresenham's algorithm is initialized. Then, in step S3, the calculation start coordinates (Xa,
Yo) is set to (0,0), and the square of the traveling distance g is set to 0. Next, the process advances from step S4 to step s6. In step S4, coordinates (xo, yo) on a series of discrete straight lines are determined according to Bresenham's algorithm. (X r, Y +), .-, (Xn, Yn), =- is generated (see Fig. 3). In step S5, step S
Calculate C based on the coordinate values obtained in step 4. this("
The calculation is performed using the previous coordinate values. That is, (X
n. When the next point (Xn+,, Yn++) of (Xn-. Yn+,) and (0,0) is derived, the distance M 1 n +, between (Xn-. , 0) using the distance I2n. As shown in Fig. 4(a), if the vehicle moves in the X direction, Qn"1'・ρn'÷2Xn+1, and the
As shown in figure (b), when proceeding in the Y direction, ln
+12・ln2+ 2 Yn〒1. In addition, if it progresses in an oblique direction as shown in Figure 4(c), (l
n+, 2=Qn'+ 2 (Xn+ Yn+ 1). In step S6, ln obtained in step s5
+, 2 is closest to Ml+. That is, determine whether (ln"15M2), and
If 2n"H"<M', return to step S4 and In+
, 12M'', compare which of i2n 4, ! and Qn2 is closer to M2, and output the X coordinate value of the coordinate point that gives the square value of the closer one in step S7. Output in step S7 above. The X coordinate value obtained gives an approximate value of McSθ, and if this value is Lc, then Lc=Mcosθ−EC−(2) However, it can be expressed as j Ec 1<1. The value can be determined by Lc/M, or because the cosine value is smaller than I, it cannot be used as is to calculate the coordinate values of the rotated image using binary calculation, and the above Lc value is used.In this case, the value of Lc is used. , the coordinate values of the rotated image can be obtained by rotating the original image enlarged vertically and horizontally by M times and dividing the resulting coordinate values by M. For example, as shown in FIG. Considering the case where a binary image of size WXH is rotated to the left by θ, as shown in Figure 6, the grid spacing of the enlarged image is M, and by rotating the n-th point in the X direction, The X coordinate value (Xn) of the obtained point is Xn=n XLc
/M -...c3). In addition, the Y coordinate value (Yn) of the point obtained by the above rotation is given as the sine value of the Y coordinate value obtained at the same time as the X coordinate value by the algorithm in Figure 2, and this is set as Ls, then Yn = n x Ls /M - (4). Also, if the size of the rotated image is WrXHr, then the above (
From Equation 2) and Equation (3), Wr=W(Mcosθ-Ec)/M=Wcosθ-WEc/M Hr=H(Mcosθ-EC)/M=Hcosθ-HEc/M. Therefore, if W and F (of the original image are less than or equal to M),
It can be seen that Wr and Hr of the rotated image can be determined with an error of one dot. Furthermore, it can be seen that the direction of the rotated image is determined on average in units of about 45°/M. Therefore, for example, M=64=
2@, it can be rotated in approximately 0.7' units. This angle is indistinguishable to the human eye, and is accurate enough for practical use. Note that the larger M is, the higher the accuracy is, but if it is too large, the calculation speed will be slow, so it is desirable to set it to an appropriate value depending on the purpose. It has been confirmed that when M is about 64, calculation speed is considerably faster than that of the other methods described in the conventional example. [Effects of the Invention] As is clear from the above, the method of calculating a cosine value from a vector according to the present invention sets a numerical value to give calculation accuracy, and sequentially points coordinates according to Bresenham's algorithm based on the direction given by the vector. Along with seeking
Find the square value of the distance of the obtained coordinate point from the coordinate origin, compare the square value with the square value of the above setting value, and when the square value is greater than or equal to the square value of the above setting value, the square value is calculated. Find out which of the square values of the distance from the coordinate origin of the previous coordinate point and the previous coordinate point is closer to the square value of the above set value, and select the coordinate point that gives the closest square value. Since the cosine value is calculated from the coordinate value corresponding to the reference coordinate axis and the set value, the cosine value can be calculated by four arithmetic calculations based on the input data.
The calculation speed can be faster than when performing complex calculations as in the conventional example ■ and ■, and it does not require a large data area as in the conventional example ■, and the cosine value that can be calculated can be Because it is not limited to a specific orientation of the table, it is effective for printing on a hit map system using relatively small bitmap images such as characters and icons, and is especially effective for CAD, CAM
, is very effective for CAI.
第1図はこの発明の一実施例を実現するためのシステム
構成図、第2図は上記実施例の手順を示すフローチャー
ト、第3図は上記実施例における座標点の求め方を説明
する図、第4図は上記座標点と座標原点との距離の二乗
の求め方を説明する図、第5図および第6図は上記実施
例で求めたコサイン値を用いて画像回転した場合の誤差
を説明する図、第7図は従来例を説明する図である。FIG. 1 is a system configuration diagram for realizing an embodiment of the present invention, FIG. 2 is a flowchart showing the procedure of the above embodiment, and FIG. 3 is a diagram explaining how to obtain coordinate points in the above embodiment. Fig. 4 is a diagram explaining how to calculate the square of the distance between the above coordinate point and the coordinate origin, and Figs. 5 and 6 explain the error when rotating an image using the cosine value obtained in the above example. FIG. 7 is a diagram illustrating a conventional example.
Claims (1)
、ベクトルで与えられた方向の基準座標軸に対する角度
のコサイン値を算出する方法であって、 算出精度を与えるための数値を設定し、上記ベクトルで
与えられた方向に基づきブレーゼンハムのアルゴリズム
に従って順次座標点を求めると共に、求めた座標点の座
標原点からの距離の二乗値を求め、その二乗値を上記設
定値の二乗値と比較して、その二乗値が上記設定値の二
乗値以上になったときに、その二乗値とその座標点の一
つ前に求めた座標点の座標原点からの距離の二乗値のう
ちのいずれが上記設定値の二乗値に近いかを求め、近い
ほうの二乗値を与える座標点の上記基準座標軸に対応す
る座標値と上記設定値とから上記コサイン値を算出する
ようにしたことを特徴とするベクトルからのコサイン値
算出方法。(1) A method of calculating the cosine value of an angle with respect to a reference coordinate axis in a direction given by a vector in order to rotate and display an image on an image display device. Based on the direction given by Bresenham's algorithm, find the coordinate points sequentially, find the square value of the distance of the found coordinate point from the coordinate origin, compare the square value with the square value of the above setting value, and calculate the value. When the square value is greater than or equal to the square value of the above setting value, which of the square value and the square value of the distance from the coordinate origin of the coordinate point calculated one point before that coordinate point is the above setting value. Cosine from a vector, characterized in that the cosine value is calculated from the coordinate value corresponding to the reference coordinate axis of the coordinate point giving the closer square value and the set value. Value calculation method.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| JP2193697A JPH0478973A (en) | 1990-07-20 | 1990-07-20 | Method for calculating cosine value from vector |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| JP2193697A JPH0478973A (en) | 1990-07-20 | 1990-07-20 | Method for calculating cosine value from vector |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| JPH0478973A true JPH0478973A (en) | 1992-03-12 |
Family
ID=16312279
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| JP2193697A Pending JPH0478973A (en) | 1990-07-20 | 1990-07-20 | Method for calculating cosine value from vector |
Country Status (1)
| Country | Link |
|---|---|
| JP (1) | JPH0478973A (en) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US7532204B2 (en) * | 2004-09-01 | 2009-05-12 | Sharp Kabushiki Kaisha | Coordinate input system and coordinate input method |
-
1990
- 1990-07-20 JP JP2193697A patent/JPH0478973A/en active Pending
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US7532204B2 (en) * | 2004-09-01 | 2009-05-12 | Sharp Kabushiki Kaisha | Coordinate input system and coordinate input method |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US4667236A (en) | Television perspective effects system | |
| CN105913417B (en) | Geometrical constraint pose method based on perspective projection straight line | |
| CN106778347B (en) | A kind of reversible DecryptDecryption method of arrow grid geodata based on trigonometric function | |
| US20250259353A1 (en) | Method and system for generating pedestrian thermodynamic diagram | |
| CN104424841A (en) | Map display apparatus and display method of character strings on map | |
| CN117806468A (en) | IMU-based cursor control method and device, storage medium, computer equipment | |
| CN108921000A (en) | Head angle mark, prediction model training, prediction technique, equipment and medium | |
| CN116182839A (en) | Method, device, electronic equipment and storage medium for determining aircraft attitude | |
| JPH0478973A (en) | Method for calculating cosine value from vector | |
| CN116932119B (en) | Virtual screen display method, device, equipment and computer-readable storage medium | |
| CN116051929A (en) | Instrument panel reading training and identifying method based on three-dimensional simulation sample generation | |
| Shu et al. | On unified optical flow field | |
| JPH0785266A (en) | Image rotation device | |
| CN112464696A (en) | Image processing method, device, equipment and storage medium | |
| CN117012295B (en) | A two-dimensional gas-liquid interface curve reconstruction method | |
| JP2756128B2 (en) | Display system | |
| JPH03296877A (en) | Curve plotting device | |
| JPH03209499A (en) | Forming method for outline font and drawing device for the same | |
| CN112230837A (en) | Method for changing viewing angle in three-dimensional dynamic geometric system | |
| JPH04168581A (en) | Approximate curve generating method for hyperellipse | |
| CN111179174B (en) | Image stretching method and device based on face recognition points | |
| JPS63140382A (en) | Plotting method for polygonal approximation of circles | |
| JPH07134781A (en) | 3D object rotation instruction method | |
| CN120693634A (en) | Information processing device, information processing method, and information processing program | |
| JP3166875B2 (en) | Arc calculation method for curve section input of figure processing device |