5 Replies - 3912 Views - Last Post: 14 November 2009 - 09:02 AM Rate Topic: -----

#1 Keevu   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 13-September 09

How do i use trigonometry to calculate the type of triangle i am input

Posted 09 November 2009 - 01:08 PM

I need to calculate which type of triangle The user inputs, how do i use trigonometry to calculate which type of triangle it is equilateral, right, or right iscoseles? I have been trying to figure this out for about 2 weeks and I am completely stuck, will someone help me out?

thanks alot.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace triangle_mthhttp://www.dreamincode.net/forums/index.php?act=Post&CODE=02&f=84&t=137833&qpid=827787
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		//check to see if user typed a number into text box.
		public bool IsNumeric(string s)
		{
			try
			{
				Double.Parse(s);
			}
			catch
			{
				return (false);
			}

			return (true);
		} 

		//calculate button
		private void button1_Click(object sender, EventArgs e)
		{
			if (!IsNumeric(textBox1.Text) ||
				!IsNumeric(textBox2.Text) ||
				!IsNumeric(textBox3.Text))
			{
				MessageBox.Show("Enter side A, B, and C.");
				return;//error, so leave
			}
			
			{
				float sidea = float.Parse(textBox1.Text); //convert string to number
				float sideb = float.Parse(textBox2.Text); //convert string to number
				float sidec = float.Parse(textBox3.Text); //convert string to number

				Classify tri1 = new Classify();//instance of Class

				float peri = tri1.Peri(sidea, sideb, sidec);
				float s = ((sidea + sideb + sidec) / 2);
				float area = (s * (s - sidea) * (s - sideb) * (s - sidec));

				textBox4.Text = peri.ToString(); //Perimeter
				textBox5.Text = area.ToString(); //area
			}
		}

				//**************************************************
				// Count class:: Implement methods Add and Subtract.
				// This class can also be used as a "base" class 
				// last updated 9/27/09 (efa)
				//**************************************************
				public class MyMath 
				{
					public float Add(float n1, float n2)
					{
						return (n1 + n2);
					}

					public float Sub(float n1, float n2)
					{
						return (n1 - n2);
					}
				}

				//**************************************************
				// Group class:: Implement methods Multiply and Divide.
				// last updated 9/27/09 (efa)
				//**************************************************
				public class TriMath:MyMath //This class has inherited from 
				{						//the base class "Count"
					public float Peri(float sidea, float sideb, float sidec)
					{
						return (sidea + sideb + sidec);
					}

				public float Div(float n1, float n2)
					{
							return (n1 / n2);
					}
				}

				//**************************************************
				// Group MyMath:: Implement method Pow and inherite
				// other methods from "Group" and "Count" classes.
				// last updated 9/27/09 (efa)
				//**************************************************
				public class Classify:TriMath
				{
					public float Pow(float n1, float n2)
					{
						return ( (float) Math.Pow(n1,n2) ); //n1 raised to the n2 power
					}
				}

		}
	}

This post has been edited by Keevu: 09 November 2009 - 01:09 PM


Is This A Good Question/Topic? 0
  • +

Replies To: How do i use trigonometry to calculate the type of triangle i am input

#2 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: How do i use trigonometry to calculate the type of triangle i am input

Posted 09 November 2009 - 01:08 PM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#3 Keevu   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 13-September 09

Re: How do i use trigonometry to calculate the type of triangle i am input

Posted 09 November 2009 - 01:12 PM

View PostPsychoCoder, on 9 Nov, 2009 - 12:08 PM, said:

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field



I do not know how to get the code to calculate the type of triangle it is. It needs to label the triangle either a right triangle, an equilateral triangle, or a right isosceles triangle. I cannot figure out how to do this and I have been working for 2 weeks.


edit: and there are no errors btw.

This post has been edited by Keevu: 09 November 2009 - 01:16 PM

Was This Post Helpful? 0
  • +
  • -

#4 Momerath   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1021
  • View blog
  • Posts: 2,463
  • Joined: 04-October 09

Re: How do i use trigonometry to calculate the type of triangle i am input

Posted 09 November 2009 - 01:42 PM

equilateral = all sides must be equal length
right triangle = sum of square of short sides = square of long side
other - not one of the above.
Was This Post Helpful? 1

#5 Keevu   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 13-September 09

Re: How do i use trigonometry to calculate the type of triangle i am input

Posted 13 November 2009 - 03:59 PM

View PostMomerath, on 9 Nov, 2009 - 12:42 PM, said:

equilateral = all sides must be equal length
right triangle = sum of square of short sides = square of long side
other - not one of the above.



can you give me an equation fr right triangle.. I am still having trouble I have tried but its not working.
Was This Post Helpful? 0
  • +
  • -

#6 Qball522   User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 86
  • Joined: 06-October 08

Re: How do i use trigonometry to calculate the type of triangle i am input

Posted 14 November 2009 - 09:02 AM

Correct me if I am wrong.

Right triangle has 2 sides squared that equal the other side squared. ie. A^2 + B^2 = C^2

There are 3 types of triangles when it come to length.
1) Equilateral= all 3 side of equal length.
2) Isosceles= 2 side of equal length.
3) Scalene = no 2 side are equal, all 3 side have different length.

If you are using lengths of all the sides, it shouldn't be that difficult.
If however you are using points on a coordinate plane that is a little tricky.
To get the distance between 2 points the formula is as follows

D(P, Q) = SquareRoot((x1 - x2) ^ 2 + (y1- y2) ^ 2)

Where:
D = Distance
P = First Point
Q = Second Point


Hope this has helped.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1