`

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);
        }

分享到:
评论

相关推荐

    Matrix Not Positive Definite(解决方案).md

    项目中碰到的问题

    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 ...

    adaptive filter theory(Simon.Haykin)(answer)

    A matrix is **positive definite** if all its eigenvalues are positive. This implies that: \[ a^T R a &gt; 0 \] for any non-zero vector \( a \). **Example of Positive Definite and Singular Matrix:** ...

    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....

    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...

    python的矩阵计算.docx

    is_positive_definite = all(eigenvalue &gt; 0 for eigenvalue in np.linalg.eigvals(matrix)) ``` **第十二章:Python求协方差矩阵** 协方差矩阵描述了随机变量之间的变化关系,可以使用`numpy.cov`: ```python ...

    楚列斯基分解 希尔伯特矩阵 解方程组 数值计算 代码

    System.out.println("Matrix is not symmetric positive definite."); return; } // 解方程组 Matrix b = new Matrix(n, 1); // 方程组的右端项 // ... 设置b的值 ... Matrix x = cd.solve(b); // 解x // ...

    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 ...

    matlab语句查询.zip_matlab语言chaxun_matlab语言查询

    disp('x is positive'); else disp('x is non-positive'); end ``` 循环结构也是常用的一部分,包括`for`和`while`循环,用于重复执行一段代码。例如: ```matlab for i = 1:10 disp(i); end ``` 函数是MATLAB...

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

    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...

    MATLAB自学一本通代码集

    disp('x is positive'); else disp('x is non-positive'); end % 数组操作 A = zeros(3); % 创建一个3x3的全零矩阵 B = A(:,2:end); % 提取第二列到最后一列 ``` 其次,MATLAB提供了丰富的内置函数和工具箱,如...

    用LDLT分解求解方程组c++

    std::cerr &lt;&lt; "Matrix is not positive definite." ; return 1; } // 求解方程组 x = ldlt_A.solve(b); // 输出解 std::cout ; return 0; } ``` 这段代码首先定义了一个3x3的系数矩阵A和一个3维的常数...

    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 ...

Global site tag (gtag.js) - Google Analytics