C Sharp Triangle Class

By wade2462 on Jun 20, 2010

Not Yet completely finished... at least in my mind. Feel free to use this code in your own projects.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Geometry
{
    public class triangle
    {
        public triangle(double GivenBase, double GivenHeight, double GivenHypotenuse, string GivenType,
                        double GivenAA = 0, double GivenBA = 0, double GivenCA= 0)
        {
            Base_Length = GivenBase;
            Height_Length = GivenHeight;
            Hypotenuse_Length = GivenHypotenuse;
            if (GivenType == "right")
            {
                if (GivenAA != 0 || GivenBA != 0 || GivenCA != 0)
                {
                    A_Degrees = GivenAA;
                    B_Degrees = GivenBA;
                    C_Degrees = GivenCA;
                }
                else
                {
                    C_Degrees = 90;
                    B_Radians = Math.Asin(Base_Length / Hypotenuse_Length);
                    A_Radians = Math.Asin(Height_Length / Hypotenuse_Length);
                    B_Degrees = RadianToDegree(B_Radians);
                    A_Degrees = RadianToDegree(A_Radians);
                }

            }
            else
            {
                Type = GivenType;
                A_Degrees = GivenAA;
                B_Degrees = GivenBA;
                C_Degrees = GivenCA;
            }

        }

        private double Base_Length, Height_Length, Hypotenuse_Length;
        private double A_Degrees, B_Degrees, C_Degrees, A_Radians, B_Radians;
        string Type;

        private double RadianToDegree(double angle)
        {
            return angle * (180.0 / Math.PI);
        }

        public void WriteAngles()
        {
            Console.WriteLine("Angle A: {0,5}. Angle B: {1,5}. Angle C: {2,5}", A_Degrees.ToString(), B_Degrees.ToString(), C_Degrees.ToString());
        }

        public void WriteLengths()
        {
            Console.WriteLine("Base: {0,5}. Height: {1,5}. Hypotenuse: {2,5}.", Base_Length.ToString(), Height_Length.ToString(), Hypotenuse_Length.ToString());
        }

        public void WriteInfo()
        {
            WriteAngles();
            WriteLengths();
        }

        public double GetAngleA()
        {
            return A_Degrees;
        }
        public double GetAngleB()
        {
            return B_Degrees;
        }
        public double GetAngleC()
        {
            return C_Degrees;
        }
        public double GetBaseLength()
        {
            return Base_Length;
        }
        public double GetHeightLength()
        {
            return Height_Length;
        }
        public double GetHypotenuseLength()
        {
            return Hypotenuse_Length;
        }

    }
}

Comments

Sign in to comment.
newbattery   -  Jan 07, 2011
newbattery   -  Jan 07, 2011
Jethro   -  Dec 15, 2010

Season's greetings from spammers all 'round the world. ;>

 Respond  
napa182   -  Dec 15, 2010

spammers hitting a new pathetic low =/

 Respond  
xiaole001   -  Dec 15, 2010

sell digital camera battery charger,It should be me like one
panasonic batteries
Digital camera batteries
laptop battery

 Respond  
battery   -  Dec 15, 2010
battery   -  Dec 15, 2010

so good

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.