TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
bn9
NA
24
0
need help finishing program!
Mar 30 2004 3:46 PM
i have the following program to figure the largest area of a triangle give a set of points. i have the class written to perform the needed mathematics but i am having some trouble getting it to work. can anyone help me!??? thank you To compute the area of a triangle use the formula: area = radical (s(s-a)(s-b)(s-c)) s - (a+b+c)/2 where and a, b, and c are the three sides of the triangle. To calculate the length of the sides you can use the distance formula: radical (x1-x2)^2+(y1+y2)^2 x1,x2 is one point y1,y2 is the second point where are the coordinates of one point and is the coodinates of the second point. DATA 1. 0,0 2. 5,4 3. -7, -4 4. -2, 6 5. 4, -3 6. 1, 10 7. 0, -6 ______________________________________ private void btnFindLargest_Click(object sender, System.EventArgs e) {int i, j, k; int iMax, jMax, kMax; double [,] v = { {0,0}, {5,4}, {-7, -4}, {-2, 6}, {4, -3}, {1, 10}, {0, -6} }; double maxArea, area = 0; iMax = 0;jMax = 1;kMax = 2; maxArea = FindArea(v, iMax, jMax, kMax); for(i=0;i
maxArea) {iMax = i; jMax = j; kMax = k; maxArea = area; } } } } lstPoints.Items.Add("Maximum area is " + maxArea.ToString()); lstPoints.Items.Add("Vertex 1 is at " + v[iMax,0].ToString() + ", " + v[iMax,1].ToString()); lstPoints.Items.Add("Vertex 2 is at " + v[jMax,0].ToString() + ", " + v[jMax,1].ToString()); lstPoints.Items.Add("Vertex 3 is at " + v[kMax,0].ToString() + ", " + v[kMax,1].ToString()); } // private double FindArea(double [,] v, int i, int j, int k) {double a, b, c, s; a = FindDistance(v, i, j); b = FindDistance(v, i, k); c = FindDistance(v, j, k); s = (a + b + c)/2; return Math.Sqrt(s*(s-a)*(s-b)*(s-c)); } // private double FindDistance(double [,]v, int x, int y) {double x1, y1, x2, y2; x1 = v[x,0]; y1 = v[x,1]; x2 = v[y,0]; y2 = v[y,1]; return Math.Sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)); }
Reply
Answers (
0
)
Lable Control
Convert.ToDateTime