Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

FORTRAN check particle distance to centre of an object.

FORTRAN check particle distance to centre of an object.

FORTRAN check particle distance to centre of an object.


I am quite new to FORTRAN and am currently making programs to gain an understanding of it. I am using FORTRAN 90 and Microsoft Visual Studio.

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.

Sorry to post on the thread I made before other people have posted. I have worked out mostly what I need to do.

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.

Apologies again, I have found a solution to this that might be viable.

(xP(i) and zP(i) are the particle co-ordinates)
IF ((((xP(i)-cylinder_x)**2)+((zP(i)-cylinder_z)**2)) < (cylinder_radius**2)) THEN

Could I improve this further?

Also, 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?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close