Skip to content

Instantly share code, notes, and snippets.

@bradphelan
Created November 20, 2017 13:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bradphelan/ec5c9ab44813e77fe5237bea539942d7 to your computer and use it in GitHub Desktop.
private static bool IsTangentConnected( Solid3D.Face face0, Solid3D.Face face1, Solid3D.Edge edge)
{
var angle = 1.5 / 180 * Math.PI;
// Then the two faces share an edge.
var surfaces0 = face0.Parametric;
var surfaces1 = face1.Parametric;
Vector3D Normal(Surface[] surfaces, Point3D p)
{
return surfaces
.Select
(s =>
{
// The below call to Project is very slow
if (!s.Project(p, out var coord2D))
throw new Exception("Unexpected");
;
return (p: s.PointAt(coord2D), n: s.Normal(coord2D));
})
.MaxBy(q => p.DistanceTo(q.p))
[0].n;
}
var pl = edge.Curve.PointAt(edge.Curve.Domain.Low);
var pm = edge.Curve.PointAt(edge.Curve.Domain.Mid);
var ph = edge.Curve.PointAt(edge.Curve.Domain.High);
var vl0 = Normal(surfaces0, pl);
var vl1 = Normal(surfaces1, pl);
var vm0 = Normal(surfaces0, pm);
var vm1 = Normal(surfaces1, pm);
var vh0 = Normal(surfaces0, ph);
var vh1 = Normal(surfaces1, ph);
var r = Vector3D.AngleBetween(vl0, vl1) < angle
&& Vector3D.AngleBetween(vm0, vm1) < angle
&& Vector3D.AngleBetween(vh0, vh1) < angle;
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment