Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 50 additions & 15 deletions TriangleApplication/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TriangleApplication"
mc:Ignorable="d"
Title="Triangle Application" Height="400" Width="460"
Title="Triangle Application" Height="400" Width="920"
WindowStartupLocation="CenterScreen"
ResizeMode="CanMinimize"
WindowStyle="None"
Expand All @@ -15,19 +15,30 @@
<!--Entire window-->
<Border CornerRadius="10 10 10 10"
Background="#CC6F29">
<!--Place contents in a stackpanel-->
<StackPanel>
<!--Place contents in a grid-->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="0.4*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--Title, min, and close buttons-->
<Border CornerRadius="9 9 0 0"
Background="#212121">
<StackPanel Orientation="Horizontal">
Background="#212121"
Grid.ColumnSpan="2">
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Center">
<Label Content="Triangle Application"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Center"
FontWeight="Bold"
FontSize="32"
Foreground="#ffffff"
Margin="50 5 20 5"/>
Margin="290,5,230,5"/>
<Button x:Name="BtnMin"
Content="—"
ToolTip="Minimize"
Expand All @@ -53,13 +64,13 @@
Margin="15"
Background="#706258"
BorderThickness="1"
BorderBrush="#212121">
BorderBrush="#212121"
Grid.Row="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="2*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*"/>
Expand Down Expand Up @@ -99,7 +110,7 @@
HorizontalContentAlignment="Left"
VerticalContentAlignment="Center"
Padding="2,0"
Margin="5"
Margin="4"
Background="Transparent"
BorderThickness="0"
FontSize="14"
Expand All @@ -115,7 +126,7 @@
Background="#ffffff">
<TextBox x:Name="TxtBoxSideB"
Padding="2,0"
Margin="5"
Margin="4"
Background="Transparent"
BorderThickness="0"
FontSize="14"
Expand All @@ -133,7 +144,7 @@
Background="#ffffff">
<TextBox x:Name="TxtBoxSideC"
Padding="2,0"
Margin="5"
Margin="4"
Background="Transparent"
BorderThickness="0"
FontSize="14"
Expand All @@ -146,7 +157,7 @@
</Border>
</Grid>
<Border.Effect>
<DropShadowEffect BlurRadius="10" ShadowDepth="1" Direction="270" Color="#706258"/>
<DropShadowEffect BlurRadius="10" ShadowDepth="5" Direction="270" Color="#706258"/>
</Border.Effect>
</Border>

Expand All @@ -155,7 +166,8 @@
CornerRadius="10"
Margin="15 5 15 15"
BorderThickness="1"
BorderBrush="#212121">
BorderBrush="#212121"
Grid.Row="2">
<TextBlock x:Name="TxtBlockResults"
Foreground="#ffffff"
FontSize="18"
Expand All @@ -165,9 +177,32 @@
TextWrapping="Wrap"
Margin="5 10 5 10"/>
<Border.Effect>
<DropShadowEffect BlurRadius="10" ShadowDepth="1" Direction="270" Color="#706258"/>
<DropShadowEffect BlurRadius="10" ShadowDepth="5" Direction="270" Color="#706258"/>
</Border.Effect>
</Border>

<!--Triangle canvas-->
<Border Grid.Row="1"
Grid.Column="1"
Grid.RowSpan="2"
Background="#ffffff"
CornerRadius="10"
Margin="15"
BorderThickness="1"
BorderBrush="#212121">
<Canvas x:Name="CanvasShape"
Height="300"
Width="430">
<Polygon x:Name="PolyTriangle"
Canvas.Top="150"
Canvas.Left="215"
Stroke="Black"
StrokeThickness="4"/>
</Canvas>
<Border.Effect>
<DropShadowEffect BlurRadius="10" ShadowDepth="5" Direction="270" Color="#706258"/>
</Border.Effect>
</Border>
</StackPanel>
</Grid>
</Border>
</Window>
39 changes: 38 additions & 1 deletion TriangleApplication/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Windows;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;

namespace TriangleApplication
{
Expand Down Expand Up @@ -44,6 +46,8 @@ private void TxtBoxSide_TextChanged(object sender, TextChangedEventArgs e)
? $"These side lengths produce a valid {triangle.GetTriangleAngleType()} {triangle.GetTriangleSideType()} triangle.\n\n" +
$"The angles for the triangle are:\n{triangle.AngleA}°, {triangle.AngleB}°, {triangle.AngleC}°"
: "A triangle is not possible with the given values.";

DrawTriangle(triangle);
}
else
{
Expand All @@ -57,6 +61,39 @@ private void TxtBoxSide_TextChanged(object sender, TextChangedEventArgs e)
}
}

private void DrawTriangle(Triangle triangle)
{
// canvas limits
// top left is 0 0, bottom right is 430 300
// Height = "300"
// Width = "430"
// middle of canvas = 215, 150
// upper limits are 215, 150 for scaling

// we also know the angles so...
double x1 = triangle.SideA;
double y1 = 0;

double x2 = 0;
double y2 = 0;

// x = x1 + m(y2 - y1) / n
double x3 = x1 + (triangle.SideA * (y1 - y2) / triangle.SideB);
double y3 = triangle.SideC;
//x = start_x + len * cos(angle);
//y = start_y + len * sin(angle);
// assume we draw the triangle at x, y = 0

// need to perform calculations prior to this
Point pointA = new Point(x1, y1);
Point pointB = new Point(x2, y2);
Point pointC = new Point(x3, y3);

PointCollection points = new PointCollection() { pointA, pointB, pointC};

PolyTriangle.Points = points;
}

/// <summary>
/// Validates all user input. Checks if the text boxes
/// are empty and if they have valid values (integers and floats).
Expand Down
9 changes: 8 additions & 1 deletion TriangleApplication/Triangle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ internal class Triangle
public double SideA { get; set; }
public double SideB { get; set; }
public double SideC { get; set; }
public double AngleB { get; set; }
public double AngleA { get; set; }
public double AngleB { get; set; }
public double AngleC { get; set; }
public double RadianA { get; set; }
public double RadianB { get; set; }
public double RadianC { get; set; }

public Triangle(double a, double b, double c)
{
Expand Down Expand Up @@ -53,6 +56,10 @@ public void SetTriangleAngles()
double powB = Math.Pow(SideB, 2);
double powC = Math.Pow(SideC, 2);

RadianA = Math.Round(Math.Acos((powA + powB - powC) / (2 * SideA * SideB)), 2);
RadianB = Math.Round(Math.Acos((powB + powC - powA) / (2 * SideB * SideC)), 2);
RadianC = Math.Round(Math.Acos((powC + powA - powB) / (2 * SideC * SideA)), 2);

// calculate the angles and round them to 2 decimal places, converts to degrees
AngleA = Math.Round(Math.Acos((powA + powB - powC) / (2 * SideA * SideB)) * (180 / Math.PI), 2);
AngleB = Math.Round(Math.Acos((powB + powC - powA) / (2 * SideB * SideC)) * (180 / Math.PI), 2);
Expand Down