/* ** Copyright (C) 2005 Antonin Stefanutti ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ///////////////////////////////////////////////////////////////////////////////////////// //an instance of this class is 3D an affine plane essentially used for an object's face //That way we have the 3D affine plane containing the face //the normal is (a,b,c) and a point belonging to this affine plane is p = 0 + d*(a,b,c) class Plane3D { public var a:Number; public var b:Number; public var c:Number; public var d:Number; ///////////////////////////////////////////////////////////////////////////////////////// //constructor public function Plane3D() { a = b = c = d = 0; } ///////////////////////////////////////////////////////////////////////////////////////// //define this plane given 3 distinct points public function set(p0x:Number,p0y:Number,p0z:Number,p1x:Number,p1y:Number,p1z:Number,p2x:Number,p2y:Number,p2z:Number):Void{ var ux:Number = p1x - p0x; var uy:Number = p1y - p0y; var uz:Number = p1z - p0z; var vx:Number = p2x - p0x; var vy:Number = p2y - p0y; var vz:Number = p2z - p0z; a = uy * vz - vy * uz; b = uz * vx - vz * ux; c = ux * vy - vx * uy; var n:Number = Math.sqrt(a*a + b*b + c*c); a /= n; b /= n; c /= n; d = -(a*p0x + b*p0y + c*p0z); } ///////////////////////////////////////////////////////////////////////////////////////// //rotate this plane around the 3 reference axis (i,j,k) by angles (a,b,c) defined //by previously computed cos and sin of each angle public function rotmEx0(ca:Number, sa:Number, cb:Number, sb:Number, cc:Number, sc:Number):Void { var h:Number = a*cc - b*sc; b = a*sc + b*cc; a = h; h = a*cb - c*sb; c = a*sb + c*cb; a = h; h = b*ca - c*sa; c = b*sa + c*ca; b = h; } ///////////////////////////////////////////////////////////////////////////////////////// //spin this point around affine axis defined by point(0) + vector(q) //by passing prevously computed variables depending on vector(q) //and the rotation angle (radian) public function rotmQx0(sw:Number, cw:Number, cx:Number, cy:Number, cz:Number):Void { var r1:Number = a; var r2:Number = b; var r3:Number = c; a = r1*(1-2*(cy*cy+cz*cz)) + r2*(2*cx*cy-2*cw*cz) + r3*(2*cw*cy+2*cx*cz); b = r1*(2*cx*cy+2*cw*cz)+r2*(1-2*(cx*cx + cz*cz)) + r3*((-2)*cw*cx+2*cy*cz); c = r1*((-2)*cw*cy + 2*cx*cz) + r2*(2*cw*cx+2*cy*cz) + r3*(1-2*(cx*cx + cy*cy)); } ///////////////////////////////////////////////////////////////////////////////////////// //scale this affine plane by scale factors (sx,sy,sz) with pivot = point(0) public function sclx0(sx:Number, sy:Number, sz:Number):Void { d *= Math.sqrt((sx*a)*(sx*a) + (sy*b)*(sy*b) + (sz*c)*(sz*c)); a /= sx; b /= sy; c /= sz; var n:Number = Math.sqrt(a*a + b*b + c*c); a /= n; b /= n; c /= n; } ///////////////////////////////////////////////////////////////////////////////////////// }