September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
1
Task/Vector-products/00META.yaml
Normal file
1
Task/Vector-products/00META.yaml
Normal file
|
|
@ -0,0 +1 @@
|
|||
--- {}
|
||||
28
Task/Vector-products/Ceylon/vector-products.ceylon
Normal file
28
Task/Vector-products/Ceylon/vector-products.ceylon
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
shared void run() {
|
||||
|
||||
alias Vector => Float[3];
|
||||
|
||||
function dot(Vector a, Vector b) =>
|
||||
a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
||||
|
||||
function cross(Vector a, Vector b) => [
|
||||
a[1] * b[2] - a[2] * b[1],
|
||||
a[2] * b[0] - a[0] * b[2],
|
||||
a[0] * b[1] - a[1] * b[0]
|
||||
];
|
||||
|
||||
function scalarTriple(Vector a, Vector b, Vector c) =>
|
||||
dot(a, cross(b, c));
|
||||
|
||||
function vectorTriple(Vector a, Vector b, Vector c) =>
|
||||
cross(a, cross(b, c));
|
||||
|
||||
value a = [ 3.0, 4.0, 5.0 ];
|
||||
value b = [ 4.0, 3.0, 5.0 ];
|
||||
value c = [-5.0, -12.0, -13.0 ];
|
||||
|
||||
print("``a`` . ``b`` = ``dot(a, b)``");
|
||||
print("``a`` X ``b`` = ``cross(a, b)``");
|
||||
print("``a`` . ``b`` X ``c`` = ``scalarTriple(a, b, c)``");
|
||||
print("``a`` X ``b`` X ``c`` = ``vectorTriple(a, b, c)``");
|
||||
}
|
||||
23
Task/Vector-products/GLSL/vector-products.glsl
Normal file
23
Task/Vector-products/GLSL/vector-products.glsl
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
vec3 a = vec3(3, 4, 5),b = vec3(4, 3, 5),c = vec3(-5, -12, -13);
|
||||
|
||||
float dotProduct(vec3 a, vec3 b)
|
||||
{
|
||||
return a.x*b.x+a.y*b.y+a.z*b.z;
|
||||
}
|
||||
|
||||
vec3 crossProduct(vec3 a,vec3 b)
|
||||
{
|
||||
vec3 c = vec3(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y- a.y*b.x);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
float scalarTripleProduct(vec3 a,vec3 b,vec3 c)
|
||||
{
|
||||
return dotProduct(a,crossProduct(b,c));
|
||||
}
|
||||
|
||||
vec3 vectorTripleProduct(vec3 a,vec3 b,vec3 c)
|
||||
{
|
||||
return crossProduct(a,crossProduct(b,c));
|
||||
}
|
||||
|
|
@ -1,25 +1,25 @@
|
|||
class Vector(x, y, z) {
|
||||
class MyVector(x, y, z) {
|
||||
method ∙(vec) {
|
||||
[self{:x,:y,:z}] »*« [vec{:x,:y,:z}] «+»;
|
||||
[self{:x,:y,:z}] »*« [vec{:x,:y,:z}] «+»
|
||||
}
|
||||
|
||||
|
||||
method ⨉(vec) {
|
||||
Vector(self.y*vec.z - self.z*vec.y,
|
||||
MyVector(self.y*vec.z - self.z*vec.y,
|
||||
self.z*vec.x - self.x*vec.z,
|
||||
self.x*vec.y - self.y*vec.x);
|
||||
self.x*vec.y - self.y*vec.x)
|
||||
}
|
||||
|
||||
|
||||
method to_s {
|
||||
"(#{x}, #{y}, #{z})";
|
||||
"(#{x}, #{y}, #{z})"
|
||||
}
|
||||
}
|
||||
|
||||
var a = Vector(3, 4, 5);
|
||||
var b = Vector(4, 3, 5);
|
||||
var c = Vector(-5, -12, -13);
|
||||
|
||||
say "a=#{a}; b=#{b}; c=#{c};";
|
||||
say "a ∙ b = #{a ∙ b}";
|
||||
say "a ⨉ b = #{a ⨉ b}";
|
||||
say "a ∙ (b ⨉ c) = #{a ∙ (b ⨉ c)}";
|
||||
say "a ⨉ (b ⨉ c) = #{a ⨉ (b ⨉ c)}";
|
||||
|
||||
var a = MyVector(3, 4, 5)
|
||||
var b = MyVector(4, 3, 5)
|
||||
var c = MyVector(-5, -12, -13)
|
||||
|
||||
say "a=#{a}; b=#{b}; c=#{c};"
|
||||
say "a ∙ b = #{a ∙ b}"
|
||||
say "a ⨉ b = #{a ⨉ b}"
|
||||
say "a ∙ (b ⨉ c) = #{a ∙ (b ⨉ c)}"
|
||||
say "a ⨉ (b ⨉ c) = #{a ⨉ (b ⨉ c)}"
|
||||
|
|
|
|||
26
Task/Vector-products/VBA/vector-products.vba
Normal file
26
Task/Vector-products/VBA/vector-products.vba
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
Option Base 1
|
||||
Function dot_product(a As Variant, b As Variant) As Variant
|
||||
dot_product = WorksheetFunction.SumProduct(a, b)
|
||||
End Function
|
||||
|
||||
Function cross_product(a As Variant, b As Variant) As Variant
|
||||
cross_product = Array(a(2) * b(3) - a(3) * b(2), a(3) * b(1) - a(1) * b(3), a(1) * b(2) - a(2) * b(1))
|
||||
End Function
|
||||
|
||||
Function scalar_triple_product(a As Variant, b As Variant, c As Variant) As Variant
|
||||
scalar_triple_product = dot_product(a, cross_product(b, c))
|
||||
End Function
|
||||
|
||||
Function vector_triple_product(a As Variant, b As Variant, c As Variant) As Variant
|
||||
vector_triple_product = cross_product(a, cross_product(b, c))
|
||||
End Function
|
||||
|
||||
Public Sub main()
|
||||
a = [{3, 4, 5}]
|
||||
b = [{4, 3, 5}]
|
||||
c = [{-5, -12, -13}]
|
||||
Debug.Print " a . b = "; dot_product(a, b)
|
||||
Debug.Print " a x b = "; "("; Join(cross_product(a, b), ", "); ")"
|
||||
Debug.Print "a . (b x c) = "; scalar_triple_product(a, b, c)
|
||||
Debug.Print "a x (b x c) = "; "("; Join(vector_triple_product(a, b, c), ", "); ")"
|
||||
End Sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue