Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cylinder-Wall Spheropolyhedron Support #1984

Open
wants to merge 3 commits into
base: trunk-patch
Choose a base branch
from

Conversation

seoulfood
Copy link
Contributor

Description

I added in spheropolyhedron support for cylindrical walls. I changed one user seen python file and the ExternalWall.h file.

Motivation and context

It's useful to be able to scan through convex polyhedra, convex spheropolyhedra, and spheres within cylindrical walls.

How has this been tested?

NEED TO ADD

Documentation builds and displays correctly.

Checklist:

  • [ x ] I have reviewed the Contributor Guidelines.
  • [ x ] I agree with the terms of the HOOMD-blue Contributor Agreement.
  • [ x ] My name is on the list of contributors (sphinx-doc/credits.rst) in the pull request source branch.
  • I have summarized these changes in CHANGELOG.rst following the established format.

Added cylinder-spheropolyhedra support
Added cylinder-spheropolyhedra overlap method
Copy link
Member

@joaander joaander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I have many suggestions to improve the code.

ALSO, you need to add unit tests to check that the intersection test is working as intended. test_external_wall.py tests the walls.

= cross(shifted_pos,
wall.orientation); // find the component of the shifted position that is
// perpendicular to the normalized orientation vector
Scalar max_dist = sqrt(dot(dist_vec, dist_vec));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value is only ever used squared.

Remove the sqrt and rename to max_dist_squared. Remove the multiplications that square it.

Comment on lines +498 to +501
vec3<Scalar> dist_vec
= cross(shifted_pos,
wall.orientation); // find the component of the shifted position that is
// perpendicular to the normalized orientation vector
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments are easier to read at the same level as the code. You can also use English language rules when writing comments.

Suggested change
vec3<Scalar> dist_vec
= cross(shifted_pos,
wall.orientation); // find the component of the shifted position that is
// perpendicular to the normalized orientation vector
// Find the component of the shifted position that is
// perpendicular to the normalized orientation vector.
vec3<Scalar> dist_vec
= cross(shifted_pos,
wall.orientation);

wall.orientation); // find the component of the shifted position that is
// perpendicular to the normalized orientation vector
Scalar max_dist = sqrt(dot(dist_vec, dist_vec));
if (wall.inside)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment would be helpful to understand what the code is doing here.

Suggested change
if (wall.inside)
// Check if the shape's bounding sphere intersects the wall.
if (wall.inside)

Also, consider rewriting this so that it evaluates the <= or > inside the if. The branch is repeated again with a ternary operator on the next line which is very confusing. Better yet, combine the content of the if check_verts -> if shape.verts.N -> branches here as well. Bringing all the "inside" and "outside" code together will make it much easier to understand.

}
// Edge case; pure sphere. In this case, check_verts implies that the
// sphere will be outside.
// Note from gabs: I don't fully understand this edge case
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When shape.verts.N is zero, it is assume to have a single vertex at 0,0,0 - making it a sphere. In that case the bounding sphere check above is the only check that is necessary. I agree that this is really confusing. This case should be handled FIRST, not last. It would be more readable moved up above and handled with its own return false branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants