Vector products: Difference between revisions
PascalABC.NET
(PascalABC.NET) |
|||
(One intermediate revision by one other user not shown) | |||
Line 3,802:
a x (b x c): -267.00000000 204.00000000 -3.00000000
</pre>
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
uses System.Numerics;
function DotProduct(v1,v2: Vector3): real
:= v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
function CrossProduct(v1,v2: Vector3): Vector3
:= new Vector3(v1.y * v2.z - v1.z * v2.y,
v1.z * v2.x - v1.x * v2.z,
v1.x * v2.y - v1.y * v2.x);
function ScalarTripleProduct(a,b,c: Vector3): real
:= DotProduct(a, CrossProduct(b, c));
function VectorTripleProduct(a,b,c: Vector3): Vector3
:= CrossProduct(a, CrossProduct(b, c));
begin
var a := new Vector3(3,4,5);
var b := new Vector3(4,3,5);
var c := new Vector3(-5,-12,-13);
Writeln(DotProduct(a, b));
Writeln(CrossProduct(a, b));
Writeln(ScalarTripleProduct(a, b, c));
Writeln(VectorTripleProduct(a, b, c));
end.
</syntaxhighlight>
{{out}}
49
<5. 5. -7>
6
<-267. 204. -3>
</pre>
=={{header|Perl}}==
Line 4,630 ⟶ 4,668:
=={{header|REXX}}==
<syntaxhighlight lang="rexx">/*REXX program computes the products:
b= 4 3 5
Say ''
/*---------------------------------------------------------------------------*/
cross: Procedure
Arg a b c, u v w
Return b*w-c*v c*u-a*w a*v-b*u
dot: Procedure
tellV: procedure; parse arg name,x y z; w=max(4,length(x),length(y),length(z)) /*max W*/▼
Arg a b c, u v w
say right(name,40) right(x,w) right(y,w) right(z,w); /*show vector.*/ return</syntaxhighlight>▼
Return a*u + b*v + c*w
{{out|output|text= when using the default internal inputs:}}▼
/*---------------------------------------------------------------------------*/
tellV: Procedure
Parse Arg name,x y z
▲
Return</syntaxhighlight>
<pre>
▲</pre>
=={{header|Ring}}==
|