`

Matrix 之 isPositive

    博客分类:
  • AS3
阅读更多

     即根据3个点即width height 求 matrix 中的正反面,这个问题有两种解法,一个是观察法 还有一个是用向量的叉积来算。


/**
 *点与点的关系有9种位置关系,两点相等返回0,其余的关系安 1-8,逆时针计算,比如第一象限为1
 *p_target相对于p_orgin的关系
 * -----------------------------------------------------------------------------
 *          ++       |      -+     |      --      |     +-       |(sX,sY)
 *      p1_0  p2_0   |  p1_0  p2_0 |  p1_0  p2_0  |  p1_0  p2_0  |
 *        1    7     |    1    3   |    1    7    |    1     3   |(pointPositionNo)
 *        2    8     |    2    4   |    2    8    |    2     4   |
 *        3    1     |    3    5   |    3    1    |    3     5   |
 *        4    2     |    4    6   |    4    2    |    4     6   |
 *        5    3     |    5    7   |    5    3    |    5     7   |
 *        6    4     |    6    8   |    6    4    |    6     8   |
 *        7    5     |    7    1   |    7    5    |    7     1   |
 *        8    6     |    8    2   |    8    6    |    8     2   |
 *                   |             |              |              |
 *           正       |      反      |      正       |       反      |(正反)
 *                   |             |              |              |
 *         r=q       |    r=PI-q   |     r=PI-q   |      r=q     |p0_p1 于+X轴角度 q
 *                   |             |              |              |
 *          (1)      |      (2)    |      (3)     |      (4)     |            
 * -----------------------------------------------------------------------------
 *
 * 相关尺寸的计算
 * 运用到 DPI Matrix Point
 * eg:
 *      1.将物理尺寸转化为屏幕尺寸
 *         p0,p1,p2,p3(mmm),etc.根据 USER_SCREEN_DPI 和 MMM_PER_INCH 转化为 p0,p1,p2,p3(pix)
 *
 *      2.根据p0,p1,p2,p3,width(pix),height(pix)计算matrix
 *         a.p0 - p1 = (实际)width | p0 - p2 = (实际)height
 *            计算|sX| |sY|
 *         b.根据p0,p1,p2,p3,countPositive2NegativeBy4Point计算图像的正反
 *             isPositive = countPositive2NegativeBy3Point(p0,p1,p2);
 *         c.p0 - p1 的角度
 *             radian = countRadianByP0AndP1(p0,p1);
 *         d.根据公式
 *             var a:Number = sX * Math.cos(radian);
 *               var b:Number = sX * Math.sin(radian);
 *               var c:Number = -isPositive*sY * Math.sin(radian);
 *               var d:Number = isPositive*sY * Math.cos(radian);
 *               var tx:Number = p0.x;
 *               var ty:Number = p0.y;
 *
 *       3.将屏幕尺寸转化为物理尺寸
 *         
 *
*/   
        //返回p0和p1形成的角度(弧度制 -PI - PI)
        public static function countRadianByP0AndP1(p0:Point,p1:Point):Number {
            var dx:Number = p1.x - p0.x;
            var dy:Number = p1.y - p0.y;
            var radian:Number = Math.atan2(dy,dx);
            return radian;
        }
       
        public static function cout3PointWHToMatrix(
                                              p0:Point,
                                              p1:Point,
                                              p2:Point,
                                              originPixWidth:Number,
                                              originPixHeight:Number):Matrix {
            var w:Number = Point.distance(p0,p1);
            var h:Number = Point.distance(p0,p2);
            var sX:Number = w/originPixWidth;
            var sY:Number = h/originPixHeight;
            var radian:Number = countRadianByP0AndP1(p0,p1);
            var isPositive:int = countPositive2NegativeBy3Point(p0,p1,p2);
           
            var a:Number = sX * Math.cos(radian);
             var b:Number = sX * Math.sin(radian);
             var c:Number = -isPositive*sY * Math.sin(radian);
             var d:Number = isPositive*sY * Math.cos(radian);
             var tx:Number = p0.x;
             var ty:Number = p0.y;
            return new Matrix(a,b,c,d,tx,ty);
        }
       
       
        //p0_p1 X p0_p3(叉积) > 0 则p1 在p0_p3向量的左侧,则图片为反的,同理 < 0, p1在 p0_p3 的右侧
        //图片为正, =0 则p1在p0_p3上,图片为中间
        public static function countPositive2NegativeBy3Point(p0:Point,p1:Point,p2:Point):int {
            var p0_p1:Point = p1.subtract(p0);//计算向量p0_p1下同
            var p0_p2:Point = p2.subtract(p0);
            var p0_p3:Point = p0_p1.add(p0_p2);
            var p0_p1Xp0_p3:Number = p0_p1.x*p0_p3.y - p0_p3.x*p0_p1.y;
            return p0_p1Xp0_p3>0?1:(p0_p1Xp0_p3<0?-1:0);
        }

分享到:
评论

相关推荐

    THE CP-MATRIX APPROXIMATION PROBLEM

    symmetric matrix A is completely positive (CP) if there exists an entrywise nonnegative matrix V such that A = V V T . In this paper, we study the CP-matrix approximation problem of projecting a ...

    Covariance Estimation for High Dimensional Data Vectors Using the Sparse Matrix Transform

    The resulting estimator is positive de nite and well-conditioned even when the sample size is limited. Experiments on standard hyperspectral data sets show that the SMT covariance estimate is ...

    SDP.zip_If..._SDP matlab_sdp

    this examples chekh if a matrix is definite positive

    pcg.rar_As One_Hermitian_hermitian matrix_pcg_preconditioned

    Here, the coefficient matrix A must be Hermitian and positive semi-definite. If the null-space of A is more than one dimensional, i.e. A*X=0 allows multiple linear independent solutions, the code ...

    Gauss-Seidel-Method.zip_To the Letter

    Though it can be applied to any matrix with non-zero elements on the diagonals, convergence is only guaranteed if the matrix is either diagonally dominant, or symmetric and positive definite....

    gauss_seidel.rar_To the Letter

    Though it can be applied to any matrix with non-zero elements on the diagonals, convergence is only guaranteed if the matrix is either diagonally dominant, or symmetric and positive definite....

    Graphs and Matrices.pdf

    emphasis on matrix techniques is even greater than what is found in these and perhaps the subject matter discussed here might be termed linear algebraic graph theory to highlight this aspect. After ...

    Advanced Linear Algebra

    When Is a Tensor Product Zero?, 367 Coordinate Matrices and Rank, 368 Characterizing Vectors in a Tensor Product, 371 Defining Linear Transformations on a Tensor Product, 374 The Tensor Product of...

    nrfPCA的MATLAB实现

    1)x: your data matrix samples in rows and variables in columns. 2)LV: How many variables to use from data, if not specified all variables are used. 3)method: Optional, will be selected automatically. ...

    Gauss-Seidel-method.zip_After Method_liebmann

    Though it can be applied to any matrix with non-zero elements on the diagonals, convergence is only guaranteed if the matrix is either diagonally dominant, or symmetric and positive definite.

    求解广义瑞利商的极值问题,包括局部最优值和全局最优值的论证

    Given symmetric matrices B,D ∈ R n×n and a symmetric positive definite matrix W ∈ R n×n , maximizingthe sum of the Rayleighquotientx ? Dx andthe gener- alized Rayleigh quotient x ? Bx x ? Wx on ...

    Error analysis

    decomposition of a positive definite symmetric matrix, can be roughly halved if Winograd's identity is used to compute the inner products involved. Floating-point error bounds for these algorithms are...

    人口模型的处理,二胎影响

    of the Chinese population from 2015 to 2030 is forecasted by improving the Leslie matrix population prediction algorithm, as well as the progressive deduction method and the queue element method based...

    算法导论_英文第三版

    28.3 Symmetric positive-definite matrices and least-squares approximation 832 29 Linear Programming 843 29.1 Standard and slack forms 850 29.2 Formulating problems as linear programs 859 29.3 The ...

    imnoise2.m

    % matrix R is assigned three values. If R(x, y) = % 0, the noise at (x, y) is pepper (black). If % R(x, y) = 1, the noise at (x, y) is salt % (white). If R(x, y) = 0.5, there is no noise % assigned to...

    SQP Algorithm C++ code in VS2005 IDE

    In the SQP loop, the approximate QP should be a convex Quadratic Programming, in which the matrix Q = ▽2f(xk) should be positive semidefinite, Q ≥ 0. Actually, the Q is the Hessian matrix of the ...

    Introduction to Algorithms, 3rd edtion

    28.3 Symmetric positive-definite matrices and least-squares approximation 832 29 Linear Programming 843 29.1 Standard and slack forms 850 29.2 Formulating problems as linear programs 859 29.3 The ...

    算法导论 第三版 英文原版 高清文字版

    28.3 Symmetric positive-definite matrices and least-squares approximation 832 29 Linear Programming 843 29.1 Standard and slack forms 850 29.2 Formulating problems as linear programs 859 29.3 The ...

    算法导论-introduction to algrithms 3rd edition

    28.3 Symmetric positive-definite matrices and least-squares approximation 832 29 Linear Programming 843 29.1 Standard and slack forms 850 29.2 Formulating problems as linear programs 859 29.3 The ...

Global site tag (gtag.js) - Google Analytics