Calculate superficial area and volume of mesh with Three.js(WebGL)
2016-10-21 16:28
441 查看
//Created by Ken on Oct 20,2016 for volume compute when upload function SignedVolumeOfTriangle(p1, p2, p3) { var v321 = p3.X*p2.Y*p1.Z; var v231 = p2.X*p3.Y*p1.Z; var v312 = p3.X*p1.Y*p2.Z; var v132 = p1.X*p3.Y*p2.Z; var v213 = p2.X*p1.Y*p3.Z; var v123 = p1.X*p2.Y*p3.Z; var singnedVolume=(1/6)*(-v321 + v231 + v312 - v132 - v213 + v123); return singnedVolume; } function VolumeOfMesh(points) { var i= 0,vols=0; var P1,P2,P3; do { P1={X:points[i],Y:points[i+1],Z:points[i+2]}; P2={X:points[i+3],Y:points[i+4],Z:points[i+5]}; P3={X:points[i+6],Y:points[i+7],Z:points[i+8]}; vols+=SignedVolumeOfTriangle(P1, P2, P3); i+=9; } while (i<points.length); return customRound(Math.abs(vols)/1000,2); } function customRound(number,fractiondigits){ with(Math){ return round(number*pow(10,fractiondigits))/pow(10,fractiondigits); } } function SuperficialAreaOfMesh(points) { var _len =points.length, _area = 0.0; if (!_len) return 0.0; var i= 0,vols=0; var va,vb,vc; do { va={X:points[i],Y:points[i+1],Z:points[i+2]}; vb={X:points[i+3],Y:points[i+4],Z:points[i+5]}; vc={X:points[i+6],Y:points[i+7],Z:points[i+8]}; var ab = {X:vb.X-va.X,Y:vb.Y-va.Y,Z:vb.Z-va.Z}; //vb.clone().sub(va); var ac = {X:vc.X-va.X,Y:vc.Y-va.Y,Z:va.Z-vc.Z}; //vc.clone().sub(va); var cross = new THREE.Vector3(); cross=crossVectors( ab, ac ); _area += Math.sqrt(Math.pow(cross.X,2)+Math.pow(cross.Y,2)+Math.pow(cross.Z,2))/2; i+=9; } while (i<points.length); return customRound(Math.abs(_area)/100,2); } function crossVectors( a, b ) { var ax = a.X, ay = a.Y, az = a.Z; var bx = b.X, by = b.Y, bz = b.Z; var P={X:ay * bz - az * by, Y:az * bx - ax * bz, Z:ax * by - ay * bx} return P; }
相关文章推荐
- 检测使用 three.js 时的 WebGL 和浏览器兼容性(Detecting WebGL and browser compatibility with three.js)(转)
- Threejs 官网 - 检测使用 three.js 时的 WebGL 和浏览器兼容性(Detecting WebGL and browser compatibility with three.js)
- Volume of Mesh Calculation With WebGL
- Convert a model from Maya to WebGL for use with THREE.js
- How to load 3d model from different domain and display it with Three.js
- [Recompose] Compose Streams of React Props with Recompose’s compose and RxJS
- WebGL With Three.js – Lesson 6(转)
- (WebGL) Max to Three.js workflow tips and tricks
- Area of Triangles and Polygons (2D)
- Test-Driven C#: Improve the Design and Flexibility of Your Project with Extreme Programming Techniques
- Teddy's Aspect Weaver Version 0.3 with Great Updating and Fixing, Especially the Implementing of Getting Runtime Method Context
- A Taste of AOP from Solving Problems with OOP and Design Patterns (Part I)
- Three TFS cool things: a tool for TFS Integration with Project and two TFS guides
- Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers
- Blending of images, raster operations and basic color adjustments with GDI+
- A Taste of AOP from Solving Problems with OOP and Design Patterns (Part I) zz
- 【MSDN文摘】Building Windows Forms Controls and Components with Rich Design-Time Features, Part 2 of 2
- Allow user to scroll and maintain position with "Scroll To Bottom of the Div" example
- A Taste of AOP from Solving Problems with OOP and Design Patterns (Part II)
- A Taste of AOP from Solving Problems with OOP and Design Patterns (Part II) zz