打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
c 如何求任意多边形的面积
#include <iostream> #include <vector> using namespace std; struct Point//定义坐标结构体 { float x, y; }; float intAreaCalc(vector<Point> &ptVector)//求解多边形的面积(知道多边形的顶点,按顺时针或者逆时针) { int i_count=vecPoly.size(); iCycle=0; float area_temp=0.f; for(int i=0;i<i_count;i++) { area_temp=area_temp+(vecPoly[i].x*vecPoly[(i+1) % i_count].y-vecPoly[(i+1) % i_count].x*vecPoly[i].y); } return abs(0.5*area_temp); } int main() { int n; while(cin>>n && n!=0)输入n,决定是几边形 { vector<Point>pt_vec;//存放多边形的各顶点 Point pt_temp;//临时的Point变量,接收输入的顶点 for(int i=0; i < n;i++)///按照顺序输入多边形的顶点坐标 { cout<<'pt_temp.x = '; cin>>pt_temp.x; cout<<'pt_temp.y = '; cin>>pt_temp.y; pt_vec.push_back(pt_temp); } float area_all = intAreaCalc(pt_vec);/得到多边形的面积 cout<<'多边形的面积是:'<<area_all<<endl; } return 0; }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
牛客网:模拟二,平衡数
怎么求一个点是否在一个多边形内呢?
找出无序数组中第K小的数
C++中vector的实现
vector存结构体
Vector<vector<int>> array用法(转载)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服