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

compute proper bounding box for cylinders #15

Closed
wants to merge 1 commit into from

Conversation

matthuszagh
Copy link
Contributor

@matthuszagh matthuszagh commented Mar 16, 2020

This PR computes a proper bounding box for cylinders and cylindrical shells. It does this by computing parametric equations for the terminal circles and then computing maxima and minima (parametric circle equations use the method described here).

Let me know what you think of this. Happy to make any/all changes needed. In particular, this won't handle zero-height cylinders correctly, although I'm not sure what the intended behavior is there. If you do have specific behavior in mind for that, let me know and I'll make this work with it.

Additionally, I'm not sure how to get the bounding box of transformed cylinders. Normally, I get the original bounding box of the object and then transform each coordinate, but that doesn't seem to work here. Any thoughts on how to do this?

@thliebig
Copy link
Owner

thliebig commented Apr 11, 2021

Hi, sorry for this very late answer.
I had a quick look at your PR but it was to complex for just a quick one. I may need to have a closer look at some point.
But my main question is. Why did you create this patch? The very rough bounding box calculation should be fine in almost all cases. A better approximation may speedup the pre-processing but I guess not by very much.
Thus what is the reason for this PR?
As far a as a transformed cylinder is considered. This is really not easy or always possible thus I just skip it. If a user wants to use hundreds or thousands of transformed objects he will be in serious (speed) trouble...

@matthuszagh
Copy link
Contributor Author

matthuszagh commented May 26, 2021

No worries! Seems that I'm a bit late to respond as well.

I've created an openems automatic mesh generation tool (still a work in progress) that uses the bounding box of each object as the basis for determining the position of mesh lines. There are cases in which I need a cylinder to terminate in a PML at the outer face of a simulation structure. Having the bounding box for cylinders extend beyond their actual boundary makes my tool think that the structure extends further out and creates mesh lines there, preventing the PML from working.

Here is an example of a CSXCAD structure exhibiting the intended behavior (using this PR), and here is an example with the unintended behavior (unfortunately, github won't let me upload XML files).

I've also attached images of the correct (first) and incorrect (second) structures (ignore the very non-smooth mesh lines in the incorrect structure, this case isn't supported by my tool). If it isn't clear from the images, the first image differs from the second in that mesh lines extend beyond the boundary of the coaxial cable in the second image, whereas they terminate at the boundary in the first image.

right

wrong

Let me know if you need more information or if this post isn't clear in some way.

@thliebig
Copy link
Owner

Hm I have picked you commit, but somehow github does not really notice?

@thliebig
Copy link
Owner

One more comment: I think the implementation in "CSPrimCylindricalShell" and "CSPrimCylinder" is pretty redundant? Maybe put it in a special funtion to reuse in both cases???
Redundancy is not good...

@thliebig
Copy link
Owner

thliebig commented May 14, 2022

I have removed the redundancy. Only change I can see: CSPrimCylindricalShell now also claims to be "accurate", but I would not see why it should not while the CSPrimCylinder should?
Can you give my change a test and review?

I think we can close this PR?

@matthuszagh
Copy link
Contributor Author

Looks good, thanks!

I'm not sure why I just copied that function definition in two places... In any event, how you have it now is much better.

@thliebig thliebig reopened this May 18, 2022
@thliebig
Copy link
Owner

Unfortunately I found a major issue with your commit... You make the "orientation" of the bounding box dependent on if the cylinder axis start<=stop or not... But the BB must always be oriented start<=stop for all directions
Any reason for this??? Well I have to change/fix that!

Note: Please use only tabs not spaces! I missed that too...

@matthuszagh
Copy link
Contributor Author

matthuszagh commented May 18, 2022

Unfortunately I found a major issue with your commit... You make the "orientation" of the bounding box dependent on if the cylinder axis start<=stop or not... But the BB must always be oriented start<=stop for all directions Any reason for this??? Well I have to change/fix that!

Can you clarify the intended behavior? I was under the impression that start[i] must be <= stop[i] (i.e., for each coordinate). It's been quite a while since I wrote this code, but from a quick glance (I'll take a more detailed look soon) it looks like that's what the "flip" logic ensures. Again, I can take a closer look and verify this if you confirm the behavior it should exhibit.

Note: Please use only tabs not spaces! I missed that too...

Sorry about that, I can create a PR with the spaces replaced with tabs, or you can, whichever you prefer.

@thliebig
Copy link
Owner

I'm already in the process to understand it and have already replaced the spaces (no big deal!)
Yes start[i] must be <= stop[i] for all i, but if I understand your code correctly you tried to flip this if the axis of the cylinder were flipped?
In any case I hopefully fixed it correctly. I tried to simplify it by using fmin/fmax in the assignments.
Please give it a good look.

@thliebig
Copy link
Owner

BTW: I found it when I investigated for #27

@matthuszagh
Copy link
Contributor Author

That looks correct to me. Sorry about the bug and thanks for the fix!

matthuszagh added a commit to matthuszagh/pyems that referenced this pull request Mar 9, 2023
This incorrect behavior corrected for a bug I introduced in
thliebig/CSXCAD#15. Thorsten identified and
fixed that bug, which causes this code to produce incorrect results.
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.

None yet

2 participants