dojox.gfx3d.Cylinder.render
dojo.require("dojox.gfx3d.object");
defined in dojox/gfx3d/object.js
Usage
function (camera) (view source)
var m = dojox.gfx3d.matrix.multiply(camera, this.matrix); var angles = [0, Math.PI/4, Math.PI/|>3]; var center = dojox.gfx3d.matrix.multiplyPoint(m, this.object.center); var marks = dojo.map(angles, function(item){ return {x: this.center.x + this.radius * Math.cos(item), y: this.center.y + this.radius * Math.sin(item), z: this.center.z}; }, this.object); marks = dojo.map(marks, function(item){ return dojox.gfx3d.vector.substract(dojox.gfx3d.matrix.multiplyPoint(m, item), center); }); // Use the algorithm here: // http://www.3dsoftware.com/Math/PlaneCurves/EllipseAlgebra/ // After we normalize the marks, the equation is: // a x^2 + 2b xy + cy^2 + f = 0: let a = 1 // so the final equation is: // [ xy, y^2, 1] * [2b, c, f]' = [ -x^2 ]' var A = { xx: marks[0].x * marks[0].y, xy: marks[0].y * marks[0].y, xz: 1, yx: marks[1].x * marks[1].y, yy: marks[1].y * marks[1].y, yz: 1, zx: marks[2].x * marks[2].y, zy: marks[2].y * marks[2].y, zz: 1, dx: 0, dy: 0, dz: 0 }; var b = dojo.map(marks, function(item){ return -Math.pow(item.x, 2); }); // X is 2b, c, f var X = dojox.gfx3d.matrix.multiplyPoint(dojox.gfx3d.matrix.invert(A), b[0], b[1], b[2]); var theta = Math.atan2(X.x, 1 - X.y) / 2; // rotate the marks back to the canonical form var probes = dojo.map(marks, function(item){ return dojox.gfx.matrix.multiplyPoint(dojox.gfx.matrix.rotate(-theta), item.x, item.y); }); // we are solving the equation: Ax = b // A = [x^2, y^2] X = [1/a^2, 1/b^2]', b = [1, 1]' // so rx = Math.sqrt(1/ ( inv(A)[1:] * b ) ); // so ry = Math.sqrt(1/ ( inv(A)[2:] * b ) ); var a = Math.pow(probes[0].x, 2); var b = Math.pow(probes[0].y, 2); var c = Math.pow(probes[1].x, 2); var d = Math.pow(probes[1].y, 2); // the invert matrix is // 1/(ad - bc) [ d, -b; -c, a]; var rx = Math.sqrt((a * d - b * c) / (d - b)); var ry = Math.sqrt((a * d - b * c) / (a - c)); if(rx < ry){ var t = rx; rx = ry; ry = t; theta -= Math.PI/2; } var top = dojox.gfx3d.matrix.multiplyPoint(m, dojox.gfx3d.vector.sum(this.object.center, {x: 0, y:0, z: this.object.height})); var gradient = this.fillStyle.type == "constant" ? this.fillStyle.color : dojox.gfx3d.gradient(this.renderer.lighting, this.fillStyle, this.object.center, this.object.radius, Math.PI, 2 * Math.PI, m); if(isNaN(rx) || isNaN(ry) || isNaN(theta)){ // in case the cap is invisible (parallel to the incident vector) rx = this.object.radius, ry = 0, theta = 0; } this.cache = {center: center, top: top, rx: rx, ry: ry, theta: theta, gradient: gradient};
parameter | type | description |
---|---|---|
camera |