UVA 11186(p349)----Circum Triangle

#include<cstdio>
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
const double pi=acos(-1.0);
struct point
{
    double x,y;
    point(double a=0.0,double b=0.0):x(a),y(b){}
};
vector<point> m;
inline double change(double rad)
{
    return (rad/180*pi);
}
inline double cross(double x1,double y1,double x2,double y2)
{
    return (x1*y2-x2*y1);
}
inline double area(point a,point b,point c)
{
    return fabs(cross(a.x-b.x,a.y-b.y,c.x-b.x,c.y-b.y)/2);
}
int main()
{
    int n,r;
    while(scanf("%d%d",&n,&r)==2&&n)
    {
        m.clear();
        double ans=0.0;
        for(int i=0;i<n;i++)
        {
            double rad;
            scanf("%lf",&rad);
            double x=change(rad);
            m.push_back(point(r*cos(x),r*sin(x)));
        }
        for(int i=0;i<n;i++)
            for(int j=i+1;j<n;j++)
                for(int k=j+1;k<n;k++)
                   ans+=area(m[i],m[j],m[k]);
        printf("%.0lf\n",ans);
    }
    return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值