(八)pcl-common篇-intersections.h

#include<pcl/point_cloud.h>
#include<pcl/point_types.h>
#include<pcl/visualization/pcl_visualizer.h> //cout endl

#include <pcl/common/intersections.h>

typedef pcl::PointXYZ PointT;

//求兩直線的交點(diǎn)或者倆平面的交線


int main()
{
    //(1)兩點(diǎn)線的交點(diǎn)菩暗,返回值:交點(diǎn)是否存在俊嗽。(點(diǎn)刑然,方向)
    //bool pcl::lineWithLineIntersection (const Eigen::VectorXf &line_a, const Eigen::VectorXf &line_b, Eigen::Vector4f &point, double sqr_eps=1e-4)
    //line_a:前三個(gè)是坐標(biāo),后三個(gè)是向量
    Eigen::VectorXf line_a(6);
    line_a(0) = 0;
    line_a(1) = 0;
    line_a(2) = 0;

    line_a(3) = 1;
    line_a(4) = 0;
    line_a(5) = 0;
    Eigen::VectorXf line_b(6);
    line_b(0) = 1;
    line_b(1) = 1;
    line_b(2) = 0;

    line_b(3) = 1;
    line_b(4) = 0;
    line_b(5) = 0;
    Eigen::Vector4f point;
    bool flag = pcl::lineWithLineIntersection(line_a, line_b, point, 1e-4);

    //(2)兩點(diǎn)線的交點(diǎn)报账,返回值:交點(diǎn)是否存在气破。(構(gòu)造函數(shù):pcl::ModelCoefficients)
    //bool pcl::lineWithLineIntersection(const pcl::ModelCoefficients & line_a, const pcl::ModelCoefficients & line_b, Eigen::Vector4f & point, double sqr_eps = 1e-4)
    pcl::ModelCoefficients line_1;
    pcl::ModelCoefficients line_2;
    //bool flag_1= pcl::lineWithLineIntersection(line_1, line_2, point,1e-4);//參數(shù)賦值失敗

    //(3)計(jì)算兩平面的交線
    //bool planeWithPlaneIntersection(const Eigen::Matrix<Scalar, 4, 1> &plane_a,const Eigen::Matrix<Scalar, 4, 1> &plane_b,Eigen::Matrix<Scalar, Eigen::Dynamic, 1> &line,double angular_tolerance)
    Eigen::Matrix<float, 4, 1> plane_a;
    Eigen::Matrix<float, 4, 1> plane_b;
    Eigen::Matrix<float, 4, 1> plane_c;
    plane_a(0, 0) = 1;// plane_a << 1, 1, 0, 0;//賦值方法二
    plane_a(1, 0) = 1;
    plane_a(2, 0) = 1;
    plane_a(3, 0) = -6;

    plane_b(0, 0) = 2;
    plane_b(1, 0) = 1;
    plane_b(2, 0) = 2;
    plane_b(3, 0) = -11;

    plane_c(0, 0) = 3;
    plane_c(1, 0) = 1;
    plane_c(2, 0) = 4;
    plane_c(3, 0) = -19;
    Eigen::Matrix<float, Eigen::Dynamic, 1> line;
    bool flag_2 = pcl::planeWithPlaneIntersection(plane_a, plane_b, line, 1e-4);//line只有5個(gè)數(shù)值寂嘉,暫時(shí)未理解出對(duì)應(yīng)的定義

    //(4)計(jì)算兩平面的交線遏暴,構(gòu)造函數(shù)
    //bool planeWithPlaneIntersection(const Eigen::Vector4f & plane_a,const Eigen::Vector4f & plane_b,Eigen::VectorXf & line,double angular_tolerance = 0.1)
    Eigen::VectorXf line1;
    bool flag_3 = pcl::planeWithPlaneIntersection(plane_a, plane_b, line1, 1e-4);

    //(5)三個(gè)面的交點(diǎn)坐標(biāo)(提前設(shè)置點(diǎn)(2,1,3),然后設(shè)平面方程的系數(shù),最后再進(jìn)行驗(yàn)算)
    //bool threePlanesIntersection(const Eigen::Vector4f & plane_a,const Eigen::Vector4f & plane_b,const Eigen::Vector4f & plane_c,Eigen::Vector3f & intersection_point,double determinant_tolerance = 1e-6)
    Eigen::Vector3f intersection_point;
    bool flag_4 = pcl::threePlanesIntersection(plane_a, plane_b, plane_c, intersection_point,1e-6);

    //(6)三個(gè)面的交點(diǎn)坐標(biāo)(構(gòu)造函數(shù))
    Eigen::Matrix<double, 4, 1> plane_ad;
    Eigen::Matrix<double, 4, 1> plane_bd;
    Eigen::Matrix<double, 4, 1> plane_cd;
    plane_ad(0, 0) = 1;// plane_a << 1, 1, 0, 0;//賦值方法二
    plane_ad(1, 0) = 1;
    plane_ad(2, 0) = 1;
    plane_ad(3, 0) = -6;

    plane_bd(0, 0) = 2;
    plane_bd(1, 0) = 1;
    plane_bd(2, 0) = 2;
    plane_bd(3, 0) = -11;

    plane_cd(0, 0) = 3;
    plane_cd(1, 0) = 1;
    plane_cd(2, 0) = 4;
    plane_cd(3, 0) = -19;
    Eigen::Vector3d intersection_point_d;
    bool flag_5 = pcl::threePlanesIntersection(plane_ad, plane_bd, plane_cd, intersection_point_d, 1e-6);

    system("pause");
    return 0;
}

