a fast algorithm to compute the area of a polygon
2012-07-07 13:15
260 查看
Assume there is a polygon (v1, v2,...vn), where vi, (1<=i<=n) are its vertices. What is the area of this polygon?
We have learnt cross product, which can be used to calculate the area of a triangle. We can also use this to calculate the area of a polygon by dividing the polygon with n segments into triangles. So the question is how to divide the polygon into triangles. We can choose a vertex A, and connect this vertex, A, to the vertices of the polygon.
There are various ways to achieve this which need proving. One way is use one vertex of the polygon as vertex A. Another way is to choose origin (0, 0) as vertex A. We can connect A(0, 0) with vi (1<=i<=n) to form triangles, A-v1-v2, A-v2-v3, A-v3-v4,...A-vn-1-vn, A-vn-v1. We can sum all the areas of these triangle, and the sum is 2 times the size of the area of polygon, labled as S.
2*S = |S(A-v1-v2) + S(A-v2-v3)+...+S(A-vn-1-vn)+S(A-vn-v1)|
= |x1y2-x2y1 + x2y3-x3y2 +...+ x(n-1)yn-xny(n-1)+xny1-x1yn|
which needs 2*n multiplications of double type.
We can reduce the calling of mulplications of double type to n by an observation, x2y2-x1y1 + x3y3-x2y2 + ... + ynxn - x(n-1)y(n-1) + x1y1 - xnyn = 0.
So 2*S = |x1y2-x2y1 + x2y3-x3y2 +...+ x(n-1)yn-xny(n-1)+xny1-x1yn + x2y2-x1y1 + x3y3-x2y2 + ... + ynxn - x(n-1)y(n-1) + x1y1 - xnyn |
= |(x1+x2)*(y2-y1) + (x2+x3)(y3-y2) +...+(x(n-1)+xn)*(yn-y(n-1)) + (xn+x1)*(y1-yn)|
which needs n multiplications of double type. This is the fast algorithm I have seen to compute the area of a polygon.
We have learnt cross product, which can be used to calculate the area of a triangle. We can also use this to calculate the area of a polygon by dividing the polygon with n segments into triangles. So the question is how to divide the polygon into triangles. We can choose a vertex A, and connect this vertex, A, to the vertices of the polygon.
There are various ways to achieve this which need proving. One way is use one vertex of the polygon as vertex A. Another way is to choose origin (0, 0) as vertex A. We can connect A(0, 0) with vi (1<=i<=n) to form triangles, A-v1-v2, A-v2-v3, A-v3-v4,...A-vn-1-vn, A-vn-v1. We can sum all the areas of these triangle, and the sum is 2 times the size of the area of polygon, labled as S.
2*S = |S(A-v1-v2) + S(A-v2-v3)+...+S(A-vn-1-vn)+S(A-vn-v1)|
= |x1y2-x2y1 + x2y3-x3y2 +...+ x(n-1)yn-xny(n-1)+xny1-x1yn|
which needs 2*n multiplications of double type.
We can reduce the calling of mulplications of double type to n by an observation, x2y2-x1y1 + x3y3-x2y2 + ... + ynxn - x(n-1)y(n-1) + x1y1 - xnyn = 0.
So 2*S = |x1y2-x2y1 + x2y3-x3y2 +...+ x(n-1)yn-xny(n-1)+xny1-x1yn + x2y2-x1y1 + x3y3-x2y2 + ... + ynxn - x(n-1)y(n-1) + x1y1 - xnyn |
= |(x1+x2)*(y2-y1) + (x2+x3)(y3-y2) +...+(x(n-1)+xn)*(yn-y(n-1)) + (xn+x1)*(y1-yn)|
which needs n multiplications of double type. This is the fast algorithm I have seen to compute the area of a polygon.
相关文章推荐
- Algorithm to find the area of a polygon
- Reducing the Dimensionality of data with neural networks / A fast learing algorithm for deep belief net
- Find the maximum of the three numbers(Take this opportunity to review the sorting algorithm)
- CareerCup Compute the rearrangement of x that is closest to y but still greater than y
- 159 Which three types of files can be automatically placed in the flash recovery area (fast recovery
- Fast algorithm to compute minimum volume oriented bounding box
- Introduction to Algorithm - Summary of Chapter 1 - The Role of Algorithm in Computing
- How to calculate the rectangle area of a projected sphere
- "A Halting Algorithm to Determine the Existence of the Decoder" accepted by TCAD
- Simple test ----Compute the area of a circle
- How to build the topology of an OSPF area
- A Fast Priority Queue Implementation of the Dijkstra Shortest Path Algorithm
- [the summarization of algorithm]How to list the prime number
- The rxfastforest algorithm case of kaggle
- Give an O(lg n)-time algorithm to find the median of all 2n elements in arrays X and Y.
- Fast ways in R to get the first row of a data frame grouped by an identifier
- Q.2.3 Implement an algorithm to delete a node in the middle of a single linked list, given only acce
- Debug:This kind of launch is configured to openthe debug perspective when it解决办法
- Xingbang mobile crushing plant to contribute to the construction of the Green Cities
- Warning: Unable to determine the number of frames in this file