using System; using Bentley.Geometry; using Bentley.GenerativeComponents; using Bentley.GenerativeComponents.MicroStation; using Bentley.Interop.MicroStationDGN; using Wolfram.NETLink; // Must be in this namespace. namespace Bentley.GenerativeComponents.Features { public class BSplineCurveMath : Features.BSplineCurve { /// <summary> /// Takes an xFunction, yFunction, and zFunction and /// generates a curve. /// </summary> /// TODO: Error handling, ReFactor Generation of points. [Update] public bool ByXYZFunction ( FeatureUpdateContext updateContext, [ParentModel] CoordinateSystem coord, [Replicatable] string xFunction, [Replicatable] string yFunction, [Replicatable] string zFunction ) { // This launches the Mathematica kernel: IKernelLink ml = MathLinkFactory.CreateKernelLink(); // Discard the initial InputNamePacket the kernel will send when launched. ml.WaitAndDiscardAnswer(); // Evaluate the definitions for xFunction, yFunction, and zFunction. // These are coming from Generative Components Feature Definition. // For example, Make the following assignments in GC: // xFunction = "X[t_] = Sin[t];" // yFunction = "Y[t_] = Cos[t];" // zFunction = "t;" // This defines a helix in the Mathematica Environment. ml.EvaluateToOutputForm(xFunction, 0); ml.EvaluateToOutputForm(yFunction, 0); ml.EvaluateToOutputForm(zFunction, 0); DPoint3d[] points = new DPoint3d[10]; // This is where the points are assigned. Refactoring neccecary here. points[0] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[0.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[0.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[0.]", 0))); points[1] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[1.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[1.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[1.]", 0))); points[2] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[2.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[2.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[2.]", 0))); points[3] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[3.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[3.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[3.]", 0))); points[4] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[4.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[4.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[4.]", 0))); points[5] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[5.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[5.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[5.]", 0))); points[6] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[6.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[6.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[6.]", 0))); points[7] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[7.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[7.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[7.]", 0))); points[8] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[8.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[8.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[8.]", 0))); points[9] = new DPoint3d(Convert.ToDouble(ml.EvaluateToOutputForm("X[9.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Y[9.]", 0)), Convert.ToDouble(ml.EvaluateToOutputForm("Z[9.]", 0))); // Always close the math link. ml.Close(); // Since we are inheriting from base bSplineCurve class, // we can call the base to generate the curve based on a collection of DPoint3ds. return base.ByPointsAsDPoint3ds(coord, points, false); } } }

### Categories

- C# (4)
- Digital Media (5)
- Engineering (1)
- Generative Components (7)
- Mathematics (5)
- Sculpture (3)
- Software Programming (9)

## Dispersing Whole Pennies Proportionally to Hours Worked

This test will disperse pennies across a set of workdays proportionally to the hours worked. Pay must not be in fractions of cents and no day can have 0 pay.

The basic strategy is to use the ratio of hours worked to total hours to determine the approximate pay for the day. Round the pay down to an integer by using Math.Floor. Calculate the total pay after doing this. If there are any remaining pennies to disperse, simply sort the list by hours worked and traverse the list, adding any remaining pennies to the remaining days.

Here are the results for dispersing 32 pennies across 8 work days: (date / hours worked / pennies earned)

12/26/09 12 7

12/29/09 10 6

12/27/09 10 6

12/31/09 10 5

12/28/09 7 4

12/30/09 5 2

01/01/10 1 1

12/25/09 1 1