Skip to content

Instantly share code, notes, and snippets.

@gurland
Created December 16, 2019 07:16
Show Gist options
  • Save gurland/65914ca863d1886ab01faa820f57e089 to your computer and use it in GitHub Desktop.
Save gurland/65914ca863d1886ab01faa820f57e089 to your computer and use it in GitHub Desktop.
3FacePyramid Sizes
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