private void getX3DBaseProperties(ShadowObject3d so3d, XElement xel) { so3d.arguments.Add("x3d_fill_emissive_color_html", this.X.getXNullString(xel, "X3DEmissiveColor")); so3d.arguments.Add("x3d_fill_diffuse_color_html", this.X.getXNullString(xel, "X3DDiffuseColor")); so3d.arguments.Add("x3d_fill_bitmap", this.X.getXNullString(xel, "X3DFillBitmap")); so3d.arguments.Add("x3d_fill_both_sides", this.X.getXNullBool(xel, "X3DFillBothSides", null)); so3d.arguments.Add("x3d_fill_normal", this.X.getXVectorByName(xel, "X3DFillNormal", null)); //OBSOLETE properties, replaced by introducing two colours to be set (or not for gridlines) // so3d.arguments.Add("x3d_fill", this.X.getXNullBool(xel, "X3DFill", null)); // so3d.arguments.Add("x3d_fill_diffuse", this.X.getXNullBool(xel, "X3DFillDiffuse", null)); }
/* TRIANGULARPRISM ***************************/ //supportive methods on TriangularPrism creation private bool triangularPrismHasVolume(ShadowObject3d sho3d) { Scientrace.Vector length = sho3d.getVector("length"); Scientrace.Vector width = sho3d.getVector("width"); Scientrace.Vector height = sho3d.getVector("height"); //as angle doesn't have to be provided when height is provided directly use angle default 1. double angle = sho3d.getDouble("angle", 1); if (angle * length.length * width.length * height.length == 0) { Console.WriteLine("WARNING: TriangularPrism " + sho3d.tag + " has no volume and will " + "therefor not be created."); return(false); } return(true); }
private Scientrace.NonzeroVector calcTriangleHeightVector(ShadowObject3d sho3d) { Scientrace.Vector length = sho3d.getVector("length"); Scientrace.Vector width = sho3d.getVector("width"); Scientrace.Vector heightdir = sho3d.getVector("heightdir"); double angle = sho3d.getDouble("angle"); //create a vector orthogonal to length en width in the same binary direction as heightdir. Scientrace.UnitVector owl = (width.crossProduct(length) * Math.Sign(width.crossProduct(length).dotProduct(heightdir))).tryToUnitVector(); Scientrace.NonzeroVector bdir = ( //calculate the direction of the short side of the prism owl * Math.Sin(angle) + width.tryToUnitVector() * Math.Cos(angle) ).tryToNonzeroVector(); if ((bdir.length < 0.99999) || (bdir.length > 1.00001)) { throw new ArgumentOutOfRangeException("bdir.length", bdir.length, "!= 1"); } Scientrace.VectorTransform trf = new Scientrace.VectorTransform( width.tryToNonzeroVector(), owl.tryToNonzeroVector(), length.tryToNonzeroVector()); Scientrace.NonzeroVector hdirtrf = trf.transform(heightdir).tryToNonzeroVector(); Scientrace.Vector hprimetrf = new Scientrace.Vector(hdirtrf.x, hdirtrf.y, 0); //eliminate "length" component of heightdir in hprime //Console.WriteLine("HPRIMTRF:"+hprimetrf.trico()); Scientrace.NonzeroVector hprimedir = trf.transformback(hprimetrf).tryToNonzeroVector().normalized(); /* ^ * /C\ * / \ * h'/ \ b * / \ * /B_______A\ * width * angle = A; beta = B; gamma = C. */ //sine rule: hprimelen / sin A = width.length() / sin C = blen / sin B double beta, gamma; beta = Math.Acos(hprimedir.normalized().dotProduct(width.tryToNonzeroVector().normalized())); gamma = Math.PI - (angle + beta); double hprimelen; double sinruleconstant = width.length / Math.Sin(gamma); hprimelen = sinruleconstant * Math.Sin(angle); Scientrace.NonzeroVector hprime = hprimedir * hprimelen; // check: (trf.transform(hprime).x / hdirtrf.x) == (trf.transform(hprime).y / hdirtrf.y) double xycoeff = ((trf.transform(hprime).x / hdirtrf.x) / (trf.transform(hprime).y / hdirtrf.y)); if (Math.Abs(1 - xycoeff) > 0.00001) //doesn't do anything if .x/.x = NaN, but that's OK for now. { throw new ArgumentOutOfRangeException("xycoeff", xycoeff, "!=1"); } try { Scientrace.NonzeroVector h = ((Math.Abs(hdirtrf.x) > Math.Abs(hdirtrf.y)) ? // Preventing .x or .y denominator == 0 errors. trf.transformback(hdirtrf * (trf.transform(hprime).x / hdirtrf.x)) : trf.transformback(hdirtrf * (trf.transform(hprime).y / hdirtrf.y)) ).tryToNonzeroVector(); return(h); } catch (Scientrace.ZeroNonzeroVectorException zne) { Console.WriteLine("ERROR: calculated height for triangularprism has length zero!"); throw (zne); } } //end calcTriangleHeightVector