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 |
return dotProduct(v, rhs.v); |
||
} |
} |
||
Line 354: | Line 354: | ||
void main() { |
void main() { |
||
const V3 a = {3 |
const V3 a = {3, 4, 5}, |
||
b = {4, 3, 5}, |
|||
c = {-5, -12, -13}; |
|||
writeln("a |
writeln("a = ", a); |
||
writeln(" |
writeln("b = ", b); |
||
writeln(" |
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 |
<pre>a = [3, 4, 5] |
||
b = [4, 3, 5] |
|||
c = [-5, -12, -13] |
|||
a . |
a . b = 49 |
||
a x |
a x b = [5, 5, -7] |
||
a . (b x c) = 6 |
|||
a x (b x c) = [-267, 204, -3]</pre> |
|||
=={{header|Euphoria}}== |
=={{header|Euphoria}}== |