Points Within

本文介绍了一种使用几何算法来判断给定点是否位于已知多边形内部的方法。通过输入多边形顶点坐标和待测点坐标,程序能够准确地输出该点是否处于多边形之内。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=81
Statement of the Problem

Several drawing applications allow us to draw polygons and almost all of them allow us to fill them with some color. The task of filling a polygon reduces to knowing which points are inside it, so programmers have to colour only those points.

You're expected to write a program which tells us if a given point lies inside a given polygon described by the coordinates of its vertices. You can assume that if a point is in the border of the polygon, then it is in fact inside the polygon.

Input Format

The input file may contain several instances of the problem. Each instance consists of: (i) one line containing integers N, 0 < N < 100 and M, respectively the number of vertices of the polygon and the number of points to be tested. (ii) N lines, each containing a pair of integers describing the coordinates of the polygon's vertices; (iii) M lines, each containing a pair of integer coordinates of the points which will be tested for "withinness" in the polygon.

You may assume that: the vertices are all distinct; consecutive vertices in the input are adjacent in the polygon; the last vertex is adjacent to the first one; and the resulting polygon is simple, that is, every vertex is incident with exactly two edges and two edges only intersect at their common endpoint. The last instance is followed by a line with a 0 (zero).

Output Format

For the ith instance in the input, you have to write one line in the output with the phrase "Problem i:", followed by several lines, one for each point tested, in the order they appear in the input. Each of these lines should read "Within" or "Outside", depending on the outcome of the test. The output of two consecutive instances should be separated by a blank line.

Sample Input

3 1
0 0
0 5
5 0
10 2
3 2
4 4
3 1
1 2
1 3
2 2
0

Sample Output

Problem 1:
Outside

Problem 2:
Outside
Within

YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
#include<stdio.h>
#include<math.h>
struct point 
{
	double x,y;
};
point p[120];
int m,n;
double MIN(double x,double y)
{
	return x<y?x:y;
}
double MAX(double x,double y)
{
	return x>y?x:y;
}
int xdy(double x,double y)
{
	return x>y;
}
int xxy(double x,double y)
{
	return x<y;
}int xddy(double x,double y)
{
	return x>=y;
}
int xxdy(double x,double y)
{
	return x<=y;
}
int xdddy(double x,double y)
{
	return fabs(x-y)<1e-6;
}
double cross(point a,point b,point c)
{
	return (c.x-a.x)*(b.y-a.y)-(b.x-a.x)*(c.y-a.y);
}
int onsegement(point a,point b,point c)
{
	double d1=MIN(a.x,b.x);
	double d2=MAX(a.x,b.x);
	double d3=MIN(a.y,b.y);
	double d4=MAX(a.y,b.y);
	if(d1<=c.x&&c.x<=d2&&d3<=c.y&&c.y<=d4)
	return 1;
	return 0;
}
int segment(point a,point b,point c,point d)
{
	double d1=cross(c,d,a);
	double d2=cross(c,d,b);
	double d3=cross(a,b,c);
	double d4=cross(a,b,d);
	if(d1*d2<0&&d3*d4<0)
	return 1;
	if(d1==0&&onsegement(c,d,a))
	return 1;
	if(d2==0&&onsegement(c,d,b))
	return 1;
	if(d3==0&&onsegement(a,b,c))
	return 1;
	if(d1==0&&onsegement(a,b,d))
	return 1;
	return 0; 
}
int inploy(point a)
{
	point b;
	b.x=1e10,b.y=a.y+50;
	int i,j,k,l,tmp,cout=0;
	for(i=0;i<m;i++)
	{
		if(cross(p[i],p[(i+1)%m],a)==0&&onsegement(p[i],p[(i+1)%m],a))
		return 1;
		//printf("cout==%d\n",cout);
		tmp=-1;
		if(cross(a,b,p[i])==0&&onsegement(a,b,p[i]))
		tmp=i;
		else if(cross(a,b,p[(i+1)%m])==0&&onsegement(a,b,p[(i+1)%m]))
		tmp=(i+1)%m;
		if(tmp!=-1&&xdddy(p[tmp].y,MAX(p[i].y,p[(i+1)%m].y)))
		cout++;
		else if(tmp==-1&&segment(p[i],p[(i+1)%m],a,b))
		cout++;
	}
	if(cout%2==0)
	return 0;
	else 
	return 1;
}
int main()
{
	int i,j,k,ind=1;
	while(scanf("%d",&m),m)
	{
		scanf("%d",&n);
		if(ind!=1)
		printf("\n");
		printf("Problem %d:\n",ind++);
		for(i=0;i<m;i++)
		scanf("%lf%lf",&p[i].x,&p[i].y);
		while(n--)
		{
			point a;
			scanf("%lf%lf",&a.x,&a.y);
			if(inploy(a))
			printf("Within\n");
			else
			printf("Outside\n");
		}
		
	}
	return 0;
}


