⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tetra.c

📁 su 的源代码库
💻 C
字号:
/* Copyright (c) Colorado School of Mines, 2006.*//* All rights reserved.                       *//*********************** self documentation **********************//**********************************************************************Tetra - Tetrahedra subroutinestetra_volume - find volume of tetrahedra give 4 pointsarea3d - find area of a triangle in 3D defined by 3 points***********************************************************************Function Prototypes:float tetra_volume(float x0[3], float x1[3], float x2[3], float x3[3]);float area3d( float x0[3], float x1[3], float x2[3]);***********************************************************************tetra_volume:Input:x0[3]	x,y,z of 1st pointx1[3]	x,y,z of 2nd pointx2[3]	x,y,z of 3rd pointx3[3]	x,y,z of 4th pointReturns:  tetrahedra volumearea_3d:Input:x0[3]		x,y,z of 1st pointx1[3]		x,y,z of 2nd pointx2[3]		x,y,z of 3rd pointReturns:***********************************************************************Notes:tetra_volume:The formula:                | x0[0]   x0[1]   x0[2]   1 |                | x1[0]   x1[1]   x1[2]   1 |           v =  | x2[0]   x2[1]   x2[2]   1 | / 6;                | x3[0]   x3[1]   x3[2]   1 |area3d:***********************************************************************References:***********************************************************************Author: CWP: Zhaobo Meng, October 1997***********************************************************************//**************** end self doc ********************************/#include "tetra.h"float tetra_volume(float x0[3], float x1[3], float x2[3], float x3[3])/**********************************************************************tetra_volume - find volume of tetrahedra give 4 points***********************************************************************Function Prototype:float tetra_volume(float x0[3], float x1[3], float x2[3], float x3[3]);***********************************************************************Input:x0[3]	x,y,z of 1st pointx1[3]	x,y,z of 2nd pointx2[3]	x,y,z of 3rd pointx3[3]	x,y,z of 4th pointReturns:  tetrahedra volume***********************************************************************Notes:The formula:                | x0[0]   x0[1]   x0[2]   1 |                | x1[0]   x1[1]   x1[2]   1 |           v =  | x2[0]   x2[1]   x2[2]   1 | / 6;                | x3[0]   x3[1]   x3[2]   1 |***********************************************************************Author: CWP: Zhaobo Meng, October 1997***********************************************************************/{      float vv;      vv=-( x1[0]*(x2[1]*x3[2]-x2[2]*x3[1])           -x1[1]*(x2[0]*x3[2]-x2[2]*x3[0])           +x1[2]*(x2[0]*x3[1]-x3[0]*x2[1]));      vv+=  x0[0]*(x2[1]*x3[2]-x2[2]*x3[1])           -x0[1]*(x2[0]*x3[2]-x2[2]*x3[0])           +x0[2]*(x2[0]*x3[1]-x3[0]*x2[1]);      vv-=  x0[0]*(x1[1]*x3[2]-x1[2]*x3[1])           -x0[1]*(x1[0]*x3[2]-x1[2]*x3[0])           +x0[2]*(x1[0]*x3[1]-x3[0]*x1[1]);      vv+= x0[0]*(x1[1]*x2[2]-x1[2]*x2[1])           -x0[1]*(x1[0]*x2[2]-x1[2]*x2[0])           +x0[2]*(x1[0]*x2[1]-x2[0]*x1[1]);      vv=ABS(vv)/6.0;      return vv;}float area3d( float x0[3], float x1[3], float x2[3])/***********************************************************************area3d - area of a triangle in 3D defined by 3 points************************************************************************Function Prototype:float area3d( float x0[3], float x1[3], float x2[3]);************************************************************************Input:x0[3]		x,y,z of 1st pointx1[3]		x,y,z of 2nd pointx2[3]		x,y,z of 3rd pointReturns:	area of triangle************************************************************************Notes:************************************************************************References:************************************************************************Author: CWP: Zhaobo Meng  October 1997***********************************************************************/{      float d1,d2,d3;      d1=sqrt((x0[0]-x1[0])*(x0[0]-x1[0])+              (x0[1]-x1[1])*(x0[1]-x1[1])+              (x0[2]-x1[2])*(x0[2]-x1[2]));      d2=sqrt((x0[0]-x2[0])*(x0[0]-x2[0])+              (x0[1]-x2[1])*(x0[1]-x2[1])+              (x0[2]-x2[2])*(x0[2]-x2[2]));      d3=sqrt((x1[0]-x2[0])*(x1[0]-x2[0])+              (x1[1]-x2[1])*(x1[1]-x2[1])+              (x1[2]-x2[2])*(x1[2]-x2[2]));      return sqrt((d1+d2+d3)*(d2+d3)*(d1+d3)*(d1+d2))/12.0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -