定义线点的哪一侧.特殊情况 [英] Defining which side of a line point is. Special case

查看:77
本文介绍了定义线点的哪一侧.特殊情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了Matlab代码,该代码允许定义线点的哪一侧.它在很多情况下都可以正常工作,但是当它很奇怪时,我发现了一种特殊情况.这是代码:

I have written a Matlab code, which allows to define which side of a line point is. It works fine for many cases, but I've found one special case when it works weird. Here is the code:

clear all
close all
clc
polylineX = [9 15];
polylineY = [7 6];
hold on
for i = 1:27
    for j = 1:32
        point(1) = j-10;
        point(2) = i-101;
        pos = sign((polylineX(2) - polylineX(1)) * (point(2) - polylineY(1)) -...
                   (polylineY(2) - polylineX(1)) * (point(1) - polylineX(1)));

        if pos == 1
            plot(point(1),point(2),'r.','MarkerSize',5)
        elseif pos == -1
            plot(point(1),point(2),'m.','MarkerSize',5)
        elseif pos == 0
            plot(point(1),point(2),'k.','MarkerSize',5)
        end;
        pause(0.00000001);
    end;
end;
plot(polylineX,polylineY)

这是结果:

程序结果

红色表示左"位置,洋红色"表示右位置,黑色"表示行中的位置.您可以看到蓝线以及我要估计的相对位置.如您所见,绘制的结果与另一行一样.

Red color is for 'left' position, 'magenta' color is for right position, 'black' color is for the position on the line. You can see the blue line as well relative position to which I am trying to estimate. As you can see the result is drawn as it was for another line.

怎么了?

实现代码时,例如,在这里:

When implementing the code I looked, for example, here:

  1. 计算线点是

推荐答案

您的公式有误:

polylineY(2) - polylineX(1)

应该是

polylineY(2) - polylineY(1)

计算正确的行列式.

这篇关于定义线点的哪一侧.特殊情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