def spatially_regular_gen(): # Generator loop for i in range(num_per_epoch): # Choose the cloud with the lowest probability cloud_idx = int(np.argmin(self.min_possibility[split])) # choose the point with the minimum of possibility in the cloud as query point point_ind = np.argmin(self.possibility[split][cloud_idx]) # Get all points within the cloud from tree structure points = np.array(self.input_trees[split][cloud_idx].data, copy=False) # Center point of input region center_point = points[point_ind, :].reshape(1, -1) # Add noise to the center point noise = np.random.normal(scale=cfg.noise_init / 10, size=center_point.shape) pick_point = center_point + noise.astype(center_point.dtype) # Check if the number of points in the selected cloud is less than the predefined num_points if len(points) < cfg.num_points: # Query all points within the cloud queried_idx = self.input_trees[split][cloud_idx].query(pick_point, k=len(points))[1][0] else: # Query the predefined number of points queried_idx = self.input_trees[split][cloud_idx].query(pick_point, k=cfg.num_points)[1][0] # Shuffle index queried_idx = DP.shuffle_idx(queried_idx) # Get corresponding points and colors based on the index queried_pc_xyz = points[queried_idx] queried_pc_xyz = queried_pc_xyz - pick_point queried_pc_colors = self.input_colors[split][cloud_idx][queried_idx] queried_pc_labels = self.input_labels[split][cloud_idx][queried_idx] # Update the possibility of the selected points dists = np.sum(np.square((points[queried_idx] - pick_po
最新发布
04-04
<think>好的,我现在要解决用户提到的ANUSPLIN软件中出现的RDATA 'NO DATA POINTS WITHIN SPECIFIED LIMITS'错误。首先,我需要理解这个错误的具体原因。根据用户提供的引用资料,特别是引用[2]和引用[3],问题可能与数据的坐标范围或投影设置有关。 首先,引用[2]指出,当出现GETLIM错误时,可能是因为splina文件中设置的DEM范围比实际数据小。这说明数据点的坐标超出了软件处理时设定的范围,导致无法找到有效数据点。因此,我需要检查用户的数据范围是否在splina或其他配置文件设置的范围内。可能需要调整splina中的DEM范围,使其覆盖所有气象站点的坐标。 接下来,引用[3]提到坐标系的问题。用户可能在处理气象数据时,使用了自定义的投影(如Albers),但气象站数据本身是经纬度坐标,未正确转换为投影坐标。这会导致坐标不一致,软件无法识别数据点是否在指定范围内。解决方法是确保所有数据,包括气象站点,都转换为相同的投影坐标系,并且在属性表中计算并导出X、Y投影坐标,而不仅仅是经纬度。 此外,引用[1]中提到输入数据时出现RDATA错误,可能与数据点的实际位置超出设定的限制有关。这可能包括水平范围(经度、纬度)或垂直范围(如高程)。需要检查数据中的坐标值是否在配置文件中定义的最小和最大值之内。 可能的解决方案步骤包括: 1. 检查并扩展splina文件中的DEM范围,确保覆盖所有数据点。 2. 统一所有数据的坐标系,将气象站点的经纬度转换为投影坐标,并导出正确的X、Y值。 3. 验证数据点是否在配置的范围内,调整相关参数如LLGRID中的经度、纬度范围,或VERTICAL中的高程限制。 4. 检查数据文件格式是否正确,避免格式错误导致软件读取错误。 同时,需要确保在导出数据时,使用正确的分隔符和格式,如空格分隔,避免多余的空格或格式错误。例如,在导出气象站点坐标时,应使用计算几何后的投影坐标,而不是原始的经纬度。 最后,用户可能需要参考引用[3]中的步骤,在ArcGIS中处理数据,确保投影一致,并正确导出X、Y坐标。这可以解决因坐标不匹配导致的RDATA错误。</think>### ANUSPLIN RDATA "NO DATA POINTS WITHIN SPECIFIED LIMITS" 解决方案 #### 1. **检查坐标系一致性** - **问题根源**:气象站点数据可能使用经纬度坐标系(如WGS84),而插值配置文件(如`.splina`)设置的DEM范围使用了投影坐标系(如Albers)。坐标系不匹配会导致软件无法识别数据点的有效范围[^3]。 - **解决方法**: 1. 在ArcGIS中为气象站点数据添加投影坐标系,确保与DEM的投影一致。 2. 在属性表中计算气象站点的投影坐标(X、Y),并导出为文本文件(方法见引用[3])。 #### 2. **调整插值范围限制** - **问题根源**:`.splina`或`.llgrid`文件中设置的DEM范围过小,导致部分数据点超出插值区域[^2]。 - **解决方法**: 1. 打开`.splina`或`.llgrid`文件,检查`XMIN/XMAX/YMIN/YMAX`参数。 2. 将范围扩展至覆盖所有气象站点的投影坐标范围(需包含至少一个缓冲区域)。 #### 3. **验证高程限制** - **问题根源**:若插值涉及高程参数(如`.vertical`文件),数据点的高程值可能超出设定阈值。 - **解决方法**: 1. 检查气象数据中的高程字段是否在配置文件的`ZMIN/ZMAX`范围内。 2. 若超出,需调整高程限制或过滤异常高程值。 #### 4. **检查数据文件格式** - **问题根源**:数据文件(如`.rdata`)的列分隔符、缺失值标记或编码格式错误。 - **解决方法**: 1. 确保数据文件为**空格分隔**的纯文本格式。 2. 检查缺失值标记(如`-9999`)是否与配置文件一致。 --- ### 关键操作示例 在`.splina`文件中调整范围参数: ``` XMIN: 1200000 // 需小于最小投影坐标X值 XMAX: 1500000 // 需大于最大投影坐标X值 YMIN: 3200000 // 需小于最小投影坐标Y值 YMAX: 3600000 // 需大于最大投影坐标Y值 ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值