static void Main() { vector3d v = new vector3d(1, 0, 42); WriteLine($"v = {v}"); vector3d u = new vector3d(42, 42, 42); WriteLine($"u = {u}"); WriteLine($"v + u = {v+u}"); WriteLine($"v - u = {v-u}"); WriteLine($"3*u = {3*u}"); WriteLine($"u*3 = {u*3}"); WriteLine($"u/3 = {u/3}"); WriteLine($"v * u = {v*u}"); // vector3d s = v.crossP(u); WriteLine($"s = v x u = {v.crossP(u)}"); WriteLine($"v * s = {v.dotP(v.crossP(u))}"); WriteLine("Update values test"); WriteLine($"Old v: {v}"); v.X = 69; v.Y = 420; v.Z = 100100; WriteLine($"New v: {v}"); WriteLine($"Dotproduct method test: v*u = {v.dotP(u)}"); }
static int Main() { WriteLine("Part A:"); WriteLine("Test of vector3d:"); double c = 2; double x = 1; double y = 1; double z = 2; vector3d vec = new vector3d(x, y, z); vector3d vec2 = new vector3d(3, 2, 1); vector3d vec1 = c * vec; WriteLine($"v*c={vec1.x},{vec1.y},{vec1.z}"); vector3d vecplu = vec + vec1; WriteLine($"v+v1={vecplu.x},{vecplu.y},{vecplu.z}"); vector3d vecmin = vec1 - vec; WriteLine($"v-v1={vecmin.x},{vecmin.y},{vecmin.z}"); WriteLine($"vdot={dot_product(vec,vec2)}"); vector3d vecpru = vector_product(vec, vec2); WriteLine($"vpro={vecpru.x},{vecpru.y},{vecpru.z}"); WriteLine($"mag={magnitude(vec)}"); WriteLine("Part B:"); WriteLine("Test ofproperties"); WriteLine($"{vec2.x}"); vec2.xcor = 1; WriteLine($"{vec2.x}"); WriteLine($"{vec2.ycor}"); return(0); }
static void Main() { double c = 4; vector3d u = new vector3d(1, 2, 3); vector3d v = new vector3d(2, -7, 6); u.print("u = "); v.print("v = "); double d = ivector3dfunctions.dot(u, u); WriteLine($"dot(u,u) = {d}"); double e = ivector3dfunctions.dot(u, v); WriteLine($"dot(u,v) = {e}"); double f = ivector3dfunctions.magnitude(u); WriteLine($"|u|= {f}"); vector3d k = ivector3dfunctions.cross(u, u); k.print("cross(u,u) ="); vector3d l = ivector3dfunctions.cross(v, u); l.print("cross(u,v) ="); WriteLine($"4*v = {c*v}"); WriteLine($"u+v = {u+v}"); WriteLine($"v+u = {v+u}"); WriteLine($"u-v = {u-v}"); }
public static int Main() { vector3d v = new vector3d(1, 2, 3); vector3d u = new vector3d(7, 5, 8); v.print("v= "); u.print("u= "); vector3d w = u + v; w.print("w= "); (v * 2).print("2*v= "); vector3d A = v.vector_product(u); A.print("v x u = "); double B = v.dot_product(u); System.Console.Write("v dot u ={0}\n", B); double C = v.magnitude(); System.Console.Write("|v| ={0}\n", C); return(0); }
// Vector product public static vector3d vp(vector3d u, vector3d v) { vector3d r = new vector3d(u[1] * v[2] - u[2] * v[1], u[2] * v[0] - u[0] * v[2], u[0] * v[1] - u[1] * v[0]); return(r); }
// Subtraction public static vector3d operator-(vector3d u, vector3d v) { vector3d r = new vector3d(u[0] - v[0], u[1] - v[1], u[2] - v[2]); return(r); }
public static double magnitude(vector3d v) { double xs = Pow(v.x, 2); double ys = Pow(v.y, 2); double zs = Pow(v.z, 2); return(Sqrt(xs + ys + zs)); }
static void Main() { vector3d u = new vector3d(1, 2, 3); double d = ivector3dfunctions.dot(u, u); WriteLine($"test of dot function calleds using iterface dot(u,u)={d}, with u=(1,2,3)"); }
public vector3d vector_product(vector3d v) { double a = y * v.z - z * v.y; double b = z * v.x - x * v.z; double c = x * v.y - y * v.x; return(new vector3d(a, b, c)); }
static void Main() { double a = 2; double b = 3; double c = 4; double d = 8; vector3d u = new vector3d(a, b, c); vector3d v = new vector3d(2 * a, b, c); vector3d w = u + v; vector3d y = u - v; vector3d x = d * u; Write("The vector u is: "); Write(u); Write("The vector v is: "); Write(v); Write("The vector w = u + v is: "); Write(w); Write("The vector y = u - v is: "); Write(y); Write("The vector x = 8*u is: "); Write(x); WriteLine("\nAttempt at dot product:"); double dot = dot_product(u, v); WriteLine("The dot product of u and v is = {0}", dot); WriteLine("Correct dot product: 33\n"); vector3d cross = new vector3d(0, 0, 0); WriteLine("Attempt at cross product:"); cross = cross_product(u, v); Write("The cross product of u and v is = {0}", cross); WriteLine("Correct cross product: (0, 8, -6)\n"); WriteLine("Attempt at calculating the magnitude:"); double magni = magnitude(u); double magniCorrect = 5.385; WriteLine("The magnitude of u is {0:f3}", magni); WriteLine("Correct magnitude: {0}\n", magniCorrect); WriteLine("Let's try to change the x-value of the u vector to 5"); u.xval = 5; Write("The vector u is: "); Write(u); WriteLine("\nLet's try to read the z-value of the u vector"); double zvalue = u.zval; Write("The z-value of the u-vector is: "); WriteLine("{0}", zvalue); }
public static void Main() { vector3d v = new vector3d(1, 1, 1); vector3d u = new vector3d(1, 2, 3); Write($"{v}*{u} = " + v * u + "\n"); Write($" {v} - {u} = " + (v - u) + "\n"); Write($"|{v}| = " + v.magnitude() + "\n"); }
public static vector3d operator*(double a, vector3d b) { vector3d result = new vector3d(0, 0, 0); result.x = b.x * a; result.y = b.y * a; result.z = b.z * a; return(result); }
public static vector3d operator-(vector3d a, vector3d b) { vector3d result = new vector3d(0, 0, 0); result.x = a.x - b.x; result.y = a.y - b.y; result.z = a.z - b.z; return(result); }
// Subtraction public static vector3d operator-(vector3d u, vector3d v) { double i = u.x - v.x; double j = u.y - v.y; double k = u.z - v.z; vector3d w = new vector3d(i, j, k); return(w); }
// Cross product public static vector3d cross_product(vector3d u, vector3d v) { double i = u.y * v.z - u.z * v.y; double j = u.z * v.x - u.x * v.z; double k = u.x * v.y - u.y * v.x; vector3d w = new vector3d(i, j, k); return(w); }
public static int Main() { vector3d v = new vector3d(2, 2, 3); vector3d u = new vector3d(1, 1, 1); vector3d w = vector3d.vp(v, u); w.print(); double a = w.x; double b = w.y; double c = w.z; Write($"{a},{b},{c}\n"); return(0); }
public static void Main() { vector3d m = new vector3d(4, 5, 3); WriteLine($"test vector: {m}"); WriteLine($"to String: {m.ToString()}"); vector3d n = m * 2; WriteLine($"multiplication by 2, {n}"); double a = n.dot_product(m); WriteLine($"dot_product, {a}"); }
static void Main() { vector3d u = new vector3d(9, 9, 9); vector3d v = new vector3d(1, 2, 3); u.print("vector3d u ="); v.print("vector3d v ="); double d = ivector3dfunctions.dot(u, u); vector3d c = ivector3dfunctions.Cross(u, v); WriteLine($"The dot product of u with u is {d}"); WriteLine($"The cross product og u with v is ({c.x},{c.y},{c.z})"); }
static int Main() { vector3d v = new vector3d(1, 1, 2); vector3d u = new vector3d(0, 1, 0); Console.WriteLine($"Dot product of v = (1,1,2) and u = (0,1,0)"); Console.WriteLine($"v*u = {vector3d.dotproduct(u,v)}"); Console.WriteLine("Vector product:"); Console.WriteLine($"v x u = {vector3d.vectorproduct(v,u)}"); Console.WriteLine("Magnitude of v:"); Console.WriteLine($"|v| = {v.magnitude()}"); return(0); }
static int Main() { vector3d v = new vector3d(1, 1, 1); vector3d u = new vector3d(0, 2, 4); v.print("v="); u.print("u="); vector3d w1 = u + v; w1.print("u+v="); vector3d w2 = v + u; w2.print("v+u="); vector3d w3 = u - v; w3.print("u-v="); vector3d w4 = v - u; w4.print("v-u="); vector3d w5 = 3 * v; w5.print("3*v="); vector3d w6 = u * 3; w6.print("u*3="); double w7 = vector3d.dot_product(u, v); w7.print("u.v="); vector3d w8 = vector3d.vector_product(u, v); w8.print("uxv="); double magv = vector3d.magnitude(v); magv.print("|v|="); return(0); }
public static int Main() { var v = new vector3d(1, 2, 3); var u = new vector3d(3, 4, 5); WriteLine($"{v} + {u} = {v+u}"); WriteLine($"{v} - {u} = {v-u}"); WriteLine($"{v} * {2} = {v*2}"); WriteLine($"{2} * {v} = {2*v}"); WriteLine($"{v} dot {u} = {v.dot_product(u)}"); WriteLine($"{v} cross {u} = {v.cross_product(u)}"); WriteLine($"The magnitude of the vector {v} is {vector3d.magnitude(v)}"); WriteLine($"{v} / {2} = {v/2}"); v.x = 9; WriteLine(v); return(0); }
static void Main() { vector3d v = new vector3d(1, 2, 3); Write("v = {0}\n", v); ivector3d iv = new vector3d(4, 5, 6); Write("iv = {0}\n", iv); ivector3d iv2 = new vector3d_array(7, 8, 9); Write("iv2 = {0}\n", iv2); iv2 = v.cross_product(iv); Write("iv2 = v x iv = {0}\n", iv2); }
static int Main() { vector3d v = new vector3d(1, 2, 3); vector3d u = new vector3d(4, 5, 6); double c = 1.5; WriteLine($"v = {v}"); WriteLine($"u = {u}"); WriteLine($"c = {c}"); WriteLine($"c*v = {c*v} & v*c = {v*c} "); WriteLine($"v+u = {v+u}"); WriteLine($"v-u = {v-u}"); WriteLine($"v*u = {v.dot_product(u)}"); WriteLine($"vxu = {v.vector_product(u)}"); WriteLine($"||v|| = {v.magnitude()}"); return(0); }
static int Main() { vector3d v1 = new vector3d(1, 2, 3); vector3d v2 = new vector3d(2, 2, 1); Write("v1 = "); v1.ToString(); Write("v2 = "); v2.ToString(); Write("v1.magnitude() = {0}\n", v1.magnitude()); vector3d v3 = v1 * 2; Write("v1*2 = "); v3.ToString(); Write("2*v1 = "); (2 * v1).ToString(); Write("v1+v2 = "); (v1 + v2).ToString(); Write("v1-v2 = "); (v1 - v2).ToString(); Write("v1.dot_product(v2) = {0}\n", v1.dot_product(v2)); Write("v1.vector_product(v2) = "); v1.vector_product(v2).ToString(); WriteLine($" v1.x={v1.x}, v1.y={v1.y}, v1.z={v1.z}"); return(0); }
static int Main() { vector3d a = new vector3d(1, 1, 0); vector3d b = new vector3d(0, 0, 1); string str_a = a.ToString(); string str_b = b.ToString(); string str_b_minus_a = (b - a).ToString(); string str_a_dot_b = (vector3d.dot_product(a, b)).ToString(); string str_a_X_b = (vector3d.vector_product(a, b)).ToString(); string str_mag_a = (vector3d.magnitude(a)).ToString(); Write("a = " + str_a + "\n"); Write("b = " + str_b + "\n"); Write("b-a = " + str_b_minus_a + "\n"); Write("a dot b = " + str_a_dot_b + "\n"); Write("a X b = " + str_a_X_b + "\n"); Write("magnitude(a) = " + str_mag_a + "\n"); return(0); }
static int Main() { vector3d v = new vector3d(1, 2, 3); vector3d u = new vector3d(5, 4, 3); v.print("v= "); u.print("u= "); (v + u).print("u+v= "); (v - u).print("u-v= "); (2 * v).print("2*v= "); System.Console.Write("v.x = {0}\n", v.x); v.x = 5.0; System.Console.Write("v.x = {0}\n", v.x); System.Console.Write("v@u= {0}\n", v.dot_product(u)); v.vector_product(u).print("v cross u= "); System.Console.Write("|v|= {0}\n", v.magnitude()); return(0); }
public static int Main() { vector3d v = new vector3d(2, 427, -17); vector3d u = new vector3d(351, -379, 1); double c = System.Math.PI; v.print("v="); u.print("u="); (v + u).print("v+u="); (v - u).print("v-u="); double vu = v.dot_product(u); Write($"v.u={vu}\n"); (v.vector_product(u)).print("v x u ="); Write("|v|={0}\n", v.magnitude()); (v * c).print($"v*{c}="); return(0); }
public static void Main() { vector3d a = new vector3d(1, 2, 3); vector3d b = new vector3d(4, 5, 6); WriteLine("The vectors are: " + a.ToString() + " and " + b.ToString()); vector3d c = a + b; WriteLine("Their sum is: " + c.ToString()); vector3d d = a - b; WriteLine("Their difference is: " + d.ToString()); double e = dotProduct(a, b); WriteLine("Their dot is: " + e.ToString()); vector3d f = vectorProduct(a, b); WriteLine("Their cross is: " + f.ToString()); double g = magnitude(a); double h = magnitude(b); WriteLine("Their magnitudes are: " + g.ToString() + " and " + h.ToString()); }
static int Main() { System.Console.Write("Example with vector v:\n"); vector3d v = new vector3d(1.2, 1.5, 2.0); System.Console.Write("v = " + v + "\n"); System.Console.Write("v_x = " + v.x + "\n"); System.Console.Write("Changing v_x to 10 and v_y to 3.\n"); v.x = 10; v.y = 3; System.Console.Write("v_x = " + v.x + "\n"); v.print("v="); System.Console.Write("Defining new vector u:"); vector3d u = new vector3d(2, 5, 7); double a = 2; u.print("u="); System.Console.Write("Calculating 2*u, u+v and cross-product of u and v \n"); vector3d w = u * a; w.print("2*u = "); vector3d q = u + v; q.print("u+v = "); vector3d t = v.vectorProduct(u); t.print("u x v = "); System.Console.Write("Magnitude v = {0:f3}\n", v.magnitude()); return(0); }
public vector3d vector_product(vector3d other) { return(new vector3d(this.y * other.z - this.z * other.y, this.z * other.x - this.x * other.z, this.x * other.y - this.y * other.x)); }