2 using System.Collections.Generic;
14 private static readonly Expr _p110 = MSingle.Eval(
"{1,1,0}");
20 public string Tag {
get; set; }
30 Expr c =
ML[color].Eval();
31 if (c.Head != MathConstants.ColorHead)
32 throw new ArgumentException(
"argument 'color' does not resolve into a Mathematica color");
43 Console.WriteLine(
"Assuming this facet is convex.");
63 get {
return Head.Plane; }
82 get {
return Head.HEsFromHere; }
87 get {
return HalfEdges.ToArray(); }
97 return ML[
"List"].Bracket(
106 private Expr PolyPrimitive
110 return ML[
"Polygon"].Bracket(
112 HalfEdges.Select(he => he.Start.Expr)
127 return ML[
"List"].Bracket(
129 ML[
"Glow[Yellow]"].Eval(),
141 get {
return HalfEdges.Select(he => he.Start); }
149 get {
return PointRefs.ToArray(); }
157 get {
return ML[
"List"].Bracket(PointRefs.Select(p => p.Expr)).Eval(); }
170 var b =
new HalfEdge(a.End, _ref110);
172 var d =
new HalfEdge(c.End, a.Start);
204 HalfEdge he1 = HalfEdges.First(he => he.Start == v1);
205 HalfEdge he2 = HalfEdges.First(he => he.Start == v2);
208 HalfEdge[] newHes = he1.Prev.DetourToVertex(v2);
210 newHes[0].LinkNext(he2);
211 he2P.LinkNext(newHes[1]);
212 newHes[1].LinkNext(he1);
214 var facet =
new Facet(newHes[0]);
216 foreach (
HalfEdge halfEdge
in newHes[0].HEsFromHere)
218 halfEdge.Facet = facet;
221 return new Facet(newHes[0]);
230 Console.WriteLine(
"Triangulating!");
231 return HalfEdges.Skip(3)
232 .Select(he => he.Start).ToList()
244 Expr t = FindIntersectSlow(p);
248 Expr point =
ML[
"{0}*{1} + (1-{0})*{2}"].Format(t, p.StartRef.Expr, p.EndRef.Expr).Eval();
251 ML[
"Cross[{1} - {0},{2} - {0}]"].Format(point, PointRefs.Last().Expr,
PointRefs.First().Expr).Eval();
253 return !PointRefs.CirclularPairs()
257 ML[
"Cross[{1} - {0},{2} - {0}]"].Format(point, pair.Item1.Expr, pair.Item2.Expr)
260 .Any(crossProduct => (bool)
ML[
"Dot[{0},{1}] <= 0"].Format(cp, crossProduct).EvalObject());
272 ML[
"Dot[{0}.{1}] - Dot[{1}.{2}]"].Format(p.EndRef.Expr,
Plane.Normal, p.StartRef.Expr)
276 if ((
bool)
ML[
"{0} == 0"].Format(tDenom).FullSimplify().EvalObject())
280 if ((
bool)
ML[
"{0} == 0"].Format(tNum).FullSimplify().EvalObject())
282 return "(1/2)".MsEvalWith();
287 Expr q =
ML[
"{0}/{1}"].Format(tNum, tDenom).FullSimplify().Eval();
289 return ((
bool)
ML[
"{0} > 0 && {0} < 1"].Format(q).FullSimplify().EvalObject())
305 return HalfEdges.Any(he => f.CheckIntersectSlow(he.EndPointPacket));
308 private bool PlaneCheck(
Facet f)
312 bool pointsInFront =
false;
313 bool pointsInBack =
false;
315 Expr headPt = Head.Start.Expr;
318 .Select(pr => pr.Expr)
320 ML[
"{0} - {1}"].Format(p, headPt).Eval()))
322 Expr dot =
ML[
"Dot"].Bracket(vector, normal).FullSimplify().Eval();
323 if ((
bool)
ML[
"{0} > 0"].Format(dot).EvalObject())
325 pointsInFront =
true;
327 if ((
bool)
ML[
"{0} < 0"].Format(dot).EvalObject())
331 if (pointsInBack && pointsInFront)
344 get {
return ML[
"Mean"].Bracket(
Points).Eval(); }
355 return ML[
"Inset"].Bracket(labelNumber, labelpoint).Eval();
365 return ML[
"Text"].Bracket(labelNumber,
Midpoint).Eval();
375 var labels = Enumerable.Range(startFrom, int.MaxValue).NetZip(
HalfEdges, (i, h) => h.Label(i));
400 return HalfEdges.Skip(i - 1).First();
418 return ML[
"List[ {{Purple, Arrow[ {{ {0}, {0} + .5*{1} }} ] }} ]"].Format(
Midpoint,
Normal).Eval();
429 return ML[
"List"].Bracket(
430 ML[
"List"].Bracket(HalfEdges.Select(he => he.Highlight)).Eval()
IEnumerable< Facet > Triangulate()
Triangulates this Facet and returns any new Facets that get created in the process.
Expr HELabelsStartingFrom(int startFrom)
Generates labels for the halfEdges
HalfEdge FacetRingClone
Clones all the HalfEdges in this HalfEdge's facet
bool Convex
Placeholder convexity checker.
PointRef End
Reference to the end point of this HalfEdge.
bool CheckIntersectSlow(Facet f)
Checks to see if Facet f intersects with this Facet.
Expr Color
This facet's color when drawn with Mathematica
PointRef[] PointRefArray
An array of every vertex of this facet
IEnumerable< PointRef > PointRefs
Enumerates the vertices of this facet
HalfEdge Head
A HalfEdge around this facet designated arbitrarily as the head. Does not change. ...
HalfEdge PickHalfEdge(int i)
Allows the user to pick a HalfEdge by cross-referencing with the HELabels
Expr Highlight
Returns this facet, but colored Yellow. A good usage of this property is to call Graphics3D[{poly,facet}] in Mathematica, which will give you a graphical representation of the polygon, but with this facet highlighted.
Expr HELabels
Generates labels for the HalfEdges, starting from 1.
Expr Points
A Mathematica List of the coordinates of every vertex
Facet CloneWithAllHalfEdgesCloned
Creates a clone of this Facet that has all new HalfEdges and PointRefs in it, but in the same locatio...
Expr Normal
Assuming the vertices on this facet are coplanar, gives the normal of this facet. ...
Expr Point
Point that this plane passes throug
A container for a Halfedge's start and end points. An immutable container.
Holds a reference to a point in the form of a Mathematica expression
static PointRef Ref010
For testing use
bool CheckIntersectSlow(EndPointPacket p)
Checks to see is this Facet intersects an Endpointpacket
Facet(HalfEdge head, string color="RGBColor[1,1,1]")
Constructs a facet
Expr ClipLabel(int labelNumber)
Creates a graphics primitive representing a label which can't be covered up
static PointRef OriginRef
For testing use
IEnumerable< HalfEdge > HalfEdges
Enumerates the HalfEdges around this facet starting from Head
Expr InsetLabel(int labelNumber)
Creates a graphics primitive representing an inset label floating .1 units above the facet...
The building blocks of a geometric model, a HalfEdge consists of a reference to a start and end point...
void ForceHalfEdgesToReferenceThis()
Goes through all Half-Edges of this Facet and forces them to reference this Facet in their "Facet" fi...
Facets are little more than a link to a HalfEdge, but they provide a convenient interface for manipul...
Facet SubDivide(PointRef v1, PointRef v2)
Subdivides this facet with an edge from v1 to v2.
static Facet TestQuad
Used for testing. Creates a small square facet in the xy plane.
static PointRef Ref100
For testing use
Expr Normal
Normal to the plane
string Tag
A tag string for this facet. Useful for debugging.
Point-normal representation of the plane containing this HalfEdge. An immutable container.
Expr HEHighlights
Highlights the HalfEdges of this Facet.
Expr Midpoint
Finds the 'Midpoint' of this Facet by averaging all the vertices together.
Expr Graphics
Mathematica graphics object which represents the facet
Expr NormalGraphics
Gives a graphical representation of the Normal vector for this facet.