-1

I have some sources with coordinates (xn, yn, zn) w.r.t a center C of a ring and unit vectors (ns_ux, ns_uy, ns_uz) along my line of sight. I want to calculate whether these sources pass through a cylinder of inner and outer radius 9.5 and 10.5 units, respectively. If they intersect this cylinder (or I call it ring, sometimes), then I would like to calculate the length of this intercept. My position is outside of this ring and there are sources which lie beyond the center C on the other side. These sources, therefore will pass through this ring twice. This picture should help visualize this problem. enter image description here

#define PI 3.142    
int main(){
int k,number=200;
float r_min=9.50000;
float r_max=10.500000;
float step=0.3;
float  z_c = 3.0;
float ns_ux[number],ns_uy[number],ns_uz[number],xn[number], yn[number],zn[number],l[number],b[number],ns[number],x_comp,y_comp,z_comp,radial;

FILE* val= NULL;
val=fopen("novae_uniform_unitvectors.txt", "r");
for(k=0;k<=(number-1);k++){
    fscanf(val,"%f %f %f %f %f %f %f %f %f", &xn[k], &yn[k], &zn[k], &ns_ux[k], &ns_uy[k], &ns_uz[k], &l[k], &b[k], &ns[k]);
    float u=0.;
for (u=0.;u<=30.;u=u+step){

        x_comp=xn[k]+u*ns_ux[k]; 

vector addition : calculating the x_comp w.r.t the center C when stepped by 'u' units along my l.o.s.

        y_comp=yn[k]+u*ns_uy[k];
        radial=pow((x_comp*x_comp+y_comp*y_comp),0.5);

        if (radial >=r_min && radial <=r_max){
            z_comp=zn[k]+u*ns_uz[k];

checking if the height is consistent with the ring's height

            if(z_comp >=-z_c && z_comp <= z_c)
        printf("%f\t%f\t%f\t%f\n",l[k],u, z_comp, radial);
     }
     }
     }
     return 0.;
     }

This 'radial' values gives me a list of points where my line of sight intersects with the ring. But, I require only the end points to calculate the length of the intercept on the ring. e.g. in the case listed below, my l.o.s. passes through the ring at I and then comes off at II. Then it keeps going until it hits the ring again at III and then come out of it at IV. I need to store only I, II , III and IV points in my file. How would I be able to do it ?

longitude..........u........ z_comp........radial

121.890999 0.100000 0.016025 9.561846 I

121.890999 0.200000 0.038453 9.538050

121.890999 0.300000 0.060881 9.515191 II

121.890999 4.799998 1.070159 9.518372 III

121.890999 4.899998 1.092587 9.541364

121.890999 4.999998 1.115016 9.565292

...... skipping to save space........

121.890999 7.399995 1.653297 10.400277

121.890999 7.499995 1.675725 10.444989

121.890999 7.599995 1.698153 10.490416 IV

caveman
  • 1,755
  • 1
  • 14
  • 19
akaur
  • 389
  • 1
  • 6
  • 22
  • Here is the link to a pictorial representation : http://postimg.org/image/wu40cg5ur/ – akaur Apr 13 '15 at 05:14
  • You have obviously put effort in to trying to explain your problem, and I commend you for that, but unfortunately, even with the image, what you are describing is not entirely clear. You describe a cylinder, but from your image, it is hard to tell whether the origin of the 9.5 and 10.5 radials are concentric with the ring and whether the ring itself is the cylinder you describe. Do your line-of-sight unit vectors with respect to positions 1,2,3,4... lie above, below the plane of the ring, etc. This makes it hard to tell whether this is a point from/within a plane problem, etc.. Try again? – David C. Rankin Apr 13 '15 at 06:05
  • The 9.5 and 10.5 are concentric with the ring. This ring is basically a hollow cylinder with inner and outer radii 9.5 and 10.5 and a given height. The line of sight unit vectors are 3 dimensional in nature. The idea is : Firstly, i am checking only the radial component of my line of sight to intersect the ring anywhere in between 9.5 and 10.5. Then, I am calculating the height (z_comp) at that particular step and check if it is over the height (z_c) of the ring or not. The example (data) above shows the case, where it goes twice through the ring. I hope it makes sense ? – akaur Apr 13 '15 at 06:14
  • Is the axial direction of the cylinder collinear with one of the Cartesian axes, e.g. z? – M Oehm Apr 13 '15 at 06:23
  • yes, it is collinear with z. – akaur Apr 18 '15 at 17:18

1 Answers1

0

Figured out a way to store only the final and initial values by using a boolean operator as follows (continued from the code in the question) :

define bool change = true;
...(rest of the program)...
if(radial >= r_min && radial <= r_max) {
    z_comp = zn[k] + u * ns_uz[k];

    if (z_comp >= -z_c && z_comp <= z_c)

        if (change) {
        printf("%f\t%f\t%f\t%f\t", l[k], b[k], ns[k], radial[i]);
        change = !change;
    }
} else { // if the condition of radial and z_comp is not met 
    if (!change) {
        fprintf(fp, "%f\n", radial[i - 1]);
        change = !change;
    }
}

This would store only the first and the last values of the radial component (i.e. the end points of the intercept of the line of sight vector on the ring)

Sushil
  • 2,837
  • 4
  • 21
  • 29
akaur
  • 389
  • 1
  • 6
  • 22