計算凸多邊形面積的算法

1. 思路:

  可以將凸多邊形(邊數n > 3)劃分為 (n - 2) 個三角形,分別運用向量叉積計算每個三角形的面積,最后累加各個三角形的面積就是多邊形的面積。

2. 求多邊形面積的算法模板:  

定義點的結構體
struct Point{    double x,y;} p[MAXPOINT];計算三角形面積 
double getS(Point a,Point b,Point c)    {  return ((b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)) / 2; ? //應用叉積的定義推出的 }計算多邊形面積。必須確保 n>=3,且多邊形是凸多邊形 
double getPS(Point p[], int n)    {double sumS = 0;for(int i = 1; i <= n - 1; i++)sumS += getS(p[1], p[i], p[i + 1]);  // n-2個三角形的面積和return sumS;}

?

轉載于:https://www.cnblogs.com/xiaoniunwp/p/3599031.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/377258.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/377258.shtml
英文地址,請注明出處:http://en.pswp.cn/news/377258.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Windows CE開發常見問題解答

轉自&#xff1a; http://blog.csdn.net/slyzhang/article/details/6110490 1.怎樣在一個控件獲得焦點時打開軟鍵盤&#xff1f;比如一個EditBox獲得焦點后&#xff0c;這個時候自動打開軟鍵盤&#xff0c;這樣可以方便用戶輸入——SIPINFO、SHSIPINFO、SIPSETINFO、SIPGETINFO…

Julia中的supertype()函數

Julia| supertype()函數 (Julia | supertype() function) supertype() function is a library function in Julia programming language, it is used to get the concrete supertype of the given type (data type). supertype()函數是Julia編程語言中的庫函數&#xff0c;用于…

《操作系統知識點整理》

目錄進程與線程比較多線程同步與互斥生產者與消費者哲學家就餐問題讀者寫者問題進程間通信管道消息隊列共享內存信號量信號Socket鎖互斥鎖與自旋鎖讀寫鎖樂觀鎖與悲觀鎖死鎖進程與線程比較 進程是資源&#xff08;包括內存、打開的文件等&#xff09;分配的單位&#xff0c;線…

for,foreach,iterator的用法和區別

相同點&#xff1a; 三個都可以用來遍歷數組和集合不同點&#xff1a;1.形式差別 for的形式是 for&#xff08;int i0;i<arr.size();i&#xff09;{...} foreach的形式是 for&#xff08;int i&…

和菜鳥一起學linux總線驅動之初識spi驅動主要結構

既然知道了協議了&#xff0c;那么就可以開始去瞧瞧linux kenerl中的spi的驅動代碼了&#xff0c;代碼中有很多的結構體&#xff0c;還是對主要的結構體先做個了解吧&#xff0c;那樣才可以很好的理解驅動。主要是include/linux/spi.h 首先是SPI的主機和從機通信接口&#xff0…

操作系統大內核和微內核_操作系統中的內核

操作系統大內核和微內核A Kernel is the central component of an Operating System. The Kernel is also said to be the heart of the Operating System. It is responsible for managing all the processes, memory, files, etc. The Kernel functions at the lowest level …

《MySQL——鎖》

全局鎖是什么&#xff1f;全局鎖有什么用&#xff1f;全局鎖怎么用&#xff1f; 全局鎖主要用在邏輯備份過程中&#xff0c;對于InnoDB 引擎的庫&#xff0c;使用–single-transaction; MySQL 提供了一個加全局讀鎖的方法&#xff0c;命令是 Flush tables with read lock (FTW…

搜索引擎Constellio及Google Search Appliances connectors

做搜索產品的時候發現國外一個同類型的產品contellio&#xff0c;發現功能比較強大&#xff0c;先記錄下來 貌似可以添加文檔 網站 以及數據庫等不同類型的數據源 http://wiki.constellio.com/index.php/Main_Page http://www.constellio.com/ http://www.constellio.com htt…

dig下載_DIG的完整形式是什么?

dig下載DIG&#xff1a;副監察長 (DIG: Deputy Inspector General) DIG is an abbreviation of the Deputy Inspector General. It is a high-level position in the Indian Police Service. The officers who already offered service on Senior Superintendent of Police (SS…

分類器是如何做檢測的?——CascadeClassifier中的detectMultiScale函數解讀

原地址&#xff1a;http://blog.csdn.net/delltdk/article/details/9186875 在進入detectMultiScal函數之前&#xff0c;首先需要對CascadeClassifier做初始化。 1. 初始化——read函數 CascadeClassifier的初始化很簡單&#xff1a; cv::CascadeClassifier classifier; cl…

<MySQL>何時使用普通索引,何時使用唯一索引

如果能夠保證業務代碼不會寫入重復數據&#xff0c;就可以繼續往下看。 如果業務不能保證&#xff0c;那么必須創建唯一索引。 關于查詢能力 普通索引和唯一索引在查詢能力上是沒有很大差別的。 如&#xff1a;select id from T where k5 1、普通索引查找到滿足條件的第一個記…

Web版OutLook,利用POP接收郵件服務器郵件

一直想做一個Web版的OutLook&#xff0c;所以才萌生這個想法&#xff0c;其實以前也接觸過這方面的東西。于是上網找了找&#xff0c;漫天的都是Jmail來接收&#xff0c;好吧&#xff0c;既然大家都在用我也就下載下來試試了。 什么&#xff0c;怎么總是報錯呢&#xff1f;原來…

abs std::abs_ABS的完整形式是什么?

abs std::absABS&#xff1a;防抱死制動系統 (ABS: Anti-lock Braking System) ABS is an abbreviation of the Anti-lock Braking System. It is a safety anti-skid braking system that is used on a variety of aircraft, automobiles and other land vehicles, such as mo…

ubuntu 使用

shell 命令歷史搜索 &#xff1a; ctrl r使能 session 選擇界面&#xff1a;安裝gnome-session-fallback安裝lwqq轉載于:https://www.cnblogs.com/JonnyLulu/p/3600263.html

漢字速查使用方法簡介

《漢字速查》&#xff08;HanziSearcher&#xff09;是一個支持全漢字字典和詞典的檢索工具。其界面如下所示。 界面上方為工具欄。 左方為字典和詞典檢索欄。 右方在啟動時顯示版權信息和作者的聯系方式&#xff0c;在執行檢索時&#xff0c;顯示檢索結果。 檢索方法 漢字速查…

android jni示例_Android服務示例

android jni示例A service is a component that runs in the background for supporting different types of operations that are long running. The user is not interacted with these. These perform task even if application is destroyed. Examples include handling of…

《MySQL——選錯索引,該如何做》

如果不斷地刪除歷史數據和新增數據&#xff0c;MySQL有時會選錯索引。 選擇索引是優化器的工作&#xff0c;優化器優化時會考慮的因素&#xff1a;掃描行數、是否需要排序、是否使用臨時表 MySQL通過統計索引上的基數&#xff0c;作為索引的區分度。 統計方法時采樣統計&#x…

LPWSTR 類型的實參與const.char *類型形參不兼容

CString csPlus; CString csSummand; m_PlusNumber.GetWindowTextW(csPlus); m_Summand.GetWindowTextW(csSummand); int nPlus atoi(csPlus.GetBuffer(0)); //將編輯框文本轉換成整數// int nPlus atoi(strcpy(csPlus.GetBuffer(10),"aa")); csPlus.ReleaseBu…

空間換時間,把遞歸的時間復雜度降低到O(2n)

遞歸算法的時間復雜度除非只有前兩項&#xff0c;否則都不是線性的&#xff0c;并且相當耗費內存。我們用最常見的的fibonacci數列來說明&#xff1a; function fibonacci(n){if( n 0 || n 1){return n;} else {return fibonacci(n - 1) fibonacci(n - 2);} } 這是一種最常見…

scala char_Scala中的Char數據類型

scala charScala Char數據類型 (Scala Char Data Type) Character (char) in Scala is a data type that is equivalent to 16-bit unsigned integer. The character data type stores a single character. It can be an alphabet, numbers, symbols, etc. The character takes…