%% load file load("glob.lf")? add_vectors(C,A,B) -> vector(name=>C, x => (A.x + B.x),y => (A.y + B.y), z =>(A.z + B.z)). subtract_vectors(C,A,B) -> vector(name=>C, x => (A.x - B.x),y => (A.y - B.y), z =>(A.z - B.z)). cross_vectors(C,A,B) -> vector(name=>C, x => (A.y * B.z - A.z * B.x) , y => - (A.x * B.z - B.x * A.z), z => (A.x * B.y - A.y * B.x)). % I could not get dot to work as a function. dot_vectors(X,A,B) :- X = A.x * B.x + A.y * B.y + A.z + B.z. magnitude(N,A) -> sqrt((A.x * A.x) + (A.y * A.y) + (A.z * A.z)). direction_2d(N,A) -> my_arctan2(A.y, A.x). add_and_write(X,N,A,B) :- X = add_vectors(N,A,B),write(X), nl. subtract_and_write(X,N,A,B) :- X = subtract_vectors(N,A,B),write(X), nl. cross_and_write(X,N,A,B) :- X = cross_vectors(N,A,B),write(X), nl. dot_and_write(X,N,A,B) :- dot_vectors(X,A,B), write(N,X). magnitude_and_write(N,A) :- X = magnitude(N,A),write("magnitude of ",N," = ",X), nl. direction_2d_and_write_r(N,A) :- X = direction_2d(N,A),write("direction of ",N," = ",X), nl. global(a)? global(b)? global(c)? global(d)? global(e)? prob05 :- a = vector(name => "a", x => 4.0, y => -3.0, z => 0.0), b = vector(name => "b", x => 6.0, y => 8.0, z => 0.0), % TROUBLE whe add following % f = vector(name => "f", x => 2.0, y => -3.0, z => 7.0), % g = vector(name => "g", x => 12.0, y => 45.0, z => -8.0), % h = vector(name => "h", x => -5.0, y => -3.0, z => 42.0), write(a),nl, write(b),nl, add_and_write(C,"c",a,b), subtract_and_write(D,"d",b,a), subtract_and_write(E,"e",a,b), magnitude_and_write("a",a), magnitude_and_write("b",b), magnitude_and_write("c",C), magnitude_and_write("d",D), magnitude_and_write("e",E), my_arctan2(Ra,a.y,a.x), write("Direction of a is ", Ra , " radians"),nl, my_arctan2(Rb,b.y,b.x), write("Direction of b is ", Rb , " radians"),nl, my_arctan2(Rc,C.y,C.x), write("Direction of c is ", Rc , " radians"),nl, my_arctan2(Rd,D.y,D.x), write("Direction of d is ", Rd , " radians"),nl, my_arctan2(Re,E.y,E.x), write("Direction of e is ", Re , " radians"),nl, my_arctan(PiD4, 1.0), Da = 45.0 / PiD4 * Ra, Db = 45.0 / PiD4 * Rb, Dc = 45.0 / PiD4 * Rc, Dd = 45.0 / PiD4 * Rd, De = 45.0 / PiD4 * Re, write("Direction of a is ", Da , " degrees"),nl, write("Direction of b is ", Db , " degrees"),nl, write("Direction of c is ", Dc , " degrees"),nl, write("Direction of d is ", Dd , " degrees"),nl, write("Direction of e is ", De , " degrees"),nl, dot_and_write(Xd1,"a dot a = ",a,a),nl, dot_and_write(Xd2,"a dot b = ",a,b),nl, dot_and_write(Xd3,"b dot a = ",a,a),nl, dot_and_write(Xd4,"a dot C = ",a,C),nl, dot_and_write(Xd5,"D dot a = ",D,a),nl, dot_and_write(Xd6,"a dot E = ",a,E),nl, dot_and_write(Xd7,"E dot a = ",E,a),nl, % cross_and_write(CXd8,"f cross g = ",f,g),nl, % cross_and_write(CXd9,"f cross h = ",f,h),nl, % cross_and_write(CXd10,"g cross h = ",g,h),nl, % cross_and_write(CXd11,"g cross f = ",g,f),nl, % cross_and_write(CXd12,"h cross f = ",h,f),nl, % cross_and_write(CXd13,"h cross g = ",h,g),nl, cross_and_write(CXd1,"a cross a = ",a,a),nl, cross_and_write(CXd2,"a cross b = ",a,b),nl, cross_and_write(CXd3,"b cross a = ",a,a),nl, cross_and_write(CXd4,"a cross C = ",a,C),nl, cross_and_write(CXd5,"D cross a = ",D,a),nl, cross_and_write(CXd6,"a cross E = ",a,E),nl, cross_and_write(CXd7,"E cross a = ",E,a),nl. prob05?