-
大小: 4.27MB文件类型: .rar金币: 1下载: 0 次发布日期: 2023-11-13
- 语言: 其他
- 标签:
资源简介
关于求线段和线段,线段和圆弧,圆弧与圆弧的交点算法和测试程序,里面有算法代码,和测试程序,主要时理解算法,算法分析:http://blog.csdn.net/u012727080/article/details/78908614
代码片段和文件信息
#include “stdafx.h“
#include
#include “LineAndArcFunction.h“
#define LAAI_LINE 1
#define LAAI_ARC 2
// 求2点的最大值和最小值
#define MAX_VAR(a b) ((a) > (b) ? (a) : (b))
#define MIN_VAR(a b) ((a) < (b) ? (a) : (b))
// 浮点型转化为整型
#define FloatToInt(a) (int(a + 0.5))
#define PI 3.1415926
// 求相交函数
POINT * fnLineArcIntersect(strLineAndArc laa_1 strLineAndArc laa_2)
{
POINT * pIntersection = NULL;
// 角度转换弧度
laa_1.angle = laa_1.angle * PI / 180;
laa_2.angle = laa_2.angle * PI / 180;
int laa1_x_min = MIN_VAR(laa_1.p1.x laa_1.p2_O.x);
int laa1_x_max = MAX_VAR(laa_1.p1.x laa_1.p2_O.x);
int laa1_y_min = MIN_VAR(laa_1.p1.y laa_1.p2_O.y);
int laa1_y_max = MAX_VAR(laa_1.p1.y laa_1.p2_O.y);
int laa2_x_min = MIN_VAR(laa_2.p1.x laa_2.p2_O.x);
int laa2_x_max = MAX_VAR(laa_2.p1.x laa_2.p2_O.x);
int laa2_y_min = MIN_VAR(laa_2.p1.y laa_2.p2_O.y);
int laa2_y_max = MAX_VAR(laa_2.p1.y laa_2.p2_O.y);
// 线段与线段相交
if (laa_1.type == LAAI_LINE && laa_2.type == LAAI_LINE)
{
float k1 = 0 k2 = 0 b1 = 0 b2 = 0;
int x y;
// 线段为一个点时
if ((laa_1.p1.x == laa_1.p2_O.x && laa_1.p1.y == laa_1.p2_O.y) || (laa_2.p1.x == laa_2.p2_O.x && laa_2.p1.y == laa_2.p2_O.y))
return NULL;
// 线段L1L2在xy区间内不想交,排除平行和直线等情况
if(laa2_x_max < laa1_x_min || laa2_x_min > laa1_x_max || laa2_y_max < laa1_y_min || laa2_y_min > laa1_y_max)
/*if ((MAX_VAR(laa_2.p1.x laa_2.p2_O.x) < MIN_VAR(laa_1.p1.x laa_1.p2_O.x)) || (MIN_VAR(laa_2.p1.x laa_2.p2_O.x) > MAX_VAR(laa_1.p1.x laa_1.p2_O.x))
|| (MAX_VAR(laa_2.p1.y laa_2.p2_O.y) < MIN_VAR(laa_1.p1.y laa_1.p2_O.y)) || (MIN_VAR(laa_2.p1.y laa_2.p2_O.y) > MAX_VAR(laa_1.p1.y laa_1.p2_O.y)))*/
return NULL;
if (laa_1.p1.x == laa_1.p2_O.x && laa_2.p1.x == laa_2.p2_O.x) // 线段L1L2斜率都不存在
return NULL;
else if (laa_1.p1.x == laa_1.p2_O.x) // 线段L1斜率不存在L2斜率存在
{
k2 = float(laa_2.p2_O.y - laa_2.p1.y) / (laa_2.p2_O.x - laa_2.p1.x);
b2 = float(laa_2.p1.y - (float)k2 * laa_2.p1.x);
y = FloatToInt((float)k2 * laa_1.p1.x + b2);
if(y >= laa1_y_min && y <= laa1_y_max)
/*if (y >= MIN_VAR(laa_1.p1.y laa_1.p2_O.y) && y <= MAX_VAR(laa_1.p1.y laa_1.p2_O.y))*/
{
pIntersection = new POINT[1];
pIntersection[0].x = laa_1.p1.x;
pIntersection[0].y = y;
return pIntersection;
}
return NULL;
}
else if(laa_2.p1.x == laa_2.p2_O.x) // 线段L1斜率存在L2斜率不存在
{
k1 = float(laa_1.p2_O.y - laa_1.p1.y) / (laa_1.p2_O.x - laa_1.p1.x);
b1 = float(laa_1.p1.y - (float)k1 * laa_1.p1.x);
y = FloatToInt((float)k2 * laa_2.p1.x + b2);
if(y >= laa2_y_min && y <= laa2_y_max)
/*if (y >= MIN_VAR(laa_2.p1.y laa_2.p2_O.y) && y <= MAX_VAR(laa_2.p1.y laa_2.p2_O.y))*/
{
pIntersection = new POINT[1];
pIntersection[0].x = laa_2.p1.x;
pIntersection[0].y = y;
return pIntersection;
}
return NULL;
}
else // 线段L1L2斜率都存在
{
k1 = float(laa_1.p2_O.y - laa_1.p1.y) / (laa_1.p2_O.x - la
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 109568 2017-12-26 15:29 LineAndCircleIntersect\Debug\LineAndArcIntersectGraphical.exe
文件 454800 2017-12-26 15:29 LineAndCircleIntersect\Debug\LineAndArcIntersectGraphical.ilk
文件 994304 2017-12-26 15:29 LineAndCircleIntersect\Debug\LineAndArcIntersectGraphical.pdb
文件 40960 2017-12-25 08:51 LineAndCircleIntersect\Debug\LineAndCircleIntersect.exe
文件 330444 2017-12-25 08:51 LineAndCircleIntersect\Debug\LineAndCircleIntersect.ilk
文件 1690624 2017-12-25 08:51 LineAndCircleIntersect\Debug\LineAndCircleIntersect.pdb
文件 1 2009-08-31 02:32 LineAndCircleIntersect\LineAndArcIntersectGraphical\ClassDiagram1.cd
文件 4114 2017-12-26 15:29 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\cl.command.1.tlog
文件 13748 2017-12-26 15:29 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\CL.read.1.tlog
文件 4804 2017-12-26 15:29 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\CL.write.1.tlog
文件 27096 2017-12-26 15:29 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\LineAndArcFunction.obj
文件 406 2017-12-25 08:51 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\LineAndArcIntersectGraphical.exe.em
文件 472 2017-12-25 08:51 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\LineAndArcIntersectGraphical.exe.em
文件 381 2017-12-26 15:29 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\LineAndArcIntersectGraphical.exe.intermediate.manifest
文件 138 2017-12-26 15:29 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\LineAndArcIntersectGraphical.lastbuildstate
文件 7590 2017-12-26 15:29 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\LineAndArcIntersectGraphical.log
文件 28987 2017-12-26 14:31 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\LineAndArcIntersectGraphical.obj
文件 4456448 2017-12-25 10:46 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\LineAndArcIntersectGraphical.pch
文件 48468 2017-12-25 10:47 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\LineAndArcIntersectGraphical.res
文件 713 2017-12-25 09:35 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\LineAndArcIntersectGraphical.vcxprojResolveAssemblyReference.cache
文件 0 2017-12-25 08:51 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\LineAndArcIntersectGraphical.write.1.tlog
文件 246 2017-12-25 08:51 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\LineAndArcIntersectGraphical_manifest.rc
文件 2 2017-12-26 15:29 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\li
文件 2 2017-12-26 15:29 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\li
文件 2 2017-12-26 15:29 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\li
文件 2 2017-12-26 15:29 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\li
文件 2 2017-12-26 15:29 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\li
文件 2 2017-12-26 15:29 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\li
文件 2 2017-12-26 15:29 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\li
文件 2 2017-12-26 15:29 LineAndCircleIntersect\LineAndArcIntersectGraphical\Debug\li
............此处省略110个文件信息
- 上一篇:教室预约管理系统
- 下一篇:Zigbee无线通信实验指导书 (清华大学 自动化系 )
评论
共有 条评论