Vector products: Difference between revisions

Content added Content deleted
(Updated D code)
Line 324: Line 324:


=={{header|D}}==
=={{header|D}}==
<lang d>import std.stdio, std.algorithm, std.conv;
<lang d>import std.stdio, std.algorithm, std.conv, std.numeric;


struct V3 {
struct V3 {
Line 333: Line 333:


pure nothrow double dot(in V3 rhs) const {
pure nothrow double dot(in V3 rhs) const {
return x*rhs.x + y*rhs.y + z*rhs.z;
return dotProduct(v, rhs.v);
}
}


Line 354: Line 354:


void main() {
void main() {
const V3 a = {3,4,5}, b = V3(4,3,5), c = V3(-5,-12,-13);
const V3 a = {3, 4, 5},
writefln("a = %s, b = %s, c = %s", a, b, c);
b = {4, 3, 5},
writeln("a . b = ", a.dot(b));
c = {-5, -12, -13};
writeln("a x b = ", a.cross(b));
writeln("a = ", a);
writeln("a .(b x c) = ", scalarTriple(a,b,c));
writeln("b = ", b);
writeln("a x(b x c) = ", vectorTriple(a,b,c));
writeln("c = ", c);
writeln("a . b = ", a.dot(b));
writeln("a x b = ", a.cross(b));
writeln("a . (b x c) = ", scalarTriple(a,b,c));
writeln("a x (b x c) = ", vectorTriple(a,b,c));
}</lang>
}</lang>
Output:
Output:
<pre>a = [3, 4, 5], b = [4, 3, 5], c = [-5, -12, -13]
<pre>a = [3, 4, 5]
a . b = 49
b = [4, 3, 5]
a x b = [5, 5, -7]
c = [-5, -12, -13]
a .(b x c) = 6
a . b = 49
a x(b x c) = [-267, 204, -3]</pre>
a x b = [5, 5, -7]
a . (b x c) = 6
a x (b x c) = [-267, 204, -3]</pre>


=={{header|Euphoria}}==
=={{header|Euphoria}}==