UVA - 11186-Circum Triangle

有个以坐标原点为圆心的圆,给出圆上的点的关于x轴的夹角,以及圆的半径,求圆上点所能构成的三角形的面积和


我的做法:


先算出每个点的坐标,枚举所有三个点的组合,叉积求面积


我的代码:

#include<iostream>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
const double pi=acos(-1.0);
struct dot
{
	double x,y;
	dot(){}
	dot(double a,double b){x=a,y=b;}
	friend dot operator -(dot a,dot b){return dot(a.x-b.x,a.y-b.y);}
	friend double operator /(dot a,dot b){return a.x*b.x+a.y*b.y;}
	friend double operator *(dot a,dot b){return a.x*b.y-a.y*b.x;}
};
double dis(dot a,dot b)
{
	return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}
double cang(dot a,dot b)
{
	return acos(a/b/dis(a,dot(0,0))/dis(b,dot(0,0)));
}
double cg1(double a)
{
	return a/pi*180;
}
double cg2(double a)
{
	return a/180*pi;
}
int main()
{
	int n,i,j,k;
	double r,t,ans;
	dot a[510];
	while(cin>>n>>r)
	{
		if(n+r==0)
			break;
		for(i=0;i<n;i++)
		{
			cin>>t;
			t=cg2(t);
			a[i]=dot(r*cos(t),r*sin(t));
		}
		ans=0;
		for(i=0;i<n;i++)
			for(j=i+1;j<n;j++)
				for(k=j+1;k<n;k++)
					ans+=fabs((a[j]-a[i])*(a[k]-a[i])/2);
		printf("%.0lf\n",ans);
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我来给你展示一下用 Python 实现 α-shape 算法提取点云切片轮廓点的代码。 ```python import numpy as np from scipy.spatial import Delaunay def alpha_shape(points, alpha): """ 计算α-shape算法提取点云切片轮廓点 :param points: 点云数据,格式为 N x 3 的 numpy 数组,表示 N 个点的 x、y、z 坐标 :param alpha: 参数α,决定了α-shape的形态 :return: 轮廓点坐标,格式为 M x 3 的 numpy 数组,表示 M 个点的 x、y、z 坐标 """ # 构建 Delaunay 三角剖分 tri = Delaunay(points) # 计算每个三角形的外接圆半径 circum_radius = np.sqrt(np.sum((tri.points[tri.simplices][:, :, :] - tri.circumcenters[:, np.newaxis, :]) ** 2, axis=(1, 2))) # 根据参数 alpha,筛选出需要保留的三角形 edge_length = np.max(tri.transform[:, :2].dot((tri.points[tri.simplices][:, 1] - tri.points[tri.simplices][:, 0])[:, :2, :]), axis=1) keep = circum_radius < 1.0 / alpha * edge_length # 获取保留三角形的边界点 tri_points = tri.points[tri.simplices][keep] edges = np.concatenate((tri_points[:, :2], tri_points[:, 1:], tri_points[:, ::2]), axis=0) edge_points = edges[np.lexsort((edges[:, 1], edges[:, 0]))] edge_diff = np.diff(edge_points, axis=0) edges_idx = np.concatenate((np.array([0]), np.where(np.any(edge_diff, axis=1))[0] + 1, np.array([edge_points.shape[0]]))) # 获取边界点的坐标 contour_points = [] for i in range(edges_idx.shape[0] - 1): contour_points.append(edge_points[edges_idx[i]:edges_idx[i + 1]][0]) contour_points.append(edge_points[edges_idx[-1] - 1]) # 返回轮廓点坐标 return np.array(contour_points) ``` 使用方法: ```python # 生成一些随机的点云数据 points = np.random.rand(100, 3) # 计算轮廓点 contour_points = alpha_shape(points, 0.5) # 打印轮廓点坐标 print(contour_points) ``` 其中,`points` 是点云数据,格式为 N x 3 的 numpy 数组,表示 N 个点的 x、y、z 坐标;`alpha` 是参数α,决定了α-shape的形态;`contour_points` 是轮廓点坐标,格式为 M x 3 的 numpy 数组,表示 M 个点的 x、y、z 坐标。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值