root/as3/FLARToolKit/trunk/src/org/libspark/flartoolkit/core/types/FLARDoublePoint2d.as

リビジョン 4718, 4.7 kB (コミッタ: rokubou, コミット時期: 4 日 前)

FLARToolKit v4 core

Line 
1 /*
2  * PROJECT: FLARToolKit
3  * --------------------------------------------------------------------------------
4  * This work is based on the FLARToolKit developed by
5  *   R.Iizuka (nyatla)
6  * http://nyatla.jp/nyatoolkit/
7  *
8  * The FLARToolKit is ActionScript 3.0 version ARToolkit class library.
9  * Copyright (C)2008 Saqoosha
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  *
24  * For further information please contact.
25  *      http://www.libspark.org/wiki/saqoosha/FLARToolKit
26  *      <saq(at)saqoosha.net>
27  *
28  */
29 package org.libspark.flartoolkit.core.types
30 {
31         import org.libspark.flartoolkit.core.*;
32         /**
33          * データ型です。
34          * 2次元の浮動小数点方の点を格納します。
35          */
36         public class FLARDoublePoint2d
37         {
38                 public var x:Number;
39                 public var y:Number;
40                 /**
41                  * 配列ファクトリ
42                  * @param i_number
43                  * @return
44                  */
45                 public static function createArray(i_number:int):Vector.<FLARDoublePoint2d>
46                 {
47                         var ret:Vector.<FLARDoublePoint2d>=new Vector.<FLARDoublePoint2d>(i_number);
48                         for(var i:int=0;i<i_number;i++)
49                         {
50                                 ret[i]=new FLARDoublePoint2d();
51                         }
52                         return ret;
53                 }
54                 public function FLARDoublePoint2d(...args:Array)
55                 {
56                         switch(args.length) {
57                         case 0:
58                                 {//public function FLARDoublePoint2d()
59                                         this.x = 0;
60                                         this.y = 0;
61                                 }
62                                 return;
63                         case 1:
64                                 if(args[0] is FLARDoublePoint2d)
65                                 {
66                                         //public function FLARDoublePoint2d(i_src:FLARDoublePoint2d)
67                                         this.x=args[0].x;
68                                         this.y=args[0].y;
69                                         return;
70                                 }else if (args[0] is FLARIntPoint2d)
71                                 {
72                                         //public function FLARDoublePoint2d(i_src:FLARIntPoint2d)
73                                         this.x=(Number)(args[0].x);
74                                         this.y=(Number)(args[0].y);
75                                         return;
76                                 }
77                                 break;
78                         case 2:
79                                 {       //public function FLARDoublePoint2d(i_x:Number,i_y:Number)
80                                         this.x = Number(args[0]);
81                                         this.y = Number(args[1]);
82                                         return;
83                                 }
84                         default:
85                                 break;
86                         }
87                         throw new FLARException();
88                 }
89                 /**
90                  * p2-p1間の距離の二乗値を計算します。
91                  * @param i_p1
92                  * @param i_p2
93                  * @return
94                  */     
95                 public function sqDist( i_p1:FLARDoublePoint2d):Number
96                 {
97                         var x:Number,y:Number;
98                         x=this.x-i_p1.x;
99                         y=this.y-i_p1.y;
100                         return x*x+y*y;
101                 }
102                 public function sqDist_2(i_p1:FLARIntPoint2d):Number
103                 {
104                         var x:Number,y:Number;
105                         x=this.x-i_p1.x;
106                         y=this.y-i_p1.y;
107                         return x*x+y*y;
108                 }
109                 public static function crossProduct3Point( p1:FLARDoublePoint2d , p2:FLARDoublePoint2d , p3:FLARDoublePoint2d ):Number
110                 {
111                         return ( p2.x - p1.x ) * ( p3.y - p2.y ) - ( p2.y - p1.y ) * ( p3.x - p2.x ) ;
112                 }
113        
114                 public static function crossProduct3Point_2( p1:FLARDoublePoint2d , p2:FLARDoublePoint2d , p3_x:Number , p3_y:Number ):Number
115                 {
116                         return ( p2.x - p1.x ) * ( p3_y - p2.y ) - ( p2.y - p1.y ) * ( p3_x - p2.x ) ;
117                 }
118        
119                 public static function makeCenter( i_points:Vector.<FLARDoublePoint2d> , i_number_of_data:int , o_out:FLARDoublePoint2d ):void
120                 {
121                         var x:Number , y:Number ;
122                         x = y = 0 ;
123                         for( var i:int = i_number_of_data - 1 ; i >= 0 ; i-- ) {
124                                 x += i_points[i].x ;
125                                 y += i_points[i].y ;
126                         }
127                         o_out.x = x / i_number_of_data ;
128                         o_out.x = y / i_number_of_data ;
129                 }
130                
131                 public static function makeCenter_2( i_points:Vector.<FLARDoublePoint2d> , i_number_of_data:int , o_out:FLARIntPoint2d ):void
132                 {
133                         var lx:Number , ly:Number ;
134                         lx = ly = 0 ;
135                         for( var i:int = i_number_of_data - 1 ; i >= 0 ; i-- ) {
136                                 lx += i_points[i].x ;
137                                 ly += i_points[i].y ;
138                         }
139                         o_out.x = int(( lx / i_number_of_data )) ;
140                         o_out.y = int(( ly / i_number_of_data )) ;
141                 }
142        
143        
144                 public function setValue(i_src:FLARDoublePoint2d):void
145                 {
146                         this.x=i_src.x;
147                         this.y=i_src.y;
148                         return;
149                 }
150                 public function setValue_2(i_src:FLARIntPoint2d):void
151                 {
152                         this.x=Number(i_src.x);
153                         this.y=Number(i_src.y);
154                         return;
155                 }
156                 public function setValue_3(x:Number,y:Number):void
157                 {
158                         this.x=x;
159                         this.y=y;
160                         return;
161                 }
162
163                 public function sqNorm():Number
164                 {
165                         return this.x*this.x+this.y+this.y;
166                 }
167                 /**
168                  * この関数は、頂点を移動します。
169                  * @param i_tx
170                  * 移動する距離x
171                  * @param i_ty
172                  * 移動する距離y
173                  */
174                 public function translate(i_tx:Number,i_ty:Number):void
175                 {
176                         this.x+=i_tx;
177                         this.y+=i_ty;
178                 }
179         }
180
181 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。