Kwasniok / cpp-raytracing

non-linear raytraycing based on "Raytracing in One Weekend"
2 stars 0 forks source link

generalize `get_coords_in_plane` #86

Open Kwasniok opened 1 year ago

Kwasniok commented 1 year ago

The general algorithm is getting linear coefficients of a vector is the span of a subspace. Observe the structure of a transformation matrix inside the algorithm.

Kwasniok commented 1 year ago

generalized algorithm in Mathematica:

replaceColumn[mat_, col_, n_] := Module[
  {matOut},
  matOut = mat;
  matOut[[All, n]] = col;
  matOut
]

n = 2;
bb = Table[Table[b[i] . b[j], {i, n}], {j, n}];
bb // MatrixForm
d = Det[bb]
bx = Table[b[i] . x, {i, n}];
bx // MatrixForm
breplx = Table[replaceColumn[bb, bx, i] // Det, {i, n}];
breplx // MatrixForm
uv = breplx / d;
uv // MatrixForm // Simplify