Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-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!

*Eng-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 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.

Thank you for your help. I have come up with this, which I think might solve it: (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

what are your thoughts?

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

Thank you for your help.

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.

No fear, this isn't for school. I'm trying to learn fortran and see what it can do. I have seen some simulations in conferences and was curious to see how it was achieved and if it can be used to help me. I don't have anyone I know who does fortran hence why I was asking here, I couldn't find it online by searching on google.

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

This problem is a lot trickier than it sounds at first.

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.


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 Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

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

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


Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

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

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close