Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2562915
  • 博文数量: 315
  • 博客积分: 3901
  • 博客等级: 少校
  • 技术积分: 3640
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-08 15:32
个人简介

知乎:https://www.zhihu.com/people/monkey.d.luffy Android高级开发交流群2: 752871516

文章分类

全部博文(315)

文章存档

2019年(2)

2018年(1)

2016年(7)

2015年(32)

2014年(39)

2013年(109)

2012年(81)

2011年(44)

分类: C/C++

2013-06-14 21:42:16

xxx.c

点击(此处)折叠或打开

  1. /**
  2.  * @brief 计算直线与平面的交点
  3.  * @param[in] planeVector - 平面上向量【目前为[0, 0, 100]
  4.  * @param[in] planePoint - 平面上一点
  5.  * @param[in] lineVector - 直线向量
  6.  * @param[in] linePoint - 直线上一点
  7.  * @param[out] resultPoint- 直线与平面的交点【失败resultPoint值全为 -1】
  8.  * @return 无
  9.  * @note 调用约定:
  10.  * 1. 数组大小均为3*sizeof(float)
  11.  */
  12. static void CalPlaneLineIntersectPoint(float planeVector[], float planePoint[],
  13.                                        float lineVector[], float linePoint[],
  14.                                        float resultPoint[]);


  15. void CalPlaneLineIntersectPoint(float planeVector[], float planePoint[],

  16.                                 float lineVector[], float linePoint[],

  17.                                 float resultPoint[])

  18. {

  19.     float vp1, vp2, vp3, n1, n2, n3, v1, v2, v3, m1, m2, m3, t,vpt;

  20.     vp1 = planeVector[0];

  21.     vp2 = planeVector[1];

  22.     vp3 = planeVector[2];

  23.     n1 = planePoint[0];

  24.     n2 = planePoint[1];

  25.     n3 = planePoint[2];

  26.     v1 = lineVector[0];

  27.     v2 = lineVector[1];

  28.     v3 = lineVector[2];

  29.     m1 = linePoint[0];

  30.     m2 = linePoint[1];

  31.     m3 = linePoint[2];

  32.     vpt = v1 * vp1 + v2 * vp2 + v3 * vp3;

  33.     //首先判断直线是否与平面平行

  34.     if (vpt == 0)

  35.     {

  36.         resultPoint[0] = -1;

  37.         resultPoint[1] = -1;

  38.         resultPoint[2] = -1;

  39.     }

  40.     else

  41.     {

  42.         t = ((n1 - m1) * vp1 + (n2 - m2) * vp2 + (n3 - m3) * vp3) / vpt;

  43.         resultPoint[0] = m1 + v1 * t;

  44.         resultPoint[1] = m2 + v2 * t;

  45.         resultPoint[2] = m3 + v3 * t;

  46.     }

  47.     return;

  48. }

阅读(2835) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~