# shit math

user_2869209
plain_text
2 years ago
5.7 kB
1
Indexable
Never
```namespace Project_2___Object_Collisions
{

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

int ReadTextInput(TextBox textBox1, ref double a)
{

try
{
a = Convert.ToDouble(textBox1.Text);

}
catch
{
MessageBox.Show("Please enter an integer in each textbox.");
txtCentreX1.Focus();
return 1;
}

return 0;

}
private void btnCheck_Click(object sender, EventArgs e)
{
//If using subroutines call them.

//if no subroutines:
//For a sphere:
//Calculate each radius and distance between centres.
//Check and report based on condition

//For boxes:
//Calculate oposite vertexes.
//Determine max and min for each coordinate of x,y,z (create min and max point which stores the max and min in respective variables.)
//Output max and mins, check and report on conditions.

//Boxes input/calc. cp = centerPoint. also cp1,cp2,cp3 are center point of object 1. and cp4,cp5,cp6 are center point of object2.
// vt = vertex. also vt1,vt2,vt3 = vertex object 1, therefore vt4, vt5, vt6 = vertex object 2.
// cX = centerX, cY = centerY cZ = centerZ.
// vCollX = vertex collisionX vCollY = vertex collisionY vCollZ = vertex collisionZ

BoxesCirclesCheck();

}

void BoxesCirclesCheck()
{
grpSpheres.Visible = true;
grpBoxes.Visible = true;
//   Object 1.            Object 2.

double cp1, cp2, cp3, cp4, cp5, cp6;
double vt1, vt2, vt3, vt4, vt5, vt6;

cp1 = 0; cp2 = 0; cp3 = 0; cp4 = 0; cp5 = 0; cp6 = 0;
vt1 = 0; vt2 = 0; vt3 = 0; vt4 = 0; vt5 = 0; vt6 = 0;

//Object 1.
//Object 2.

double vCollX = secondVertexFunction(cp1, vt1);
double vCollY = secondVertexFunction(cp2, vt2);
double vCollZ = secondVertexFunction(cp3, vt3);

double vColl2X = secondVertexFunction(cp4, vt4);
double vColl2Y = secondVertexFunction(cp5, vt5);
double vColl2Z = secondVertexFunction(cp6, vt6);

//  vt1 cp1      vt2 cp2    vt3  cp3
//r^2 = sqroot (x - h)^2 +  (y - k)^2 + (z - p)^2

double distancevariable = 0;
double distance;
distance = distanceFunction(distancevariable, cp1, cp2, cp3, cp4, cp5, cp6);

double min;
double max;
double min2;
double max2;

lblDistance.Text = "Distance between objects is: " + distance;

}
double secondVertexFunction(double cpv, double vtv)
{
double newVert;
newVert = 2 * cpv - vtv;
return newVert;
}

double radiusFunction(double radiusV, double cpX, double cpY, double cpZ, double vtX, double vtY, double vtZ)
{
double square = 2;
radiusV = Math.Pow((vtX - cpX), square) + Math.Pow((vtY - cpY), square) + Math.Pow((vtZ - cpZ) , square);
}

double distanceFunction(double distance, double cpX, double cpY, double cpZ, double cpX2, double cpY2, double cpZ2)
{
double square = 2;
distance = Math.Pow((cpX2- cpX),square) + Math.Pow((cpY2 - cpY), square) + Math.Pow((cpZ2 - cpZ), square);
return Math.Round(Math.Sqrt(distance),2);
}

private void btnClear_Click(object sender, EventArgs e)
{
txtCentreX1.Focus();

txtCentreX1.Text = " ";
txtCentreX2.Text = " ";
txtCentreY1.Text = " ";
txtCentreY2.Text = " ";
txtCentreZ1.Text = " ";
txtCentreZ2.Text = " ";
txtVertexX1.Text = " ";
txtVertexX2.Text = " ";
txtVertexY1.Text = " ";
txtVertexY2.Text = " ";
txtVertexZ1.Text = " ";
txtVertexZ2.Text = " ";
grpSpheres.Text = " ";
grpBoxes.Text = " ";
grpSpheres.Visible = false;
grpBoxes.Visible = false;

}

}

}```