shit math
user_2869209
plain_text
3 years ago
5.7 kB
5
Indexable
namespace Project_2___Object_Collisions { public partial class Form1 : Form { public Form1() { InitializeComponent(); } //your code here 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) { //your code here //your code here //Read in all 4 points. //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. ReadTextInput(txtCentreX1, ref cp1); ReadTextInput(txtCentreY1, ref cp2); ReadTextInput(txtCentreZ1, ref cp3); ReadTextInput(txtVertexX1, ref vt1); ReadTextInput(txtVertexY1, ref vt2); ReadTextInput(txtVertexZ1, ref vt3); //Object 2. ReadTextInput(txtCentreX2, ref cp4); ReadTextInput(txtCentreX2, ref cp5); ReadTextInput(txtCentreY2, ref cp6); ReadTextInput(txtVertexX2, ref vt4); ReadTextInput(txtVertexY2, ref vt5); ReadTextInput(txtVertexZ2, ref vt6); 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); //Radius. // vt1 cp1 vt2 cp2 vt3 cp3 //r^2 = sqroot (x - h)^2 + (y - k)^2 + (z - p)^2 double radiusvariable1 = 0; double radiusvariable2 = 0; double distancevariable = 0; double distance; double radius1 = radiusFunction(radiusvariable1, cp1, cp2, cp3, vt1, vt2, vt3); double radius2 = radiusFunction(radiusvariable2, cp4, cp5, cp6, vt4, vt5, vt6); distance = distanceFunction(distancevariable, cp1, cp2, cp3, cp4, cp5, cp6); double min; double max; double min2; double max2; lblRadius1.Text = "Radius of bounding sphere for object 1 is: " + radius1; lblRadius2.Text = "Radius of bounding sphere for object 2 is: " + radius2; lblSumOfRadii.Text = "Sum of the two radii is: " + radius1 + radius2; 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); return Math.Round(Math.Sqrt(radiusV),2); } 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; } } }
Editor is loading...