zoukankan      html  css  js  c++  java
  • 判断点在直线左侧或者右侧

    直线$$line(ep,bp)$$的直线方程如下: $$frac{ep(2) - bp(2)}{ep(1)-bp(1)} = frac{ep(2)-x}{ep(1)-y}$$ 当 y = p(1) 时,上述式子等于 $$frac{ep(2) - bp(2)}{ep(1)-bp(1)} = frac{ep(2)-x}{ep(1)-p(1)}$$ $$x=ep(2)- frac{(ep(2)-bp(2))(ep(1)-p(1))}{ep(1)-bp(1)}$$ 当点p在$$line(ep,bp)$$左侧时,由于 $$x>p(2)$$,因此: $$ep(2)- frac{(ep(2)-bp(2))(ep(1)-p(1))}{ep(1)-bp(1)}<p(2)$$ 假设 $$ep(1)-bp(1)>0$$, 则: $$(ep(2)-p(2))(ep(1)-bp(1))- (ep(2)-bp(2))(ep(1)-p(1))<0$$


    matlab 代码如下:

    1 function [ret] = checkPoint(bp,ep,p)
    2      if ep(1) < bp(1) 
    3             tmp = ep; 
    4             ep = bp; 
    5             bp = tmp; 
    6      end 
    7           ret = (ep(2) - p(2)) * (ep(1) - bp(1)) - (ep(2) - bp(2))*(ep(1) - p(1)) < 0; 
    8 end    
  • 相关阅读:
    数学
    数学
    Computer Science
    数学
    Computer Science
    元学习
    数学
    数学
    数学
    数学
  • 原文地址:https://www.cnblogs.com/-lee/p/4254080.html
Copyright © 2011-2022 走看看