Skip to content

Instantly share code, notes, and snippets.

@bradphelan
Last active November 21, 2017 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradphelan/367d8d74b0c8549f3da0e343aca4d768 to your computer and use it in GitHub Desktop.
Save bradphelan/367d8d74b0c8549f3da0e343aca4d768 to your computer and use it in GitHub Desktop.
Vector3D Normal(Solid3D.Face face, Point3D p)
{
return face
.Parametric
.SelectMany
(s => s.PointInversion( p, 1e-3, out var coord2D )
? Some((p: s.PointAt(coord2D), n: s.Normal(coord2D)))
: None )
.MaxBy(q => p.DistanceTo(q.p))
[0].n;
}
@bradphelan
Copy link
Author

Trick is that Optional implements IEnumerable so works with SelectMany to flatten it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment