18题怎么根据端点判断线段的条数规律是什么边界上的端点?

谢邀这个纯粹是概念性的问题你注意,如果讨论问题时,没有说度量空间 X 包含在某个更大的集合里,而是只在空间 X 中的话,它是不存在边界的(尽管集合 X 的直径可能是有限的,甚至本身可能就是有限集)所以你问的问题就没有意义对于更一般的拓扑空间来讲,拓扑空间 X 的子集 A 的边界 \partial A 通常是被定义为这样的点 x 的集合:x 的任何邻域 V 至少包含了 A 中的一点和 \complement A 中的一点而这样的点 x 则被称作边界点边界还有很多其他等价定义,比如定义为 A 的闭包 \mathrm{Cl}(A)
和 \complement A 的闭包的交集,即:\partial A=\mathrm{Cl}(A)\cap\mathrm{Cl}(\complement A)还可以定义为定义为 A 的闭包 \mathrm{Cl}(A) 和 A 的内部 \mathrm{Int}(A) 的差集,即\partial A=\mathrm{Cl}(A)-\mathrm{Int}(A)按定义,拓扑空间 X 本身的边界当然是 \varnothing实际上,开集、闭集、邻域、内点、内部、聚点(极限点)、附着点、边界点、边界……这些概念统统都是相对的概念,要看你具体是在哪个拓扑空间里研究它比如开区间 \left( 0,1 \right) 在 \mathbb{R} 中是开集,在 \mathbb{R}^{2} 中却不是开集(当赋予由欧几里得度量导出的标准拓扑时)在拓扑空间 X 本身研究 X ,它当然没有边界,也就没有边界点只有当你在一个包含 X 的更大的集合里讨论 X 时,它的边界才可能非空另外,在度量空间里的球形邻域也不一定是你日常看到的球形,和所在的空间、所使用的度量有关,可以是各种千奇百怪的样子比如 \mathbb{R}^{2} 中,配备欧几里得度量,球形邻域 B\left( x,\varepsilon \right) 就是一个以点 x 为圆心, \varepsilon 为半径的圆又比如闭区间 \left[ a,b \right] 上的连续实值函数组成的集合 C\left[ a,b \right] ,引入切比雪夫度量 d\left( f,g \right) =\max_{a\leq x\leq b}{\left
f\left( x \right)-g\left( x \right) \right|}那么可以验证,以在 \left[ a,b \right] 上恒等于某个实数 c 的常数函数为中心,在 \left[ a,b \right] 上连续,且在 \left[ a,b \right] 函数值满足 c-\varepsilon<f\left( x \right)<c+\varepsilon 的一切连续有界函数,构成球形邻域 B\left( f_{c},\varepsilon \right)其中 f_{c}\left( x \right)=c 是 \left[ a,b \right] 上的常值函数再比如说,在 \mathbb{R}^{3} 中,令点 x 的坐标为 \left( x_{1},x_{2},x_{3} \right) 赋以度量 d\left( x,y \right)=\sup_{i=1,2,3}{\left
x_{i}-y_{i} \right|} 那么球形邻域 B\left( x,\varepsilon \right) 是个以 2\varepsilon 为边长、各边平行于坐标轴的立方体}

