Skip to content

Commit dbad863

Browse files
committed
Some fixes in depth calculation of bar surfaces
1 parent c568fc9 commit dbad863

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

js/src/graph3d/graph3d.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,25 +1848,17 @@ links.Graph3d.prototype._redrawDataBar = function() {
18481848

18491849
// create five sides, calculate both corner points and center points
18501850
var surfaces = [
1851-
{corners: top},
1852-
{corners: [top[0], top[1], bottom[1], bottom[0]]},
1853-
{corners: [top[1], top[2], bottom[2], bottom[1]]},
1854-
{corners: [top[2], top[3], bottom[3], bottom[2]]},
1855-
{corners: [top[3], top[0], bottom[0], bottom[3]]}
1851+
{corners: top, center: links.Point3d.avg(bottom[0].point, bottom[2].point)},
1852+
{corners: [top[0], top[1], bottom[1], bottom[0]], center: links.Point3d.avg(bottom[1].point, bottom[0].point)},
1853+
{corners: [top[1], top[2], bottom[2], bottom[1]], center: links.Point3d.avg(bottom[2].point, bottom[1].point)},
1854+
{corners: [top[2], top[3], bottom[3], bottom[2]], center: links.Point3d.avg(bottom[3].point, bottom[2].point)},
1855+
{corners: [top[3], top[0], bottom[0], bottom[3]], center: links.Point3d.avg(bottom[0].point, bottom[3].point)}
18561856
];
18571857

1858-
// calculate center points of each of the surfaces
1859-
// use this to calculate the distance of this point to camera
1858+
// calculate the distance of each of the surface centers to the camera
18601859
for (j = 0; j < surfaces.length; j++) {
18611860
surface = surfaces[j];
1862-
corners = surface.corners;
1863-
1864-
var center = new links.Point3d(
1865-
(corners[0].point.x + corners[1].point.x + corners[2].point.x + corners[3].point.x) / 4,
1866-
(corners[0].point.y + corners[1].point.y + corners[2].point.y + corners[3].point.y) / 4,
1867-
(corners[0].point.z + corners[1].point.z + corners[2].point.z + corners[3].point.z) / 4
1868-
);
1869-
var transCenter = this._convertPointToTranslation(center);
1861+
var transCenter = this._convertPointToTranslation(surface.center);
18701862
surface.dist = this.showPerspective ? transCenter.length() : -transCenter.z;
18711863
}
18721864

@@ -2165,7 +2157,21 @@ links.Point3d.add = function(a, b) {
21652157
};
21662158

21672159
/**
2168-
* Calculate the cross producto of the two provided points, returns axb
2160+
* Calculate the average of two 3d points
2161+
* @param {links.Point3d} a
2162+
* @param {links.Point3d} b
2163+
* @return {links.Point3d} The average, (a+b)/2
2164+
*/
2165+
links.Point3d.avg = function(a, b) {
2166+
return new links.Point3d(
2167+
(a.x + b.x) / 2,
2168+
(a.y + b.y) / 2,
2169+
(a.z + b.z) / 2
2170+
);
2171+
};
2172+
2173+
/**
2174+
* Calculate the cross product of the two provided points, returns axb
21692175
* Documentation: http://en.wikipedia.org/wiki/Cross_product
21702176
* @param {links.Point3d} a
21712177
* @param {links.Point3d} b

js/src/graph3d/playground/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ <h2>Options</h2>
234234
<tr><td>valueMin</td><td><input type="text" id="valueMin" /></td></tr>
235235
<tr><td>valueMax</td><td><input type="text" id="valueMax" /></td></tr>
236236

237-
<tr><td>barWidth</td><td><input type="text" id="barWidth" /></td></tr>
237+
<tr><td>xBarWidth</td><td><input type="text" id="xBarWidth" /></td></tr>
238+
<tr><td>yBarWidth</td><td><input type="text" id="yBarWidth" /></td></tr>
238239

239240
</table>
240241

js/src/graph3d/playground/playground.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,8 @@ function getOptions() {
519519
valueMin: Number(document.getElementById("valueMin").value) || undefined,
520520
valueMax: Number(document.getElementById("valueMax").value) || undefined,
521521

522-
barWidth: Number(document.getElementById("barWidth").value) || undefined
522+
xBarWidth: Number(document.getElementById("xBarWidth").value) || undefined,
523+
yBarWidth: Number(document.getElementById("yBarWidth").value) || undefined
523524
};
524525
}
525526

@@ -638,7 +639,7 @@ function drawDatasource() {
638639

639640
// Draw our graph with the created data and options
640641
graph.draw(data, options);
641-
}
642+
};
642643

643644
url = document.getElementById("datasourceText").value;
644645
document.getElementById("draw").disabled = "disabled";

0 commit comments

Comments
 (0)