## FORTRAN check particle distance to centre of an object.

## FORTRAN check particle distance to centre of an object.

(OP)

Hi,

I am quite new to FORTRAN and am currently making programs to gain an understanding of it.

I have made a program in FORTRAN 90, this spawns particles in which then land on a plane. What I would like to do is to check to see if any of the particles are within any cylinders in a line. If they are then I would like to keep them, if not then I would like them to be deleted.

I have thought about how this could be achieved. I have the centre points of the cylinder and the radius (ie. xyz for centre of the top and xyz for centre of the bottom, and a radius value). I thought that the centre of the particle with the radius could be compared with each co-ordinate of the centre point through the cylinder, and then to see if it is within the radius of that point, thus within the cylinder.

Please could you point me in the direction of a tutorial which teaches how to code this, or give me some guidance of how I can achieve this?

Thank you for your time, I really appreciate it.

I am quite new to FORTRAN and am currently making programs to gain an understanding of it.

I have made a program in FORTRAN 90, this spawns particles in which then land on a plane. What I would like to do is to check to see if any of the particles are within any cylinders in a line. If they are then I would like to keep them, if not then I would like them to be deleted.

I have thought about how this could be achieved. I have the centre points of the cylinder and the radius (ie. xyz for centre of the top and xyz for centre of the bottom, and a radius value). I thought that the centre of the particle with the radius could be compared with each co-ordinate of the centre point through the cylinder, and then to see if it is within the radius of that point, thus within the cylinder.

Please could you point me in the direction of a tutorial which teaches how to code this, or give me some guidance of how I can achieve this?

Thank you for your time, I really appreciate it.

## RE: FORTRAN check particle distance to centre of an object.

I have 3 co-ordinates for the top and base of the cylinder, such that the base is 1.00, 1.00, 1.00 and the top is 1.00, 3.00, 1.00, with a radius of 1.00

The generated particles have a co-ordinate for the centre as well as a radius value.

For the Y co-ordinate (yP(i)) it would be:

IF (yP(i) > 1.00 .and. yP(i) < 3.00) THEN

!Test the x and z values (with radius?) to work out if they are in a cylinder

IF ((xP(i)+r(i))) THEN

ELSE DELETE Particle (if not within the x or z range)

ElSE DELETE Particle (If not within the y range)

I have also come into a problem that if it is within a 1.00 radius of the x, then it is fine, and the same for z. But if taken in conjunction they will form a square and be wrongly accepted. What could I do to overcome this? Would an IF ((xP(i)+r(i))) AND IF ((zP(i)+r(i))) THEN (keep particle) work?

If anyone has a more elegant way to write this please let me know, or a better way rather than the convoluted route I am taking.

Many thanks.

## RE: FORTRAN check particle distance to centre of an object.

TTFN

FAQ731-376: Eng-Tips.com Forum Policies

Need help writing a question or understanding a reply? forum1529: Translation Assistance for Engineers

## RE: FORTRAN check particle distance to centre of an object.

IF ((((xP(i)-cylinder_x)**2)+((zP(i)-cylinder_z)**2)) < (cylinder_radius**2)) THEN

what are your thoughts?

## RE: FORTRAN check particle distance to centre of an object.

TTFN

FAQ731-376: Eng-Tips.com Forum Policies

Need help writing a question or understanding a reply? forum1529: Translation Assistance for Engineers

## RE: FORTRAN check particle distance to centre of an object.

This is going to sound like a really silly question. I have the statements to define if a particle is in the cylinder, how would I code to store the particle co-ordinates within the cylinder, and delete the particle if it is outside?

Many thanks,

## RE: FORTRAN check particle distance to centre of an object.

TTFN

FAQ731-376: Eng-Tips.com Forum Policies

Need help writing a question or understanding a reply? forum1529: Translation Assistance for Engineers

## RE: FORTRAN check particle distance to centre of an object.

## RE: FORTRAN check particle distance to centre of an object.

Just checking simple distance formula's won't do the trick.... not even close!

If your starting goal is to learn fortran, you might experiment with less difficult geometry problems. The difficulty in this problem has only to do with understanding the geometry of 3D space. The fortran involved should be extremely simple.

You could look up the formula's for the shortest distance from a point to a line in 3D space. If the distance is within acceptable tolerances, your point "might" be within the cylinder. If the point is near the end of the cylinder (outside of it or in it), that will require more checking.

My gut reaction here is... you need to rotate your coordinate axes such that one of the x or y or z coordinate axes lines up with the centerline passing through the cylinder. After calculating the coordinates of your cyclinders centerline and your point in question based on the new reference axes, I believe the problem would be trivial to solve. The main difficulty here is doing the coordinate axes transformation in 3D space. 2D is easy. 3D may cause you some large headaches.

Dan