1 #include <iostream>
2 #include <string>
3 #include <cmath>
4
5 #define PI 3.1415926
6 #define EXP 1e-6
// 截取精度
7 #define EXP1 1e-4
// 校验精度
8
9
10
11 int main() {
12
/* start_point表示判断点,point_all代表多边形点的二维数组 */
13
double start_point[] = { 0.0, 0.0 };
14
15
double point_all[7][2] = {
16
{ 1.0, 1.0 },
17
{ 0.0, 3.0 },
18
{ 1.0, 2.0 },
19
{ 1.5, 3.0 },
20
{ 2.0, 2.0 },
21
{ 3.0, 4.0 },
22
{ 3.0, 0.0 }
23
};
24
25
const int n = 7;// +1;
26
const int double_n = 2 * n;
27
double All_point_xy[double_n + 2] = {};
28
29
for (int i = 0; i < n; i++) {
30
for (int j = 0; j < 2; j++) {
31
All_point_xy[2 * i + j] = { point_all[i][j] };
// 想将接收的多边形点放到一个一维数组中
32
}
33
}
34
35
All_point_xy[double_n] = All_point_xy[0];
36
All_point_xy[double_n + 1] = All_point_xy[1];
// 为方便多边形边界判断,再次将开头点放到末尾
37
38
printf("点元素集合(末尾重复开头):\n");
// 验证
39
for (int i = 0; i < double_n + 2; i++) {
40
printf("%f , ", All_point_xy[i]);
41
}
42
43
44
int counter = 0;
45
double point_x;
// 交点x坐标
46
double point_y;
// 交点y坐标
47
double theta = 45;
48
double theta_arr[11] = { 45, 60, 256, 128, 64, 32, 16, 8, 4, 2, 1 };
// 不同角度的射线方向
49
double t, b;
50
double Deg2rad = 180 / PI;
// C++ 中三角函数计算,运用的是弧度
51
double tan_theta = tan(theta / Deg2rad);
// 转换至弧度,进行正切值计算
52
printf("\n验证正切值:%lf", tan_theta);
// 验证转换关系,以及求解是否正确
53
54
bool Coincidence_judgment = false;
// 重合判段标识
55
bool Coincidence_judgment02 = false;
// 为更好地跳出循环,进行了两次重合判断
56
double slope_vertex_start[n+1] = {};
57
58
for (int i = 0; i < (std::end(theta_arr) - std::begin(theta_arr)); i++) { // 获得数组的长度方法
59
int now_theta = theta_arr[i];
60
double slope_vertex = tan(now_theta / Deg2rad);
// 记录顶点所处斜率
61
slope_vertex_start[0] = tan(now_theta / Deg2rad);
62
for (int j = 0; j <= (n - 1); j++) {
63
double point_start_x = All_point_xy[2 * j];
64
double point_start_y = All_point_xy[2 * j + 1];
65
double point_end_x = All_point_xy[2 * j + 2];
66
double point_end_y = All_point_xy[2 * j + 3];
67
double err_x = point_end_x - point_start_x;
68
if (err_x == 0) {
69
err_x = EXP;
70
}
71
72
double slope_half_line = tan(theta_arr[i] / Deg2rad);
// 射线斜率
73
double slope_line_segment = (point_end_y - point_start_y) / err_x;
// 两点形成直线的斜率
74
double err_0 = abs(slope_half_line - slope_line_segment);
// 由于无法绝对相等,设计了精度差
75
76
slope_vertex_start[j+1] = slope_line_segment;
77
//if (j == 0) {
78
//
slope_vertex_start = slope_line_segment;
// 存储首个顺序边界的斜率,防止被刷掉
79
//}
80
81
82
printf("\n%d", j);
83
if (err_0 < EXP) {
// 斜率相等,表示射线与边界平行或重合,再次求解两点与判断点之间的斜率,如果两个相等,则表示重合
84
double slope2start = (point_start_y - start_point[1]) / (point_start_x - start_point[0]);
85
double slope2end = (point_end_y - start_point[1]) / (point_end_x - start_point[0]);
86
double err_1 = abs(slope2end - slope2start);
87
if (err_1 < EXP) {
88
Coincidence_judgment = true;
// 重合
89
Coincidence_judgment02 = true;
90
}
91
}
92
if (Coincidence_judgment == true) {
93
Coincidence_judgment = false;
94
break;
// 重合则表示该斜率不可用,跳出整个循环
95
}
96
// 如果不重合,则利用两个直线求交点的公式求解交点坐标
97
b = start_point[1] - slope_half_line * start_point[0];
98
t = (slope_half_line * point_start_x + b - point_start_y) / (point_end_y - point_start_y - slope_half_line * (point_end_x - point_start_x));
99
point_x = (point_end_x - point_start_x) * t + point_start_x;
100
point_y = (point_end_y - point_start_y) * t + point_start_y;
101
102
printf("\n%d", now_theta);
103
printf("\n求解交点坐标:%lf, %lf ", point_x, point_y);
104
105
double slope_vertex = slope_vertex_start[j];
106
107
if (((abs(point_x - point_start_x) < EXP) && (abs(point_y - point_start_y) < EXP))
((abs(point_x - point_end_x) < EXP) && (abs(point_y - point_end_y)) < EXP)) {
108
109
110
111
if (((slope_half_line < slope_vertex ) && (slope_half_line < slope_line_segment))
((slope_half_line > slope_vertex) && (slope_half_line > slope_line_segment))) {
112
113
continue;
114
}
115
116
117
if (j == n - 1) {
118
if (((slope_half_line < slope_vertex_start[1]) && (slope_half_line > slope_line_segment))
((slope_half_line > slope_vertex_start[1]) && (slope_half_line < slope_line_segment))) {
119
continue;
120
}
121
}
122
if ((abs(point_x - point_start_x) < EXP)) {
123
if (start_point[0] < point_x) {
// 由于上面求解交点坐标方式是以直线形式进行的,将其转换至一个方向表示射线形式
124
printf("\n可用交点:%d,%lf, %lf", j, point_x, point_y);
125
counter++;
126
}
127
}
128
129
}
130
else if ((point_x > point_start_x) && (point_x > point_end_x)) {
131
printf("x坐标上限均大于两端点,故舍弃并跳出\n ");
132
continue;
133
}
134
else if ((point_x < point_start_x) && (point_x < point_end_x)) {
135
printf("x坐标上限均小于两端点,故舍弃并跳出\n ");
136
continue;
137
}
138
else if ((point_y > point_start_y) && (point_y > point_end_y)) {
139
printf("y坐标上限均大于两端点,故舍弃并跳出\n ");
140
continue;
141
}
142
else if ((point_y < point_start_y) && (point_y < point_end_y)) {
143
printf("y坐标上限均小于两端点,故舍弃并跳出\n ");
144
continue;
145
}
146
else {
147
148
printf("正常值,触发 counter++;\n ");
149
if (start_point[0] < point_x) {
// 由于上面求解交点坐标方式是以直线形式进行的,将其转换至一个方向表示射线形式
150
printf("\n可用交点:%d,%lf, %lf", j, point_x, point_y);
151
counter++;
152
}
153
154
}
155
156
157
}
158
if (Coincidence_judgment02 == true) {
159
Coincidence_judgment02 = false;
160
counter = 0;
161
continue;
162
}
163
else {
164
break;
165
}
166
167
}
168
169
printf("\n交点个数 = %d", counter);
170
171
if (counter % 2 == 1) {
172
printf("\n点在多边形的内部");
173
}
174
else {
175
printf("\n点在多边形的外部");
176
}
177
return 0;
178 }}

我要回帖

更多关于 根据端点判断线段的条数规律是什么 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信