Hi guys
I have a very simple POB object which is just a wedge, and I’m trying to see how the angle between the internal and external reflective surfaces change with tilt angle rotation around x. I can do this fine in OpticsStudio, by altering the TiltAroundX in the non-sequential component editor.
I then made a C# standalone app, so that I could control what I wanted programmatically.
I open up the file, no problems:
IOpticalSystem TheSystem = TheApplication.PrimarySystem;
// Add your custom code here...
///open relevant file
bool SuccessfulFileOpen = TheSystem.LoadFile(FQP,
saveIfNeeded: false
);
Console.WriteLine("File succesfully opened: " + SuccessfulFileOpen);
Console.WriteLine(FQP);
I then access the object to make sure it’s thr right one:
INonSeqEditor NCE = TheSystem.NCE;
INCERow Object_n = NCE.GetObjectAt(ObjectNumber: 1);
Console.WriteLine("Object Comment: " + Object_n.Comment);
And set up a batch ray trace
//set up ray tracing
var rayTracer = TheSystem.Tools.OpenBatchRayTrace();
var nRays = 5000;
var normUnPolData = rayTracer.CreateNormUnpol(nRays, ZOSAPI.Tools.RayTrace.RaysType.Real, nSurfaces);
var calcOPD = ZOSAPI.Tools.RayTrace.OPDMode.None;
Last step is I increment over all the tilt angles as follows:
var start = -2;
var end = -22;
for (double j = start; j >= end; j--)
{
Object_n.TiltAboutX = j;
//TheSystem.Save();
//clear data from batch
normUnPolData.ClearData();
List<Tuple<double, double, double>> xyz = new List<Tuple<double, double, double>>();
for (int ray = 0; ray <= nRays; ray++)
{
var hx = NormRandom(1);
var hy = NormRandom(1); ;
var rand_px = NormRandom(1);
var rand_py = NormRandom(1);
while (rand_px * rand_px + rand_py * rand_py > 1)
{
rand_py = NormRandom(1);
}
normUnPolData.AddRay(1, rand_px, rand_py, 0, 0, calcOPD);
}
rayTracer.RunAndWaitForCompletion();
normUnPolData.StartReadingResults();
for (int ray = 0; ray <= nRays; ray++)
{
var rayN = 0;
double X;
double Z;
double Y;
var error = 0;
var vign = 0;
double A, B, C, D, E, F, G, H = 0;
bool success = normUnPolData.ReadNextResult(out rayN, out error, out vign, out X, out Y, out Z, out A, out B, out C, out D, out E, out F, out G, out H);
xyz.Add(new Tuple<double, double, double>(X, Y, Z));
}
}
And collect the data. In my eyes, this is identical to what I would be doing inside OpticsStudio, but for some reason, it doesn’t seem to work like it does in the GUI. Am I doing anything wrong? I’m varying the TiltAboutX in increments, collecting rays, and last step not shown is saving them to a CSV file.
However, when I plot the data in python, I get the following:
Which is not right, so I must be doing something wrong in the code.
I’ve even tried to change the TiltAroundX to say -2, saved when it gets to -22 in the C# program, and then opened it up in the GUI, and the wedge is at that saved angle, so I know I’m rotating the right object in the right way.
Any help would be greatly helpful!