Find the intersection of a line with a plane: Difference between revisions
Content added Content deleted
(→With a geometric algebra library: correction) |
(→With a geometric algebra library: simplify and add module version import requirement) |
||
Line 1,491: | Line 1,491: | ||
See task [[geometric algebra]] |
See task [[geometric algebra]] |
||
<syntaxhighlight lang=raku>use Clifford; |
<syntaxhighlight lang=raku>use Clifford:ver<6.2.1>; |
||
# We pick a projective basis and |
# We pick a (non-degenerate) projective basis and |
||
# we define the dual and meet operators. |
|||
# the pseudo-scalar along with its square |
|||
my $I = [∧] my ($i, $j, $k, $l) = @e; |
my $I = [∧] my ($i, $j, $k, $l) = @e; |
||
sub prefix:<∗>($M) { $M/$I } |
|||
my $I2 = ($I**2).narrow; |
|||
sub infix:<∨>($A, $B) { ∗((∗$B)∧(∗$A)) } |
|||
my $direction = -$j - $k; |
my $direction = -$j - $k; |
||
$direction /= sqrt($direction**2); |
|||
# Homogeneous coordinates of (X, Y, Z) are (X, Y, Z, 1) |
# Homogeneous coordinates of (X, Y, Z) are (X, Y, Z, 1) |
||
Line 1,508: | Line 1,508: | ||
# A plane is a trivector |
# A plane is a trivector |
||
my $plane = (5*$k + $l) ∧ ($k*- |
my $plane = (5*$k + $l) ∧ ($k*-$i∧$j∧$k); |
||
# The intersection is the meet |
# The intersection is the meet |
||
⚫ | |||
# according to the De Morgan Law, |
|||
# the meet is the dual of the join of the duals. |
|||
⚫ | |||
my $PLANE = $plane*$I/$I2; |
|||
my $M = $LINE∧$PLANE; |
|||
my $m = $M*$I/$I2; |
|||
# Affine coordinates of (X, Y, Z, W) are (X/W, Y/W, Z/W) |
# Affine coordinates of (X, Y, Z, W) are (X/W, Y/W, Z/W) |
||
say $m/($m·$l) |
say $m/($m·$l) X· ($i, $j, $k);</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>(0 -5 5)</pre> |
<pre>(0 -5 5)</pre> |