Skip to content

Commit

Permalink
Fix directions
Browse files Browse the repository at this point in the history
  • Loading branch information
oberbichler committed May 28, 2020
1 parent 80bcc52 commit 4b65870
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
9 changes: 5 additions & 4 deletions Bowerbird/DGridPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,22 @@ bool FindDirections(double u, double v, out Vector3d dir1, out Vector3d dir2, ou
return false;
}

var normal = Vector3d.CrossProduct(refA1, refA2);

if (Math.Abs(e[2]) < 1e-8)
{
dir1 = refA1 / refA1.Length;
}
else
{
var d1 = (e[0] - e[1] + tmp) / (2 * e[2]) * refA1 + refA2;
var alpha = Math.Atan2(2 * e[2], e[0] - e[1]) / 2;

dir1 = d1 / d1.Length;
dir1 = refA1 / refA1.Length;
dir1.Rotate(alpha, normal);
}

dir2 = dir1;

var normal = Vector3d.CrossProduct(refA1, refA2);

var angle = Math.Atan(Math.Sqrt(n2 / n1));

dir1.Rotate(angle, normal);
Expand Down
15 changes: 7 additions & 8 deletions Bowerbird/PSPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,23 @@ bool FindDirections(double u, double v, out Vector3d dir1, out Vector3d dir2, ou
e.Transform(TransformToLocalCartesian(refA1, refA2));
e.Transform(Material);

var tmp = Math.Sqrt(Math.Pow(e[0] - e[1], 2) + 4 * Math.Pow(e[2], 2));
var n1 = 0.5 * (e[0] + e[1] + tmp);
var n2 = 0.5 * (e[0] + e[1] - tmp);
var normal = Vector3d.CrossProduct(refA1, refA2);

if (Math.Abs(e[2]) < 1e-8)
{
dir1 = refA1 / refA1.Length;
dir2 = refA2 / refA2.Length;
}
else
{
var d1 = (e[0] - e[1] + tmp) / (2 * e[2]) * refA1 + refA2;
var d2 = (e[0] - e[1] - tmp) / (2 * e[2]) * refA1 + refA2;
var alpha = Math.Atan2(2 * e[2], e[0] - e[1]) / 2;

dir1 = d1 / d1.Length;
dir2 = d2 / d2.Length;
dir1 = refA1 / refA1.Length;
dir1.Rotate(alpha, normal);
}

dir2 = dir1;
dir2.Rotate(Math.PI / 2, normal);

return true;
}

Expand Down

0 comments on commit 4b65870

Please sign in to comment.