Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Minimum Cost Polygon Triangulation
When nonintersecting diagonals are forming a triangle in a polygon, it is called the triangulation. Our task is to find a minimum cost of triangulation.
The cost of triangulation is the sum of the weights of its component triangles. We can find the weight of each triangle by adding their sides, in other words, the weight is the perimeter of the triangle.
Input and Output
Input:
The points of a polygon. {(0, 0), (1, 0), (2, 1), (1, 2), (0, 2)}
Output:
The total cost of the triangulation. Here the cost of the triangulation is 15.3006.
Algorithm
minCost(polygon, n)
Here cost() will be used to calculate the perimeter of a triangle.
Input: A set of points to make a polygon, and a number of points.
Output − Minimum cost for triangulation of a polygon.
Begin if n val table[i, j] := val i := i + 1 done done return table[0, n-1] End
Example
#include#include #include #define MAX 1000000.0 using namespace std; struct Point { int x, y; }; double min(double x, double y) { return (x val) table[i][j] = val; //update table data to minimum value } } } } return table[0][n-1]; } int main() { Point points[] = {{0, 0}, {1, 0}, {2, 1}, {1, 2}, {0, 2}}; int n = 5; cout Output
The minimumcost: 15.3006
Advertisements
