PolyLink
A library to allow manipulation of geometry from within Mathematica
 All Classes Namespaces Files Functions Variables Properties
Containers.cs
Go to the documentation of this file.
1 using System.Text;
2 using System.Threading.Tasks;
3 using Wolfram.NETLink;
4 
5 namespace PolyLink
6 {
7  //TODO Figure out how to MathLink up them Structs! fool
8 
12  public struct EndPointPacket
13  {
14  private readonly PointRef _startRef;
15  private readonly PointRef _endRef;
16 
22  public EndPointPacket(PointRef startRef, PointRef endRef) : this()
23  {
24  _startRef = startRef;
25  _endRef = endRef;
26  }
27 
31  public PointRef StartRef
32  {
33  get { return _startRef; }
34  }
35 
39  public PointRef EndRef
40  {
41  get { return _endRef; }
42  }
43 
48  {
49  get
50  {
51  return new EndPointPacket(EndRef, StartRef);
52  }
53  }
54 
58  public Expr AsVector
59  {
60  get { return EndRef - StartRef; }
61  }
62 
66  public Expr Magnitude
67  {
68  get
69  {
70  return "Sqrt".MsBracket(
71  "Dot".MsBracket(new[] {this.AsVector, this.AsVector}));
72  }
73  }
74  }
75 
79  public struct Plane
80  {
81  private readonly Expr _point;
82  private readonly Expr _normal;
83 
89  public Plane(Expr point, Expr normal) : this()
90  {
91  _normal = "Normalize".MsBracket(normal);
92  _point = point;
93  }
94 
98  public Expr Point
99  {
100  get { return _point; }
101  }
102 
106  public Expr Normal
107  {
108  get { return _normal; }
109  }
110 
111 
112 
113  //Static methods for unit testing
114  public static Expr UpVec
115  {
116  get { return _upVec; }
117  }
118 
119  private static readonly Expr _upVec = "{0,1,0}".MsEvalWith();
120 
124  public static Plane TestOriginUp
125  {
126  get
127  {
128  return new Plane(PointRef.Origin, UpVec);
129  }
130  }
136  public Expr ProjectPoint(Expr q)
137  {
138  var vec = "{0} - {1}".MsEvalWith(q, Point);
139  var dist = "Dot[{0},{1}]".MsEvalWith(vec, Normal);
140  return "{0} - {1} * {2}".MsEvalWith(q, dist, Normal);
141  }
142  }
143 }