Vector products: Difference between revisions

Line 1,268:
6
(-267, 204, -3)</pre>
 
=={{header|Objeck}}==
<lang objeck>bundle Default {
class VectorProduct {
function : Main(args : String[]) ~ Nil {
a := Vector3D->New(3.0, 4.0, 5.0);
b := Vector3D->New(4.0, 3.0, 5.0);
c := Vector3D->New(-5.0, -12.0, -13.0);
 
a->Dot(b)->Print();
a->Cross(b)->Print();
a->ScaleTrip(b, c)->Print();
a->VectorTrip(b, c)->Print();
}
}
 
class Vector3D {
@a : Float;
@b : Float;
@c : Float;
 
New(a : Float, b : Float, c : Float) {
@a := a;
@b := b;
@c := c;
}
 
method : GetA() ~ Float {
return @a;
}
 
method : GetB() ~ Float {
return @b;
}
 
method : GetC() ~ Float {
return @c;
}
 
method : public : Dot(vec : Vector3D) ~ Float {
return @a * vec->GetA() + @b * vec->GetB() + @c * vec->GetC();
}
 
method : public : Cross(vec : Vector3D) ~ Vector3D {
newA := @b * vec->GetC() - @c * vec->GetB();
newB := @c * vec->GetA() - @a * vec->GetC();
newC := @a * vec->GetB() - @b * vec->GetA();
 
return Vector3D->New(newA, newB, newC);
}
 
method : public : ScaleTrip(vec_b: Vector3D, vec_c : Vector3D) ~ Float {
return Dot(vec_b->Cross(vec_c));
}
 
method : public : Print() ~ Nil {
IO.Console->Print('<')->Print(@a)->Print(" ,")
->Print(@b)->Print(", ")->Print(@c)->PrintLine('>');
}
 
method : public : VectorTrip(vec_b: Vector3D, vec_c : Vector3D) ~ Vector3D {
return Cross(vec_b->Cross(vec_c));
}
}
}
</lang>
 
=={{header|OCaml}}==
760

edits