@@ -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
0 commit comments