Rodrigues’ rotation formula: Difference between revisions
Content added Content deleted
(Added credits) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 12:
=={{header|Ada}}==
<
use Ada.Text_Io;
with Ada.Numerics.Elementary_Functions;
Line 55:
Theta => Angle(Source, Target))));
end Rodrigues;
</syntaxhighlight>
{{out}}
<pre>
Line 65:
=={{header|ALGOL 68}}==
{{Trans|JavaScript}}
<
MODE VECTOR = [ 3 ]REAL;
MODE MATRIX = [ 3 ]VECTOR;
Line 105:
)
)
END</
{{out}}
<pre>
Line 113:
=={{header|AutoHotkey}}==
{{Trans|JavaScript}}
<
v2 := [8,5,-30]
a := getAngle(v1, v2)
Line 149:
, [z*x*t - y*sa, z*y*t + x*sa, ca + z*z*t]]
return matrixMultiply(r, p)
}</
{{out}}
<pre>[2.232221, 1.395138, -8.370829]</pre>
Line 155:
=={{header|C}}==
{{trans|JavaScript}}
<
#include <math.h>
Line 214:
printf("[%.13f, %.13f, %.13f]\n", np.x, np.y, np.z);
return 0;
}</
{{out}}
Line 249:
{{trans|JavaScript}}
{{works with|Factor|0.99 2021-06-02}}
<
math.vectors prettyprint sequences sequences.generalizations ;
Line 261:
{ 5 -6 4 } { 8 5 -30 }
dupd [ cross normalize ] [ angle-between ] 2bi a-rotate .</
{{out}}
<pre>
Line 269:
=={{header|FreeBASIC}}==
This example rotates the vector [-1, 2, -0.4] around the axis [-1, 2, 1] in increments of 18 degrees.
<
type vector
Line 330:
r = rodrigues( v, k, theta )
print using "##.### [##.### ##.### ##.###]"; theta; r.x; r.y; r.z
next theta</
{{out}}<pre>
Theta rotated vector
Line 359:
=={{header|Go}}==
{{trans|JavaScript}}
<
import (
Line 414:
np := aRotate(v1, ncp, a)
fmt.Println(np)
}</
{{out}}
Line 423:
=={{header|JavaScript}}==
===JavaScript: ES5===
<
return Math.sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
}
Line 458:
var ncp = normalize(cp);
var np = aRotate(v1, ncp, a);
console.log(np); </
===JavaScript: ES6===
Line 467:
and is not available to all JavaScript interpreters)
<
"use strict";
Line 613:
null, 2
);
})();</
{{Out}}
<pre>[
Line 629:
of numbers. Some of the functions have been generalized to work with vectors
of arbitrary length.
<syntaxhighlight lang="jq">
# v1 and v2 should be vectors of the same length.
def dotProduct(v1; v2): [v1, v2] | transpose | map(.[0] * .[1]) | add;
Line 677:
;
example</
{{out}}
<pre>
Line 686:
=={{header|Julia}}==
{{trans|Perl}}
<
using JSON3
Line 707:
np = rodrotate(v1, ncp, a)
JSON3.write(np) # "[2.2322210733082284,1.3951381708176411,-8.370829024905854]"
</syntaxhighlight>
=={{header|Nim}}==
{{trans|Wren}}
Only changed most function names.
<
type
Line 753:
nvp = normalized(vp)
np = v1.rotate(nvp, a)
echo np</
{{out}}
Line 760:
=={{header|Perl}}==
===Task-specific===
<
use strict;
use Math::Trig; # acos
Line 816:
my $json=JSON->new->canonical;
print $json->encode($np) . "\n";</
{{out}}
<pre>[2.23222107330823,1.39513817081764,-8.37082902490585]</pre>
===Generalized===
<
use warnings;
use feature <say signatures>;
Line 852:
my($v1,$v2) = ([5, -6, 4], [8, 5, -30]);
say join ' ', @{aRotate $v1, normalize(crossProduct $v1, $v2), getAngle $v1, $v2};</
{{out}}
<pre>2.23222107330823 1.39513817081764 -8.37082902490585</pre>
Line 858:
=={{header|Phix}}==
{{trans|JavaScript}}
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">norm</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">v</span><span style="color: #0000FF;">)</span>
Line 901:
<span style="color: #000000;">np</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">aRotate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">v1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">ncp</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">a</span><span style="color: #0000FF;">);</span>
<span style="color: #0000FF;">?</span><span style="color: #000000;">np</span>
<!--</
{{out}}
<pre>
Line 909:
=={{header|Processing}}==
{{trans|C}}
<
//Aamrun, 30th June 2022
Line 978:
}
</syntaxhighlight>
=={{header|Raku}}==
<syntaxhighlight lang="raku"
sub norm (@v) { sqrt @v⋅@v }
sub normalize (@v) { @v X/ @v.&norm }
Line 1,004:
my @v1 = [5,-6, 4];
my @v2 = [8, 5,-30];
say join ' ', aRotate @v1, normalize(crossProduct @v1, @v2), getAngle @v1, @v2;</
{{out}}
<pre>2.232221073308229 1.3951381708176411 -8.370829024905852</pre>
Line 1,010:
Alternately, differing mostly in style:
<syntaxhighlight lang="raku"
sub infix:<❌> (@v1, @v2) { # cross product
Line 1,057:
}).join: "\n"
}
TESTING</
{{out}}
<pre>Task example - Point and composite axis / angle:
Line 1,088:
=={{header|Wren}}==
{{trans|JavaScript}}
<
var normalize = Fn.new { |v|
Line 1,128:
var ncp = normalize.call(cp)
var np = aRotate.call(v1, ncp, a)
System.print(np)</
{{out}}
|