Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is there a logic error in Line::isOnEdge() function? #5

Open
zhuzy-2018 opened this issue Jul 28, 2021 · 1 comment
Open

is there a logic error in Line::isOnEdge() function? #5

zhuzy-2018 opened this issue Jul 28, 2021 · 1 comment

Comments

@zhuzy-2018
Copy link

in iou.cpp line27-29,it is said:
if (abs(pp1^pp2) < EPS &&
pp1pp2 < EPS)
return true;
which from my point of view is |pp1|
|pp2|sin(pp1,pp2)<EPS and |pp1||pp2|*cos(pp1,pp2)<EPS.
but it doesnt mean that p is on p1p2.

why dont you use the value of cos/sin of pp1 and pp2 to judge if p in on line p1p2?

@weiquanmao
Copy link
Member

简单解释一下:

这个接口是判断点是否在线段

  1. abs(pp1^pp2) < EPS(即sin(pp1,pp2)<EPS)说明点PP1P2共线(EPS为容差值)
  2. 满足1)的条件下还存在三种可能
    a. PP1P2线段上(P1_P_P2为180度)
    b. PP1P2线段的延长线上(P1_P_P2为0度)
    c. P在一个相对很远的位置(P1_P_P2为0度,类似于b,算是一种退化?)
  3. 通过pp1pp2 < EPS排除情况b)和c)

应该是等效于你提到的sin/cos,对2)中不满足的情况无法排除,而且存在除零的风险

我的方法存在归一化的问题,建议对PP1PP2进行一下归一化

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants