若干空间几何计算实现代码(Qt、C++)
1 已知空间两个向量,求与其垂直第三个向量
/*!
* \brief 求垂直与两向量的第三个向量
*/
void MatUtil::GetVerticalVector(const QList coordinate_z,
const QList coordinate_x,
QList &coordinate_y) {
coordinate_y[0] = coordinate_x[1] * coordinate_z[2] -
coordinate_x[2] * coordinate_z[1];
coordinate_y[1] = coordinate_x[2] * coordinate_z[0] -
coordinate_x[0] * coordinate_z[2];
coordinate_y[2] = coordinate_x[0] * coordinate_z[1] -
coordinate_x[1] * coordinate_z[0];
}
2 求封闭图形面积
把封闭图形差分成一个个三角形,依次求每个三角形面积。最后一组记得是两个三角形
/*!
* \brief 求封闭图形面积
* points 输入点。第一个list为几张图片、第二个list位每张图片多少点、第三个list为每个点实际坐标
* areas 输出每个图片面积
*/
void MatUtil::GetCircleArea(
const QList points, QList &areas) {
areas.clear();
for(qint32 i = 0; i
double x1 = points[i][j][0];
double y1 = points[i][j][1];
double x2 = points[i][j + 1][0];
double y2 = points[i][j + 1][1];
double x3 = 352.0;
double y3 = 352.0;
area +=
0.01 * 0.01 *
abs(0.5 * (x1 * y2 + x2 * y3 + x3 * y1 - x1 * y3 - x2 * y1 - x3 * y2));
}
double x1 = points[i][0][0];
double y1 = points[i][0][1];
double x2 = points[i][points[i].count() - 1][0];
double y2 = points[i][points[i].count() - 1][1];
double x3 = 352.0;
double y3 = 352.0;
area +=
0.01 * 0.01 *
abs(0.5 * (x1 * y2 + x2 * y3 + x3 * y1 - x1 * y3 - x2 * y1 - x3 * y2));
areas
return sqrt((p[0] - x[0]) * (p[0] - x[0]) +
(p[1] - x[1]) * (p[1] - x[1]) +
(p[2] - x[2]) * (p[2] - x[2]));
}
4 求三点的曲率半径和曲率、求中心线曲率最大的系列点
![xxx](https://img-blog.csdnimg.cn/img_convert/50912cf01d61d47ac1dad3d925067d82.png)
![xxx](https://img-blog.csdnimg.cn/img_convert/801340f26931423b7d22ee5a42b6e656.png)
// 求dot曲率
double DotCurvature(const QList dot1,
const QList dot2,
const QList dot3) {
double cur;//求得的曲率
double radius;//曲率半径
double dis1, dis2, dis3; //距离
dis1 = distance(dot1, dot2);
dis2 = distance(dot1, dot3);
dis3 = distance(dot2, dot3);
radius = sqrt((dis1 + dis2 - dis3) * (dis1 - dis2 + dis3) *
(dis2 + dis3 - dis1) * (dis1 + dis2 + dis3)) / (dis1 * dis2 * dis3);
cur = 1 / radius;
return cur;
}
// 选择contour_points曲率最大点
void Geometry(QList contour_points,
QList &out_points,
QList &number) {
number
result_compare = result;
qint32 size = number.count() - 1;
for(qint32 i = 0; i
result ++;
for(qint32 j = number.at(i) + 30; j
out_points
t = dot[i];
dot[i] = dot[i + 1];
dot[i + 1] = t;
t1 = number[i];
number[i] = number[i + 1];
number[i + 1] = t1;
}
}
5 求图像重心
/*!
* \brief 求重心
* points 输入点。第一个list为几张图片、第二个list位每张图片多少点、第三个list为每个点实际坐标
* gravity 输出每张图片的重心
*/
void MatUtil::GetImageCenterOfGravity(
const QList points, QList &gravity) {
gravity.clear();
for(qint32 i = 0; i
x_tmp += points[i][j][0];
y_tmp += points[i][j][1];
}
x_tmp /= points[i].count();
y_tmp /= points[i].count();
gravity_tmp
QList vctor;
vctor
double d = (fabs((y2 - y1) * x0 + (x1 - x2) * y0 + ((x2 * y1) - (x1 * y2)))) /
(sqrt(pow(y2 - y1, 2) + pow(x1 - x2, 2)));
return d;
}
|