參考文章:
http://pointclouds.org/documentation/intersections_8h.html
http://pointclouds.org/documentation/intersections_8h_source.html

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末衷模,一起剝皮案震驚了整個(gè)濱河市鹊汛,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌阱冶,老刑警劉巖刁憋,帶你破解...
    沈念sama閱讀 217,542評(píng)論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異熙揍,居然都是意外死亡职祷,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,822評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)有梆,“玉大人是尖,你說(shuō)我怎么就攤上這事∧嘁” “怎么了饺汹?”我有些...
    開封第一講書人閱讀 163,912評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)痰催。 經(jīng)常有香客問(wèn)我兜辞,道長(zhǎng),這世上最難降的妖魔是什么夸溶? 我笑而不...
    開封第一講書人閱讀 58,449評(píng)論 1 293
  • 正文 為了忘掉前任逸吵,我火速辦了婚禮,結(jié)果婚禮上缝裁,老公的妹妹穿的比我還像新娘扫皱。我一直安慰自己,他們只是感情好捷绑,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,500評(píng)論 6 392
  • 文/花漫 我一把揭開白布韩脑。 她就那樣靜靜地躺著,像睡著了一般粹污。 火紅的嫁衣襯著肌膚如雪段多。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,370評(píng)論 1 302
  • 那天壮吩,我揣著相機(jī)與錄音进苍,去河邊找鬼。 笑死鸭叙,一個(gè)胖子當(dāng)著我的面吹牛琅捏,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播递雀,決...
    沈念sama閱讀 40,193評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼蚀浆!你這毒婦竟也來(lái)了缀程?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,074評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤市俊,失蹤者是張志新(化名)和其女友劉穎杨凑,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體摆昧,經(jīng)...
    沈念sama閱讀 45,505評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡撩满,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,722評(píng)論 3 335
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片伺帘。...
    茶點(diǎn)故事閱讀 39,841評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡昭躺,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出伪嫁,到底是詐尸還是另有隱情领炫,我是刑警寧澤,帶...
    沈念sama閱讀 35,569評(píng)論 5 345
  • 正文 年R本政府宣布张咳,位于F島的核電站帝洪,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏脚猾。R本人自食惡果不足惜葱峡,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,168評(píng)論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望龙助。 院中可真熱鬧砰奕,春花似錦、人聲如沸泌参。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,783評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)沽一。三九已至盖溺,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間铣缠,已是汗流浹背烘嘱。 一陣腳步聲響...
    開封第一講書人閱讀 32,918評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留蝗蛙,地道東北人蝇庭。 一個(gè)月前我還...
    沈念sama閱讀 47,962評(píng)論 2 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像捡硅,于是被迫代替她去往敵國(guó)和親哮内。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,781評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容