If you were on side of cones, we could catch you.
Actually, we try to catch spreading particles in the space.
vUtil.cpp Wed Jun 09 18:57:02 2021 1 :#include2 : 3 :#include "vPoint.h" 4 :#include "vLine.h" 5 :#include "vTriangle.h" 6 :#include "vCalculation.h" 7 :#include "vIntersection.h" 8 : 9 :#include "vScreen.h" 10 :#include "vUtil.h" 11 : 12 ://triangular pyramid, trigonal pyramid 13 :int vUtil::OnSideCones ( vPoint* p, vPoint* eye, vPoint** a, int n) { 14 : vTriangle tri; 15 : vIntersection inter; 16 : vCalculation calc; 17 : vPoint ray; 18 : 19 : // Create Triangle in Local memories. 20 : tri.p1.setPoint( a[0]->x, a[0]->y , a[0]->z ); 21 : tri.p2.setPoint( a[1]->x, a[1]->y, a[1]->z ); 22 : tri.p3.setPoint( a[2]->x, a[2]->y, a[2]->z ); 23 : 24 : int aa = calc.subtract( p, eye, &ray); 25 : 26 : // vPoint* vIntersection::Intersect ( vTriangle tri, vPoint eye, vPoint ray ) 27 : double depth = inter.Depth( tri, *eye, ray); 28 : if ( depth < 0.0 ) { 29 : return -1; 30 : } 31 : 32 : return 1; 33 :} 34 : 35 :
.\vIntersection.cpp Wed Jun 09 19:02:10 2021 40 :// 20210609 41 :double vIntersection::Depth ( vTriangle tri, vPoint eye, vPoint ray ) { 42 : 43 : printf("vPoint* vIntersection::Intersect ( vTriangle tri, vPoint eye, vPoint ray ) starts.\r\n"); 44 : 45 : vCalculation *cal = nullptr; 46 : 47 : cal = new vCalculation (); 48 : 49 : printf("eye= "); 50 : eye.print(); 51 : printf("ray= "); 52 : ray.print(); 53 : 54 : vPoint* n = tri.getNormal (); 55 : double d = -n->x*tri.p1.x - n->y*tri.p1.y - n->z * tri.p1.z; 56 : double depth = ( -d - n->x*eye.x - n->y*eye.y - n->z*eye.z ) / ( n->x*ray.x + n->y*ray.y + n->z*ray.z ); 57 : 58 : printf("depth=%f\r\n", depth); 59 : 60 : delete( cal ); 61 : 62 : printf("vPoint* vIntersection::Depth ( vTriangle tri, vPoint eye, vPoint ray ) ends.\r\n"); 63 : return depth; 64 :} 65 :
.\vUtil.cpp Thu Jun 10 19:03:18 2021 ... 37 ://triangular pyramid, trigonal pyramid 38 :int vUtil::InsideCones ( vPoint* p, vPoint* eye, vPoint** a, int n) { 39 : vTriangle tri; 40 : vIntersection inter; 41 : vCalculation calc; 42 : vPoint ray; 43 : vPoint* b[3]; 44 : 45 : b[0] = eye; 46 : for ( int i=0; i<4; i++ ) { 47 : b[1] = a[i]; 48 : b[2] = a[ ( i + 1 ) % 4] ; 49 : if ( this->OnSideCones( p, eye, b, 3 ) == -1 ) return -1; 50 : } 51 : 52 : return 1; 53 :} 54 :
.\vUtil.cpp Fri Jun 11 16:52:48 2021 55 ://https://stackoverflow.com/questions/13408990/how-to-generate-random-float-number-in-c 56 ://https://www.tutorialspoint.com/how-do-i-generate-random-floats-in-cplusplus#:~:text=In%20C%20or%20C%2B%2B%2C%20we%20cannot%20create%20random,result%20with%20some%20floating%20point%20constant%20like%200.5. 57 :int vUtil::SpreadSeed ( vPoint* from, vPoint* to, vPoint** seed, int* n) { 58 : float x, y, z; 59 : 60 : if ( *n == 0 ) { 61 : *n = 10; 62 : } 63 : 64 : srand((unsigned int)time(NULL)); 65 : float ax = to->x - from->x; 66 : float ay = to->y - from->y; 67 : float az = to->z - from->z; 68 : 69 : seed = (vPoint**) malloc ( *n * sizeof(vPoint*) ); 70 : if ( sizeof(seed) != *n ) return -1; 71 : 72 : for ( int i=0; i<*n; i++ ) { 73 : x = ( ((float)rand()/(float)(RAND_MAX)) * ax); 74 : y = ( ((float)rand()/(float)(RAND_MAX)) * ay); 75 : z = ( ((float)rand()/(float)(RAND_MAX)) * az); 76 : seed[i] = memorizevPoint ( x, y, z ); 77 : } 78 : 79 : return 1; 80 :} 81 : .\display_threeD.cpp Fri Jun 11 15:08:47 2021 179 :// 180 :int spreading_particles_initialize () { 181 : vUtil autil; 182 : vPoint* from = new vPoint ( 0.0f, 0.0f, 0.0f ); 183 : vPoint* to = new vPoint ( 100.0f, 100.0f, 100.0f ); 184 : vPoint** seed = nullptr; 185 : 186 : int number = 50; 187 : int a = autil.SpreadSeed( from, to, seed, &number); 188 : 189 : return 0; 190 :} 191 :