public RayScattered Scatter(Dielectric dielectric, Ray ray, RayHitpoint hitpoint, Color rayColor) { Vector3 outwardNormal; var reflected = Maths.Reflect(ray.Direction, hitpoint.Normal); float niOverNt; float cosine; if (Vector3.Dot(ray.Direction, hitpoint.Normal) > 0) { outwardNormal = -hitpoint.Normal; niOverNt = dielectric.Index; cosine = Vector3.Dot(ray.Direction, hitpoint.Normal) / ray.Direction.Length(); cosine = (float)Math.Sqrt(1 - dielectric.Index * dielectric.Index * (1 - cosine * cosine)); } else { outwardNormal = hitpoint.Normal; niOverNt = 1.0f / dielectric.Index; cosine = -Vector3.Dot(ray.Direction, hitpoint.Normal) / ray.Direction.Length(); } var refracted = Maths.Refract(ray.Direction, outwardNormal, niOverNt); var reflectProb = refracted.HasValue ? Schlick(cosine, dielectric.Index) : 1.0f; var newRay = Maths.RandomGenerator.NextDouble() < reflectProb ? new Ray(hitpoint.Point, reflected) : new Ray(hitpoint.Point, refracted); return(new RayScattered(newRay, rayColor)); }
private static Structure CreateSiO2TestStructure() { var topMetal = new Metal(Length.FromNanometers(4)); topMetal.SetWorkFunction(Energy.FromElectronVolts(4.45)); var oxide = new Dielectric(Length.FromNanometers(2)); oxide.DielectricConstant = 3.9; oxide.BandGap = Energy.FromElectronVolts(8.9); oxide.ElectronAffinity = Energy.FromElectronVolts(0.95); var semiconductor = new Semiconductor(); semiconductor.BandGap = Energy.FromElectronVolts(1.1252); semiconductor.ElectronAffinity = Energy.FromElectronVolts(4.05); semiconductor.DielectricConstant = 11.7; semiconductor.IntrinsicCarrierConcentration = Concentration.FromPerCubicCentimeter(1.41E10); semiconductor.DopingType = DopingType.N; semiconductor.DopantConcentration = Concentration.FromPerCubicCentimeter(1E18); var structure = new Structure(); structure.Temperature = new Temperature(300); structure.AddLayer(semiconductor); structure.AddLayer(oxide); structure.AddLayer(topMetal); return(structure); }
private static Structure CreateMIMTestStructure() { var topMetal = new Metal(Length.FromNanometers(4)); topMetal.SetWorkFunction(Energy.FromElectronVolts(4.45)); var oxide = new Dielectric(Length.FromNanometers(2)); oxide.DielectricConstant = 3.9; oxide.BandGap = Energy.FromElectronVolts(8.9); oxide.ElectronAffinity = Energy.FromElectronVolts(0.95); var bottomMetal = new Metal(Length.FromNanometers(4)); bottomMetal.SetWorkFunction(Energy.FromElectronVolts(4.45)); var structure = new Structure(); structure.Temperature = new Temperature(300); structure.AddLayer(bottomMetal); structure.AddLayer(oxide); structure.AddLayer(topMetal); return(structure); }
public double GridResolution = 1.0; // mm public HeadPhantom(string name = "head-phantom", double width = 160, double height = 200) : base(name) { Width = width; Height = height; Dielectric skinMaterial = new Dielectric("skin", 50, kappa: 0.65, density: 1100); skinMaterial.FillColor = new Material.Color(245, 215, 205, 15); skinMaterial.EdgeColor = new Material.Color(255, 235, 217, 15); Sphere skin = new Sphere(null, skinMaterial, 11, new Vector3D(), 1); skin.Transformations.Add(new TScale(Width / 2, Width / 2, Height / 2)); this.Add(skin); Dielectric boneMaterial = new Dielectric("bone", 13, kappa: 0.1, density: 2000); boneMaterial.FillColor = new Material.Color(227, 227, 227, 15); boneMaterial.EdgeColor = new Material.Color(202, 202, 202, 15); Sphere bone = new Sphere(null, boneMaterial, 12, new Vector3D(), 1); bone.Transformations.Add(new TScale(0.95 * Width / 2, 0.95 * Width / 2, 0.95 * Height / 2)); this.Add(bone); Dielectric brainMaterial = new Dielectric("brain", 60, kappa: 0.7, density: 1040); brainMaterial.FillColor = new Material.Color(255, 85, 127, 15); brainMaterial.EdgeColor = new Material.Color(71, 222, 179, 15); Sphere brain = new Sphere(null, brainMaterial, 13, new Vector3D(), 1); brain.Transformations.Add(new TScale(0.9 * Width / 2, 0.9 * Width / 2, 0.9 * Height / 2)); this.Add(brain); }
public static Hittable_list random_scene() { Hittable_list world = new Hittable_list(); var ground_material = new Lambertian(new Color(0.5, 0.5, 0.5)); world.add(new Sphere(new Point3(0, -1000, 0), 1000, ground_material)); for (int a = -11; a < 11; a++) { for (int b = -11; b < 11; b++) { var choose_mat = Utilities.random_double(); Point3 center = new Point3(a + 0.9 * Utilities.random_double(), 0.2, b + 0.9 * Utilities.random_double()); if ((center - new Point3(4, 0.2, 0)).length() > 0.9) { Material sphere_material; if (choose_mat < 0.8) { Color albedo = Color.random() * Color.random(); sphere_material = new Lambertian(albedo); world.add(new Sphere(center, 0.2, sphere_material)); } else if (choose_mat < 0.95) { Color albedo = Color.random(0.5, 1); var fuzz = Utilities.random_double(0, 0.5); sphere_material = new Metal(albedo, fuzz); world.add(new Sphere(center, 0.2, sphere_material)); } else { sphere_material = new Dielectric(1.5); world.add(new Sphere(center, 0.2, sphere_material)); } } } } var material1 = new Dielectric(1.5); world.add(new Sphere(new Point3(0, 1, 0), 1.0, material1)); var material2 = new Lambertian(new Color(0.4, 0.2, 0.1)); world.add(new Sphere(new Point3(-4, 1, 0), 1.0, material2)); var material3 = new Metal(new Color(0.7, 0.6, 0.5), 0.0); world.add(new Sphere(new Point3(4, 1, 0), 1.0, material3)); return(world); }
public void SetEpsilon_InvalidEpsilon_ThrowsException() { // Arrange const double InvalidPermittivity = -1.0; var target = new Dielectric(); // Act Complex result = target.Epsilon = InvalidPermittivity; // Assert // See ExpectedException }
public void GetPermittivity_DefaultEpsilon_ReturnsOne() { // Arrange var parameter = new SpectrumUnit(300e-9, SpectrumUnitType.WaveLength); var target = new Dielectric(); // Act Complex result = target.GetPermittivity(parameter); // Assert Assert.AreEqual(Complex.One, result); }
private Hitable[] OneWeekScene() { var center = new Vector3(4.0f, 2.0f, 0.0f); var position = new Vector3(0.0f, -1000.0f, 0.0f); var hitables = new List <Hitable>(500); hitables.Add(new Sphere(position, -position.y, new Lambertian(0.5f * Vector3.one))); float radius = 0.2f; var dielectric = new Dielectric(1.5f); for (int a = -11; a < 11; ++a) { for (int b = -11; b < 11; ++b) { position.Set(a + 0.9f * Util.UnitRandFloat(), radius, b + 0.9f * Util.UnitRandFloat()); if ((position - center).sqrMagnitude <= 0.81) { continue; } var chooseMat = Util.UnitRandFloat(); if (chooseMat < 0.8f) { // hitables.Add(new Sphere(position, radius, new Lambertian(new Vector3(Util.UnitRandFloat(), Util.UnitRandFloat(), Util.UnitRandFloat())))); hitables.Add(new MovingSphere(position, position + new Vector3(0.0f, 0.5f * Util.UnitRandFloat(), 0.0f), 0.0f, 1.0f, radius, new Lambertian(new Vector3(Util.UnitRandFloat(), Util.UnitRandFloat(), Util.UnitRandFloat())))); continue; } if (chooseMat < 0.95f) { hitables.Add(new Sphere(position, radius, new Metal(new Vector3(0.5f * (1.0f + Util.UnitRandFloat()), 0.5f * (1.0f + Util.UnitRandFloat()), 0.5f * (1.0f + Util.UnitRandFloat())), 0.5f * (1.0f + Util.UnitRandFloat())))); continue; } hitables.Add(new Sphere(position, radius, dielectric)); } } radius = 1.0f; position.Set(0.0f, 1.0f, 0.0f); hitables.Add(new Sphere(position, radius, dielectric)); position.Set(-4.0f, 1.0f, 0.0f); hitables.Add(new Sphere(position, radius, new Lambertian(new Vector3(0.4f, 0.2f, 0.1f)))); position.Set(4.0f, 1.0f, 0.0f); hitables.Add(new Sphere(position, radius, new Metal(new Vector3(0.7f, 0.6f, 0.5f), 0.0f))); var retval = new Hitable[1]; retval[0] = new BvhNode(hitables.ToArray(), 0, hitables.Count, 0.0f, 1.0f); return(retval); }
public void GetPermittivity_SetEpsilon_ReturnsOne() { // Arrange const double RelativePermittivity = 5.0; var parameter = new SpectrumUnit(300e-9, SpectrumUnitType.WaveLength); var target = new Dielectric { Epsilon = RelativePermittivity }; // Act Complex result = target.GetPermittivity(parameter); // Assert Assert.AreEqual(RelativePermittivity, result); }
private void CornellBox() { this.width = 512; this.height = 512; isSky = false; Vector3D lookFrom = new Vector3D(278, 278, -800); Vector3D lookAt = new Vector3D(278, 278, 0); float diskToFocus = 10; float aperture = 0; float vfov = 40; camera = new Camera(lookFrom, lookAt, new Vector3D(0, 1, 0), vfov, (float)width / (float)height, aperture, diskToFocus, 0, 1); List <Hitable> list = new List <Hitable>(); Material red = new Lambertian(new ConstantTexture(new Vector3D(0.65f, 0.05f, 0.05f))); Material white = new Lambertian(new ConstantTexture(new Vector3D(0.73f, 0.73f, 0.73f))); Material green = new Lambertian(new ConstantTexture(new Vector3D(0.2f, 0.45f, 0.15f))); Material light = new DiffuseLight(new ConstantTexture(new Vector3D(50, 50, 50))); Material aluminum = new Metal(new Vector3D(0.8f, 0.85f, 0.88f), 0); Material glass = new Dielectric(1.5f); //list.Add(new FlipNormals(new XZRect(213, 343, 227, 332, 554, light))); list.Add(new FlipNormals(new XZTriangle(213, 343, 278, 227, 227, 332, 554, light))); list.Add(new FlipNormals(new YZRect(0, 555, 0, 555, 555, green))); list.Add(new YZRect(0, 555, 0, 555, 0, red)); //list.Add(new YZTriangle(0, 555, 555, 0, 0, 555, 0, red)); list.Add(new FlipNormals(new XZRect(0, 555, 0, 555, 555, white))); list.Add(new XZRect(0, 555, 0, 555, 0, white)); list.Add(new FlipNormals(new XYRect(0, 555, 0, 555, 555, white))); //list.Add(new Translate(new RotateY(new Box(new Vector3D(0, 0, 0), // new Vector3D(165, 165, 165), white), -18), new Vector3D(130, 0, 65))); list.Add(new Translate(new RotateY(new Box(new Vector3D(0, 0, 0), new Vector3D(165, 330, 165), white), 15), new Vector3D(265, 0, 295))); // list.Add(new Translate(new RotateY(new Box(new Vector3D(0, 0, 0), // new Vector3D(165, 330, 165), aluminum), 15), new Vector3D(265, 0, 295))); list.Add(new Sphere(new Vector3D(190, 90, 190), 90, glass)); BVHNode b = new BVHNode(list, list.Count, 0, 1); world.list.Add(b); }
static void Main() { bool writeDebugInfo = false; IMaterial groundMaterial = new LambertianDiffuse(Color3.FromRgb(255, 212, 216)); IMaterial rightMaterial = new Metal(Color3.FromRgb(220, 220, 220)); IMaterial leftMaterial = new Dielectric(1.5); IMaterial centerMaterial = new LambertianDiffuse(Color3.FromRgb(222, 133, 255)); Renderer renderer = new() { // Define objects in the scene HittableObjects = new HittableList { new Sphere(new Vector3(0, 1, -100.5), 100, groundMaterial), new Sphere(new Vector3(0, 1, 0), 0.5, centerMaterial), new Sphere(new Vector3(-1, 1, 0), 0.5, leftMaterial), new Sphere(new Vector3(1, 1, 0), 0.5, rightMaterial), } }; // Define the camera Camera camera = new(1280, 720) { Origin = new Vector3(0, 0, 0), MultithreadedRendering = true, SamplesPerPixel = 100, MaxBounces = 12 }; // Render RenderResult result = new(); result.frameNumber = 0; result.camera = camera; result.pixels = renderer.RenderScene(camera, out result.frameTime); // Write to disk System.IO.Directory.CreateDirectory("./images/"); Renderer.WriteFrame("./images/image_" + result.frameNumber + ".png", result.pixels, result.camera.ResolutionHeight, result.camera.ResolutionWidth, ImageFormat.Png, writeDebugInfo, result.frameTime, result.camera); } }
protected override void Start() { base.Start(); if (plate1 == null || plate2 == null) { Debug.LogError("Capacitor requires two plates!"); gameObject.SetActive(false); } if (chargePoolHander == null) { chargePoolHander = GameObject.FindObjectOfType <ChargePoolHandler>(); if (chargePoolHander == null) { Debug.LogError("Capacitor requires a charge pool handler!"); } } dielectric = GameObject.FindObjectOfType <Dielectric>(); }
public HitableList GetSceneWorld() { var world = new HitableList { new Sphere(new Vector3(0, -1000, 0), 1000f, new Lambertian(new CheckerTexture(new ConstantTexture(Colors.AntiqueWhite), new ConstantTexture(Colors.DarkBlue)))) }; Func <float> randFloat = VectorHelpers.RandomFloat; for (int i = -5; i < 5; i++) { for (int j = -5; j < 5; j++) { Vector3 center = new Vector3(i + 0.9f * randFloat(), 0.2f, j + 0.9f * randFloat()); float materialChoice = randFloat(); Material m; if (materialChoice < 0.75) { m = new Lambertian(new ConstantTexture(new Vector3(randFloat() * randFloat(), randFloat() * randFloat(), randFloat() * randFloat()))); } else if (materialChoice < 0.95) { m = new Metal(new Vector3(0.5f * (1 + randFloat()), 0.5f * (1 + randFloat()), 0.5f * (1 + randFloat())), 0.5f * randFloat()); } else { m = new Dielectric(1.5f); } var s = new Sphere(center, 0.2f, m); world.Add(s); } } world.Add(new Sphere(new Vector3(0, 1, 0), 1.0f, new Dielectric(1.5f))); world.Add(new Sphere(new Vector3(-4, 1, 0), 1.0f, new Lambertian(new ConstantTexture(new Vector3(0.4f, 0.2f, 0.1f))))); world.Add(new Sphere(new Vector3(4, 1, 0), 1.0f, new Metal(new Vector3(0.7f, 0.6f, 0.5f), 0))); return(world); }
public World CreateBookWorld() { var hitables = new List <IHitable>(); hitables.Add(new Sphere(new Vector3(0f, -1000f, 0f), 1000f, new Lambertian(new Vector3(0.5f, 0.5f, 0.5f)))); var rand = new Random(); for (var a = -11; a < 11; a++) { for (var b = -11; b < 11; b++) { var chooseMat = (float)rand.NextDouble(); var center = new Vector3(a + 0.9f * (float)rand.NextDouble(), 0.2f, b + 0.9f * (float)rand.NextDouble()); if ((center - new Vector3(4f, 0.2f, 0f)).Length() > 0.9f) { IMaterial material; if (chooseMat < 0.8f) //diffuse { material = new Lambertian(new Vector3((float)(rand.NextDouble() * rand.NextDouble()), (float)(rand.NextDouble() * rand.NextDouble()), (float)(rand.NextDouble() * rand.NextDouble()))); } else if (chooseMat < 0.95) //metal { material = new Metal(new Vector3(0.5f * (float)(1f + rand.NextDouble()), 0.5f * (float)(1 + rand.NextDouble()), 0.5f * (float)(1 + rand.NextDouble())), 0.5f * (float)(1 + rand.NextDouble())); } else //glass { material = new Dielectric(1.5f); } hitables.Add(new Sphere(center, 0.2f, material)); } } } hitables.Add(new Sphere(new Vector3(0f, 1f, 0f), 1.0f, new Dielectric(1.5f))); hitables.Add(new Sphere(new Vector3(-4.0f, 1, 0), 1.0f, new Lambertian(new Vector3(0.4f, 0.2f, 0.1f)))); hitables.Add(new Sphere(new Vector3(4f, 1f, 0f), 1.0f, new Metal(new Vector3(0.7f, 0.6f, 0.5f), 0.0f))); var world = new World(hitables); return(world); }
public void Polygon_SwappedArrayDimensionsInConstructor_ReturnsSameObject() { double[,] v1 = new double[2, 3] { { 0.0, 1.0, 2.0 }, { 3.0, 4.0, 5.0 } }; double[,] v2 = new double[v1.GetLength(1), v1.GetLength(0)]; for (int i = 0; i < v2.GetLength(0); i++) { for (int j = 0; j < v2.GetLength(1); j++) { v2[i, j] = v1[j, i]; } } Material m = new Dielectric("dummy"); Polygon p1 = new Polygon(null, m, 0, 2, 0, v1); Polygon p2 = new Polygon(null, m, 0, 2, 0, v2); Assert.Equal(p1.Points, p2.Points); }
public void RenderScene() { int nx = 800; int ny = 400; int ns = 100; var lowerLeftCorner = new Vector3(-2.0, -1.0, -1.0); var horizontal = new Vector3(4.0, 0.0, 0.0); var vertical = new Vector3(0.0, 2.0, 0.0); var origin = new Vector3(0.0, 0.0, 0.0); Random rng = new Random(); UnitSphereUniformSampler sphereSampler = new UnitSphereUniformSampler(rng); UnitCircleUniformSampler circleSampler = new UnitCircleUniformSampler(rng); IMaterial mat1 = new Lambertian(new Vector3(0.1, 0.2, 0.5), sphereSampler); IMaterial mat2 = new Lambertian(new Vector3(0.8, 0.8, 0.0), sphereSampler); IMaterial mat3 = new Metal(new Vector3(0.8, 0.6, 0.2), 0.3, sphereSampler); IMaterial mat4 = new Dielectric(1.5, rng); List <IHitable> objects = new List <IHitable>(4); objects.Add(new Sphere(new Vector3(0, 0, -1), 0.5, mat1)); objects.Add(new Sphere(new Vector3(0, -100.5, -1), 100, mat2)); objects.Add(new Sphere(new Vector3(1, 0, -1), 0.5, mat3)); objects.Add(new Sphere(new Vector3(-1, 0, -1), 0.5, mat4)); objects.Add(new Sphere(new Vector3(-1, 0, -1), -0.45, mat4)); HitableList world = new HitableList(objects); Vector3 lookFrom = new Vector3(-2, 2, 1); Vector3 lookAt = new Vector3(0, 0, -1); Camera camera = new Camera( circleSampler, lookFrom, lookAt, new Vector3(0, 1, 0), 90.0 * Math.PI / 180.0, (double)nx / (double)ny, 0.2, (lookAt - lookFrom).Length()); Random random = new Random(); // Create folder to output frames if (!Directory.Exists("ThreeSpheres")) { Directory.CreateDirectory("ThreeSpheres"); } Sensor sensor = new Sensor(nx, ny, new SqrtColorSpace(), RGBColor.Black); int frameNum = 0; for (int s = 0; s < ns; ++s) { for (int j = ny - 1; j >= 0; --j) { for (int i = 0; i < nx; i++) { double u = (i + random.NextDouble()) / nx; double v = (j + random.NextDouble()) / ny; Ray3 r = new Ray3(camera.GetRay(u, v)); Vector3 color = Program.Color(r, world, 0); sensor.AddSample(i, j, new RGBColor(color[0], color[1], color[2])); } } if (s % (ns / 10) == 0) { // Output 1 frame with current number of samples sensor.WritePPMFile($"ThreeSpheres\\frame_{frameNum}.ppm").Wait(); frameNum++; } Console.Write("\r{0}", s); } sensor.WritePPMFile("finalOutput.ppm").Wait(); }
static void TestAraPhone() { Endo e = new Endo(null, "endo", new Vector3D(0, 0, 0), 0); Module_1x2 m1 = new Module_1x2("m1"); Module_2x2 m2 = new Module_2x2("m2"); Module_1x2 m4 = new Module_1x2("m4"); Module_2x2 m5 = new Module_2x2("m5"); Module_1x2 m6 = new Module_1x2("m6"); Module_1x2 m7 = new Module_1x2("m7"); XmlCompound u1 = new XmlCompound(m1, "u1", new Vector3D(0, 0, 0), 0); u1.Parse(XElement.Load("Box.xml")); u1.Transformations.Add(new TTranslate(20, 3, 3)); m5.Add(u1); //e.AddModule(1, m1); //e.AddModule(3, m2); //e.AddModule(4, m4); e.AddModule(5, m5); //e.AddModule(6, m6); //e.AddModule(7, m7); // Phantom Compound headPhantom = new Compound("head-phantom"); Dielectric skinMaterial = new Dielectric("skin", 50, kappa: 0.65, density: 1100); skinMaterial.FillColor = new Material.Color(245, 215, 205, 54); skinMaterial.EdgeColor = new Material.Color(255, 235, 217, 250); Sphere skin = new Sphere(null, skinMaterial, 11, new Vector3D(), 1); skin.Transformations.Add(new TScale(80, 100, 80)); headPhantom.Add(skin); Dielectric boneMaterial = new Dielectric("bone", 13, kappa: 0.1, density: 2000); boneMaterial.FillColor = new Material.Color(227, 227, 227, 54); boneMaterial.EdgeColor = new Material.Color(202, 202, 202, 250); Sphere bone = new Sphere(null, boneMaterial, 12, new Vector3D(), 1); bone.Transformations.Add(new TScale(75, 95, 75)); headPhantom.Add(bone); Dielectric brainMaterial = new Dielectric("brain", 60, kappa: 0.7, density: 1040); brainMaterial.FillColor = new Material.Color(255, 85, 127, 54); brainMaterial.EdgeColor = new Material.Color(71, 222, 179, 250); Sphere brain = new Sphere(null, brainMaterial, 13, new Vector3D(), 1); brain.Transformations.Add(new TScale(65, 85, 65)); headPhantom.Add(brain); headPhantom.Transformations.Add(new TTranslate(33, 70, 90)); Compound s = new Compound("space"); s.Add(e); s.Add(headPhantom); RectilinearGrid g = new SimpleGrid_6x3(); g.ZLines.Add(170); double airBox = 50; double maxRes = 5; double ratio = 1.5; g.AddAirbox(airBox); g.SmoothMesh(maxRes, ratio); s.Add(new SARBox("SAR", 1200e6, new Vector3D(), new Vector3D(20, 20, 20))); s.Add(new NF2FFBox("nf2ff", new Vector3D(g.XLines.First(), g.YLines.First(), g.ZLines.First()), new Vector3D(g.XLines.Last(), g.YLines.Last(), g.ZLines.Last()))); s.Add(new LumpedPort(100, 1, 50.0, new Vector3D(-0.1, -0.1, -1.25), new Vector3D(+0.1, +0.1, +1.25), ENormDir.Z, true)); Simulation fdtd = new Simulation(); fdtd.Excitation = new GaussExcitation(1e9, 1.5e9); g.AddPML(10); XDocument doc = new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XComment("Test XML file for CyPhy generated openEMS simulations"), new XElement("openEMS", fdtd.ToXElement(), new XElement("ContinuousStructure", new XAttribute("CoordSystem", 0), s.ToXElement(), g.ToXElement() ) ) ); doc.Save("CSXTest.xml"); }
static void ExportAntenna_Small_15x6mm() { double thickness = 0.01; double airBox = 5.0; double innerResolution = 0.5; double outerResolution = 5.0; var antenna = new CSXCAD.Antenna.Small_15x6mm_2400MHz(thickness); const double pcbThickness = 1.5; var lumpedPort = new LumpedPort(90, 1, 50, new Vector3D(0.0, 0.0, -pcbThickness), new Vector3D(0.0, 0.0, 0), ENormDir.Z, true); antenna.Add(lumpedPort); double margin = 2.0; double groundWidth = 5.0; var p1 = new Vector3D(antenna.BoundingBox.P1.x - margin, -groundWidth - margin, -pcbThickness); var p2 = new Vector3D(antenna.BoundingBox.P2.x + margin, antenna.BoundingBox.P2.y + margin, 0); double epsRel = 4.88; var substrate = new Dielectric("pcb", epsRel, 1e-3 * 2 * Math.PI * 2.45e9 * epsRel * Material.Eps0); substrate.EdgeColor = new Material.Color(10, 255, 10, 128); substrate.FillColor = new Material.Color(10, 255, 10, 128); var pcb = new CSXCAD.Box(null, substrate, 60, p1, p2); antenna.Add(pcb); var bottomGround = new Metal("bottom-ground"); bottomGround.EdgeColor = new Material.Color(235, 148, 7, 255); bottomGround.FillColor = bottomGround.EdgeColor; var bottomGroundPlane = new CSXCAD.Box(null, bottomGround, 100, new Vector3D(antenna.BoundingBox.P1.x - antenna.D1, antenna.D4 / 2, -pcbThickness), new Vector3D(antenna.BoundingBox.P2.x + antenna.D3, -groundWidth, -pcbThickness - 0.01)); antenna.Add(bottomGroundPlane); var topGround = new Metal("top-ground"); topGround.EdgeColor = new Material.Color(235, 148, 7, 255); topGround.FillColor = topGround.EdgeColor; var topGroundPlane = new CSXCAD.Box(null, topGround, 100, new Vector3D(antenna.BoundingBox.P1.x - antenna.D1, -antenna.D4 / 2, 0), new Vector3D(antenna.BoundingBox.P2.x + antenna.D3, -groundWidth, 0.01)); antenna.Add(topGroundPlane); var viaMetal = new Metal("via"); viaMetal.EdgeColor = new Material.Color(235, 148, 7, 255); viaMetal.FillColor = viaMetal.EdgeColor; var via = new Cylinder(null, viaMetal, 100, new Vector3D(-(antenna.W1 / 2 + antenna.D5 + antenna.W2 / 2), 0, -pcbThickness), new Vector3D(-(antenna.W1 / 2 + antenna.D5 + antenna.W2 / 2), 0, 0), 0.25); antenna.Add(via); Simulation fdtd = new Simulation(); fdtd.Excitation = new GaussExcitation(2450e6, 500e6); RectilinearGrid grid = new RectilinearGrid();; grid.Add(new Vector3D(0, 0, 0)); grid.Add(pcb.P1); grid.Add(pcb.P2); /* * foreach (var v in antenna.antennaPoly) * { * grid.Add(new Vector3D(v.x, v.y, 0)); * } */ grid.SmoothMesh(innerResolution); grid.AddAirbox(airBox); grid.SmoothMesh(outerResolution); var nf2ff = new NF2FFBox("nf2ff", new Vector3D(grid.XLines.First(), grid.YLines.First(), grid.ZLines.First()), new Vector3D(grid.XLines.Last(), grid.YLines.Last(), grid.ZLines.Last())); antenna.Add(nf2ff); grid.AddPML(8); XDocument doc = new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XComment("Test XML file for CyPhy generated openEMS simulations"), new XElement("openEMS", fdtd.ToXElement(), new XElement("ContinuousStructure", new XAttribute("CoordSystem", 0), antenna.ToXElement(), grid.ToXElement() ) ) ); doc.Save("Small_15x6mm.xml"); }
public void build() { DestroyRenderAreaTexture(); texture = new Texture2D(200, 200); GameObject.Find("ViewRectangle").GetComponent <MeshRenderer> ().material.mainTexture = texture; vp = new ViewPlane(texture.width, texture.height, 1.0f, 1); vp.max_depth = 5; background_color = Constants.white; tracer_ptr = new Whitted(this); Jittered jit = new Jittered(1); AmbientOccluder ambocl = new AmbientOccluder(); ambocl.scale_radiance(1.0f); ambocl.set_color(Constants.white); ambocl.set_minAmount(Constants.black); ambocl.SetSampler(jit); set_ambient_light(ambocl); PerspectiveCamera pinhole_ptr1 = new PerspectiveCamera(); pinhole_ptr1.set_eye(new Vector3(0, 0, 500)); pinhole_ptr1.set_lookat(Vector3.zero); pinhole_ptr1.set_view_distance(600.0f); pinhole_ptr1.compute_uvw(); set_camera(pinhole_ptr1); Directional directional = new Directional(); directional.set_color(new Color(1, 1, 1, 1)); directional.set_direction(new Vector3(-1, -1, 0)); directional.cast_shadows = true; directional.scale_radiance(3.0f); add_light(directional); Dielectric mat_ptr = new Dielectric(); mat_ptr.set_eta_in(0.8f); mat_ptr.set_eta_in(1.2f); mat_ptr.set_cf_in(new Color(0.0f, 1.0f, 0.8f, 1)); mat_ptr.set_cf_out(new Color(0.75f, 1.0f, 0.4f, 1)); mat_ptr.set_ks(0.5f); mat_ptr.set_exp(100.0f); mat_ptr.set_ior(1.2f); Sphere sph = new Sphere(); sph.sphereCenter = Vector3.zero; sph.sphereRad = 1.0f; sph.set_material(mat_ptr); Instance sphInst = new Instance(sph); sphInst.set_material(mat_ptr); add_object(sphInst); sphInst.set_identity(); sphInst.Scale(40, 40, 1); sphInst.Translate(0.0f, 0.0f, -60); Dielectric mat_ptr1 = new Dielectric(); mat_ptr.set_eta_in(0.2f); mat_ptr.set_eta_in(0.4f); mat_ptr1.set_cf_in(new Color(0.0f, 1.0f, 0.0f, 1)); mat_ptr1.set_cf_out(new Color(0.75f, 1.0f, 0.0f, 1)); mat_ptr1.set_ks(0.8f); mat_ptr1.set_exp(100.0f); mat_ptr1.set_ior(1.52f); Rectangle rect1 = new Rectangle(Vector3.zero, new Vector3(1, 0, 0), new Vector3(0, 1, 0)); rect1.set_material(mat_ptr1); Instance rect1Inst = new Instance(rect1); rect1Inst.set_material(mat_ptr1); add_object(rect1Inst); rect1Inst.set_identity(); rect1Inst.Scale(80, 80, 1); rect1Inst.Translate(-40, -40, 0.0f); render_scene(); }
static void ExportAntenna_InvertedF() { double thickness = 0.01; double airBox = 5.0; double innerResolution = 0.5; double outerResolution = 5.0; var antenna = new CSXCAD.Antenna.InvertedF_2400MHz(thickness); const double pcbThickness = 1.5; var lumpedPort = new LumpedPort(90, 1, 50, new Vector3D(0.0, 0.0, -pcbThickness), new Vector3D(0.0, 0.0, 0), ENormDir.Z, true); antenna.Add(lumpedPort); double margin = 2.0; double groundWidth = 5.0; var p1 = new Vector3D(antenna.BoundingBox.P1.x - margin, -groundWidth - margin, -pcbThickness); var p2 = new Vector3D(antenna.BoundingBox.P2.x + margin, antenna.BoundingBox.P2.y + margin, 0); var substrate = new Dielectric("pcb", 3.38, 1e-3 * 2 * Math.PI * 2.45e9 * 3.38 * Material.Eps0); substrate.EdgeColor = new Material.Color(10, 255, 10, 128); substrate.FillColor = new Material.Color(10, 255, 10, 128); var pcb = new CSXCAD.Box(null, substrate, 60, p1, p2); //antenna.Add(pcb); var topGround = new Metal("bottom-ground"); topGround.EdgeColor = new Material.Color(235, 148, 7, 255); topGround.FillColor = topGround.EdgeColor; var topGroundPlane = new CSXCAD.Box(null, topGround, 100, new Vector3D(antenna.BoundingBox.P1.x, 0, -pcbThickness), new Vector3D(antenna.BoundingBox.P2.x, -groundWidth, -pcbThickness)); antenna.Add(topGroundPlane); var bottomGround = new Metal("top-ground"); bottomGround.EdgeColor = new Material.Color(235, 148, 7, 255); bottomGround.FillColor = bottomGround.EdgeColor; var topGroundPlaneLeft = new CSXCAD.Box(null, bottomGround, 100, new Vector3D(antenna.BoundingBox.P1.x, 0, 0), new Vector3D(-0.46 / 2 - 0.45, -groundWidth, 0)); var topGroundPlaneRight = new CSXCAD.Box(null, bottomGround, 100, new Vector3D(0.46 / 2 + 0.45, 0, 0), new Vector3D(antenna.BoundingBox.P2.x, -groundWidth, 0)); antenna.Add(topGroundPlaneLeft); antenna.Add(topGroundPlaneRight); Simulation fdtd = new Simulation(); fdtd.Excitation = new GaussExcitation(2450e6, 500e6); RectilinearGrid grid = new RectilinearGrid();; grid.Add(new Vector3D(0, 0, 0)); grid.SmoothMesh(innerResolution); grid.AddAirbox(airBox); grid.SmoothMesh(outerResolution); var nf2ff = new NF2FFBox("nf2ff", new Vector3D(grid.XLines.First(), grid.YLines.First(), grid.ZLines.First()), new Vector3D(grid.XLines.Last(), grid.YLines.Last(), grid.ZLines.Last())); antenna.Add(nf2ff); grid.AddPML(8); XDocument doc = new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XComment("Test XML file for CyPhy generated openEMS simulations"), new XElement("openEMS", fdtd.ToXElement(), new XElement("ContinuousStructure", new XAttribute("CoordSystem", 0), antenna.ToXElement(), grid.ToXElement() ) ) ); doc.Save("InvertedF.xml"); }
public IElementBuilder WithMaterial(Dielectric dielectric) { _scatterable = new Option <IScatterable>(new ScatterableDielectric(dielectric, _scatterableComputer)); return(this); }
private XDocument BuildDipoleSarXml() { double unit = 1e-3; double f0 = 1e9; double c0 = 299792458.0; double lambda0 = c0 / f0; double fStop = 1.5e9; double lambdaMin = c0 / fStop; // Simulation engine Simulation fdtd = new Simulation(); fdtd.Excitation = new GaussExcitation(0, fStop); // possible typo in Dipole_SAR.xml // Simulation space Compound s = new Compound("space"); // Dipole antenna double dipoleLength = 0.46 * lambda0 / unit; s.Add(new Box(null, new Metal("Dipole"), 1, new Vector3D(0, 0, -dipoleLength / 2), new Vector3D(0, 0, dipoleLength / 2))); // Phantom Compound headPhantom = new Compound("head-phantom"); Dielectric skinMaterial = new Dielectric("skin", 50, kappa: 0.65, density: 1100); skinMaterial.FillColor = new Material.Color(245, 215, 205, 250); skinMaterial.EdgeColor = new Material.Color(255, 235, 217, 250); Sphere skin = new Sphere(null, skinMaterial, 11, new Vector3D(), 1); skin.Transformations.Add(new TScale(80, 100, 100)); headPhantom.Add(skin); Dielectric boneMaterial = new Dielectric("headbone", 13, kappa: 0.1, density: 2000); boneMaterial.FillColor = new Material.Color(227, 227, 227, 250); boneMaterial.EdgeColor = new Material.Color(202, 202, 202, 250); Sphere bone = new Sphere(null, boneMaterial, 12, new Vector3D(), 1); bone.Transformations.Add(new TScale(75, 95, 95)); headPhantom.Add(bone); Dielectric brainMaterial = new Dielectric("brain", 60, kappa: 0.7, density: 1040); brainMaterial.FillColor = new Material.Color(255, 85, 127, 250); brainMaterial.EdgeColor = new Material.Color(71, 222, 179, 250); Sphere brain = new Sphere(null, brainMaterial, 13, new Vector3D(), 1); brain.Transformations.Add(new TScale(65, 85, 85)); headPhantom.Add(brain); headPhantom.Transformations.Add(new TTranslate(100, 0, 0)); s.Add(headPhantom); // Excitation double meshResAir = lambdaMin / 20 / unit; double meshResPhantom = 2.5; LumpedPort lp = new LumpedPort(100, 1, 50.0, new Vector3D(-0.1, -0.1, -meshResPhantom / 2), new Vector3D(+0.1, +0.1, +meshResPhantom / 2), ENormDir.Z, true); s.Add(lp); // Grid RectilinearGrid g = new RectilinearGrid(); g.XLines.Add(0); g.YLines.Add(0); foreach (double z in new double[] { -1.0 / 3, 2.0 / 3 }) { g.ZLines.Add(-dipoleLength / 2 - meshResPhantom * z); g.ZLines.Add(+dipoleLength / 2 + meshResPhantom * z); } foreach (Sphere sp in new Sphere[] { skin, bone, brain }) { g.XLines.Add(sp.AbsoluteTransformation.Matrix[0, 3] + sp.AbsoluteTransformation.Matrix[0, 0]); g.XLines.Add(sp.AbsoluteTransformation.Matrix[0, 3] - sp.AbsoluteTransformation.Matrix[0, 0]); g.YLines.Add(sp.AbsoluteTransformation.Matrix[1, 3] + sp.AbsoluteTransformation.Matrix[1, 1]); g.YLines.Add(sp.AbsoluteTransformation.Matrix[1, 3] - sp.AbsoluteTransformation.Matrix[1, 1]); g.ZLines.Add(sp.AbsoluteTransformation.Matrix[2, 3] + sp.AbsoluteTransformation.Matrix[2, 2]); g.ZLines.Add(sp.AbsoluteTransformation.Matrix[2, 3] - sp.AbsoluteTransformation.Matrix[2, 2]); } g.ZLines.Add(-meshResPhantom / 2); // port g.ZLines.Add(+meshResPhantom / 2); // Mesh over dipole and phantom g.SmoothMesh(meshResPhantom); g.XLines.Add(-200); g.XLines.Add(250 + 100); g.YLines.Add(-250); g.YLines.Add(+250); g.ZLines.Add(-250); g.ZLines.Add(+250); g.SmoothMesh(meshResAir, 1.2); s.Add(new SARBox("SAR", f0, new Vector3D(-10, -100, -100), new Vector3D(180, 100, 100))); s.Add(new NF2FFBox("nf2ff", new Vector3D(g.XLines.First(), g.YLines.First(), g.ZLines.First()), new Vector3D(g.XLines.Last(), g.YLines.Last(), g.ZLines.Last()), lambdaMin / 15 / unit)); g.AddPML(10); g.XLines.Sort(); g.YLines.Sort(); g.ZLines.Sort(); // Export return(new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XComment("Test XML file for CyPhy generated openEMS simulations"), new XElement("openEMS", fdtd.ToXElement(), new XElement("ContinuousStructure", new XAttribute("CoordSystem", 0), s.ToXElement(), g.ToXElement() ) ) )); }
public ScatterableDielectric(Dielectric dielectric, IScatterableComputer computer) { _dielectric = dielectric; _computer = computer; }
public override void Build() { vp = ViewPlane.Create(1024, 768, SystemOfCoordinates.SSC_INT); vp.NumSamples = 16; vp.MaxDepth = 5; backgroundColor = new Vec3(0.5); tracer = new Whitted(this); Ambient a = new Ambient(); a.ScaleRadiance = 0.5f; AmbientLight = a; Pinhole pinhole = new Pinhole(new Vec3(5, 6, 10), new Vec3(0.0, 1.0, 0.0), new Vec3(0.0, 1.0, 0.0), 2000); Camera = pinhole; PointLight light1 = new PointLight(); light1.SetLocation(40, 50, 30); light1.ScaleRadiance = 3.0f; AddLight(light1); Vec3 glassColor = new Vec3(0.65, 1.0, 0.75); Vec3 liquidColor = new Vec3(1.0, 0.25, 1.0); Dielectric glass = new Dielectric(); glass.SetEtaIn(1.50f); glass.SetEtaOut(1.0f); glass.SetCfIn(glassColor); glass.SetCfOut(1, 1, 1); Dielectric liquid = new Dielectric(); liquid.SetEtaIn(1.33f); liquid.SetEtaOut(1.0f); liquid.SetCfIn(liquidColor); liquid.SetCfOut(1, 1, 1); Dielectric dielectric = new Dielectric(); dielectric.SetEtaIn(1.33f); dielectric.SetEtaOut(1.50f); dielectric.SetCfIn(liquidColor); dielectric.SetCfOut(glassColor); //double height = 2.0; //double innerRadius = 0.9; //double wallThickness = 0.1; //double baseThickness = 0.3; //double waterHeight = 1.5; //double meniscusRadius = 0.1; double glassHeight = 2.0; double liquidHeight = 1.5; double innerRadius = 0.991; double outerRadius = 1.0; GlassWithLiquid glassWithLiquid = new GlassWithLiquid(glassHeight, liquidHeight, innerRadius, outerRadius); //GlassWithLiquid glassWithLiquid = new GlassWithLiquid( // height, // innerRadius, // wallThickness, // baseThickness, // waterHeight, // meniscusRadius); glassWithLiquid.SetGlassAirMaterial(glass); glassWithLiquid.SetLiquidAirMaterial(liquid); glassWithLiquid.SetLiquidGlassMaterial(dielectric); AddObject(glassWithLiquid); Matte matte = new Matte(); matte.SetColor(1, 1, 0); matte.SetKa(0.25f); matte.SetKd(0.65f); Instance straw = new Instance(new OpenCylinder(-1.2, 1.7, 0.05)); straw.Material = matte; straw.RotateZ(40); straw.Translate(0, 1.25f, 0); //straw.ComputeBoundingBox(); AddObject(straw); // ground plane Checker3D checker = new Checker3D(); checker.Size = 0.5f; checker.SetColor1(0.75f); checker.SetColor2(1); SV_Matte svMatte = new SV_Matte(); svMatte.SetKa(0.5f); svMatte.SetKd(0.75f); svMatte.SetCd(checker); Plane plane = new Plane(new Vec3(0, -0.01, 0), new Vec3(0, 1, 0)); plane.Material = svMatte; AddObject(plane); }
/// <summary> /// Initializes a new instance of the <see cref="DielectricFactor"/> class. /// </summary> /// <param name="medium">The medium.</param> public DielectricFactor(Dielectric medium) : base(medium) { this.Displacement = 1 / medium.Epsilon; }
public List <IHittable> Generate() { var world = new List <IHittable>(); var checker = new CheckerTexture(new Vec3(0.2, 0.3, 0.1), new Vec3(0.9, 0.9, 0.9)); var groundMat = new Lambertian(checker); world.Add(new Sphere { Center = new Vec3(0, -1000, 0), Radius = 1000, Material = groundMat }); var earthTex = new ImageTexture("../../Data/earthmap.jpg"); var earthMat = new Lambertian(earthTex); for (var a = -11; a < 11; a++) { for (var b = -11; b < 11; b++) { var chooseMat = MathUtils.RandDouble(); var radius = MathUtils.RandDouble(0.2, 0.3); var offset = 1.0 - (radius / 2); var center = new Vec3( a + offset * MathUtils.RandDouble(), radius, b + offset * MathUtils.RandDouble()); if ((center - new Vec3(4, radius, 0)).Length <= 0.9) { continue; } if (chooseMat < 0.05) { var albedo = Vec3.Random() * Vec3.Random() * 10; var mat = new DiffuseLight(albedo); world.Add(new Sphere { Center = center, Material = mat, Radius = radius }); } if (chooseMat < 0.2) { var albedo = Vec3.Random() * Vec3.Random(); var mat = new Lambertian(albedo); var c2 = center + new Vec3(0, MathUtils.RandDouble(0, 0.2), 0); world.Add(new MovingSphere { Center0 = center, Center1 = c2, Radius = radius, Time0 = 0, Time1 = 1, Material = mat }); } else if (chooseMat < 0.4) { world.Add(new Sphere { Center = center, Radius = radius, Material = earthMat }); } else if (chooseMat < 0.6) { var color1 = Vec3.Random() * Vec3.Random(); var color2 = Vec3.One - color1; var scale = MathUtils.RandomInt(3, 10); var mat = new Lambertian(new NoiseTexture(color1, color2, scale)); world.Add(new Sphere { Center = center, Radius = radius, Material = mat }); } else if (chooseMat < 0.8) { var albedo = Vec3.Random(0.5, 1); var fuzz = MathUtils.RandDouble(0, 0.5); var mat = new Metal { Albedo = albedo, Fuzz = fuzz }; world.Add(new Sphere { Center = center, Radius = radius, Material = mat }); } else { var mat = new Dielectric { RefractionIndex = 1.5 }; world.Add(new Sphere { Center = center, Radius = radius, Material = mat }); } } } var mat1 = new Dielectric { RefractionIndex = 1.5 }; var mat2 = new Lambertian(new Vec3(0.4, 0.2, 0.1)); var mat3 = new Metal { Albedo = new Vec3(0.7, 0.6, 0.5), Fuzz = 0.0 }; world.Add(new Sphere { Center = new Vec3(0, 1, 0), Radius = 1.0, Material = mat1 }); world.Add(new Sphere { Center = new Vec3(-4, 1, 0), Radius = 1, Material = mat2 }); world.Add(new Sphere { Center = new Vec3(4, 1, 0), Radius = 1.0, Material = mat3 }); return(world); }