数学:知道n边形各顶点坐标,求面积

方法一:

float   area_of_polygon(int   vcount,float   x[],float   y[]) 

    int   i; 
    float   s; 
    if   (vcount <3)   return   0; 
    s=y[0]*(x[vcount-1]-x[1]); 
    for   (i=1;i <vcount;i++) 
          s+=y[i]*(x[(i-1)]-x[(i+1)%vcount]); 
    return   s/2; 
    }

方法二:

算法版大牛海星原创

public   float   area_of_polygon(Point[]   APoints) 

        if   (APoints.Length   <   3)   return   0; 
        float   s   =   APoints[0].Y   *   (APoints[APoints.Length   -   1].X   -   APoints[1].X); 
        for   (int   i   =   1;   i   <   APoints.Length;   i++) 
                s   +=   APoints[i].Y   *   (APoints[(i   -   1)].X   -   
                        APoints[(i   +   1)   %   APoints.Length].X); 
        return   System.Math.Abs(s   /   2); 
}

private   void   button1_Click(object   sender,   EventArgs   e) 

        Text   =   area_of_polygon(new   Point[]   {   
                new   Point(0,   0),   new   Point(0,   10), 
                new   Point(10,   10),   new   Point(10,   0)}).ToString(); 
}

方法三:

生成多边形,其实就是指定这些顶点的顺序 
在确定了顺序后,   假定是p0,   p2,   ....,   pn-1 
那么多边形的面积可以简单的按照如下公式计算

float   area   =   0; 
for   (int   i=0,   j=1;   i <n;   i++,   j++) 

      j   =   j   %   n; //因为当j=n时候,需要让j回归1
      area   +=   p[i].x*p[j].y   -   p[i].y*p[j].x; 

area   =   fabs(   area   *   0.5);//取1/2再取绝对值,因为求出来的面积值可能为负(各顶点顺时针排列的时候)

时间: 2024-08-12 13:12:17

数学:知道n边形各顶点坐标,求面积的相关文章

MT【12】三点坐标求面积

$L_1,L_2$是O发出的两条射线,C是一个常数,一条动直线$l$分别与$L_1,L_2$交于A,B两点.$S_{\Delta ABC}=C$,求A,B的中点D的轨迹方程.(2012北大自主招生) 评:如果知道行列式的相关知识,可以由坐标直接求线段长,面积以及体积.

直接提取四个顶点坐标

%直接提取四个顶点坐标 clc;clear;close;%clc清除命令行,clear清除存在内存里的数据,close关闭打开了的文件, I=imread('e:\role0\003i.bmp'); %载入图像 I = I(:,:,1); BW=im2bw(I); figure ; imshow(~BW); [x,y]=getpts ;

osg::NodeVisitor中计算一个节点对应的世界变换矩阵、法向量、顶点坐标

class MyNodeVisitor:public osg::NodeVisitor { pulic: MyNodeVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} void apply(osg::Geode& geode) { //计算当前geode节点对应的世界变换矩阵,用来计算geode中顶点对应的世界坐标 osg::Matrix geodeMatrix=osg::computeLocalToWo

UVA 152-Tree&#39;s a Crowd(暴力求解三维坐标求最短距离)

Tree's a Crowd Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description  Tree's a Crowd  Dr William Larch, noted plant psychologist and inventor of the phrase ``Think like a tree--Think Fig'' has invented a new

Maximal Area Quadrilateral CodeForces - 340B || 三点坐标求三角形面积

Maximal Area Quadrilateral CodeForces - 340B 三点坐标求三角形面积(可以带正负,表示向量/点的不同相对位置): http://www.cnblogs.com/xiexinxinlove/p/3708147.html https://jingyan.baidu.com/article/a65957f49596ab24e67f9be7.html 枚举对角线,求出在对角线两侧取任意点能得到的三角形的面积,然后对于每条对角线,最大值就是两侧面积最大值之和. 1

WebGL通过getAttribLocation向顶点坐标器传递信息

<canvas style="border: red solid 3px;" id='webgl' width='500' height='500'>不支持</canvas> <script> //顶点着色器程序 var VSH = 'attribute vec4 a_Position;\n' + 'attribute float a_PointSize;\n' + 'void main(){\n' + 'gl_Position = a_Positi

由顶点坐标计算任意多边形面积

我们知道,如果三角形的一个顶点在原点,另两点A(x1 , y1)和B(x2 , y2) 则其面积可以表示为 SABC =0.5× |OA|×|OB|×sin(∠AOB) =0.5×|OA×OB| =0.5×|(x1,y1)×(x2,y2)| =0.5×[(x1y2)-(y1x2)] 以下图中的三角形ABC为例,欲求SABC 从原点,将ABC以向量形式表示 因此SABC = SOBC-SOAC-SOAB =SABC = SOBC + (-SOAC) + (-SOAB) 这样直接求ABC的面积转化为

nyoj-67-三角形面积(S=(1/2)*(x1y2+x2y3+x3y1-x1y3-x2y1-x3y2))

题目链接 1 /* 2 Name:nyoj-67-三角形面积 3 Copyright: 4 Author: 5 Date: 2018/4/26 16:44:47 6 Description: 7 三角形的三个顶点坐标求其面积的公式为: 8 S=(1/2)*(x1y2+x2y3+x3y1-x1y3-x2y1-x3y2) 9 */ 10 #include <iostream> 11 #include <cstdio> 12 using namespace std; 13 int mai

无线传感器网络中的节点定位技术

原文:http://www.cnblogs.com/dolphin0520/archive/2013/05/03/3056789.html 无线传感器网络的许多应用要求节点知道自身的位置信息,才能向用户提供有用的检测服务.没有节点位置信息的监测数据在很多场合下是没有意义的.比如,对于森林火灾检测.天然气管道监测等应用,当有事件发生时,人们关心的一个首要问题就是事件发生在哪里,此时如果只知道发生了火灾却不知道火灾具体的发生地点,这种监测没有任何实质的意义,因此节点的位置信息对于很多场合是至关重要的