Created
December 16, 2019 07:16
-
-
Save gurland/65914ca863d1886ab01faa820f57e089 to your computer and use it in GitHub Desktop.
3FacePyramid Sizes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 _3FacePyramid | |
{ | |
public partial class Form1 : Form | |
{ | |
double display_width, display_height; | |
double side, main; | |
private double get_triangle_area(double a, double b, double c) | |
{ | |
double p = (a + b + c) / 2.0; | |
return Math.Sqrt(p * (p - a) * (p - b) * (p - c)); | |
} | |
private void height_KeyDown(object sender, KeyEventArgs e) | |
{ | |
if (e.KeyCode == Keys.Enter) | |
{ | |
button1.PerformClick(); | |
e.Handled = true; | |
e.SuppressKeyPress = true; | |
} | |
} | |
private void width_KeyDown(object sender, KeyEventArgs e) | |
{ | |
if (e.KeyCode == Keys.Enter) | |
{ | |
button1.PerformClick(); | |
e.Handled = true; | |
e.SuppressKeyPress = true; | |
} | |
} | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
if (double.TryParse(width.Text, out display_width)) | |
{ | |
if (double.TryParse(height.Text, out display_height)) | |
{ | |
double side = Math.Sqrt(Math.Pow(display_width / 2, 2) + Math.Pow(display_height, 2)); | |
double cathet2 = Math.Sqrt(Math.Pow(display_height, 2) + Math.Pow((display_width/2), 2)); | |
double main = Math.Sqrt(Math.Pow(cathet2, 2) + Math.Pow(display_height, 2)); | |
pyramidHeight.Text = String.Format("{0:0.00}", display_height); | |
A1.Text = String.Format("{0:0.00}", side); | |
B1.Text = String.Format("{0:0.00}", main); | |
C1.Text = String.Format("{0:0.00}", display_height); | |
sideArea.Text = String.Format("{0:0.00}", get_triangle_area(side, main, display_height)); | |
A2.Text = String.Format("{0:0.00}", main); | |
B2.Text = String.Format("{0:0.00}", main); | |
C2.Text = String.Format("{0:0.00}", display_width); | |
mainArea.Text = String.Format("{0:0.00}", get_triangle_area(main, main, display_width)); | |
} | |
} | |
else | |
{ | |
//parsing failed. | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment