Need help!! Please provide a step-by-step solution through the use of mathematic
ID: 3713300 • Letter: N
Question
Need help!! Please provide a step-by-step solution through the use of mathematica code along with a detailed explanation!!!! This is very URGENT!!! PLEASE reply as soon as possible!! Thank you!!
Number of data points) numpts 5; Test data set) ptso, e), (l, e, (o, 1), (1, 1), (o.3, .4 dmesh DelaunayMesh [pts] Extract the triangle list from the Delaunay triangulation ) tris Meshcells [dmesh, 2] numtris -Length[tris]; * This demonstrates how to access the pts from the tris list ) Print[" Number of triangles numtris - ", numtris]; Do Print[ Tri ", i, v1-", pts [[tris[[i, 1, 1]111, " V2-", pts [[tris[ [i, 1, 2]]11, 3ltristti, 1, 3 fi, 1, numtris) 1: Number of triangles numtris-4 Tri 1 v1-(0, 1 v2 [0, e v3-(0.3, 0.4 Tri 2 v1 0.3, 0.4) v2-11, 0 v3(1, 1) Tri 4 v1-0.3, 0.4) v2-(1, 1) v3 -(0, 1) B. Create a neighbor list for a given triangulation as discussed in class. Data structure to hold neighbor data) nghbrs Table[ (e, o, e), (i, 1, numtris]; Your code here )Explanation / Answer
#include <iostream>
#include <cmath>
#define MAX 1000000.0
using namespace std;
struct Point
{
float x, y;
};
// minimum of two double values
double min(double x, double y)
{
return (x <= y)? x : y;
}
// distance between two points in a plane
double dist(Point p1, Point p2)
{
return sqrt((p1.x - p2.x)*(p1.x - p2.x) +
(p1.y - p2.y)*(p1.y - p2.y));
}
// cost of a triangle. The cost is considered
// as perimeter (sum of lengths of all edges) of the triangle
double cost(Point points[], int i, int j, int k)
{
Point p1 = points[i], p2 = points[j], p3 = points[k];
return dist(p1, p2) + dist(p2, p3) + dist(p3, p1);
}
// minimum cost for convex
// polygon triangulation.
double mTCDP(Point points[], int n)
{
// 3 points to form a triangle
if (n < 3)
return 0;
// table[i][j] stores cost of triangulation
double table[n][n];
// table[0][n-1] which is the result.
for (int gap = 0; gap < n; gap++)
{
for (int i = 0, j = gap; j < n; i++, j++)
{
if (j < i+2)
table[i][j] = 0.0;
else
{
table[i][j] = MAX;
for (int k = i+1; k < j; k++)
{
double val = table[i][k] + table[k][j] + cost(points,i,j,k);
if (table[i][j] > val)
table[i][j] = val;
}
}
}
}
return table[0][n-1];
}
// Main Function
int main()
{
Point points[] = {{0, 0}, {1, 0}, {0, 1}, {1, 1}, {0.3,0.4}};
int n = sizeof(points)/sizeof(points[0]);
cout << mTCDP(points, n);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.