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

Need a method to check where does a bluemira wire intersect with a straight line #3039

Closed
5 tasks
OceanNuclear opened this issue Feb 23, 2024 · 5 comments
Closed
5 tasks
Labels
cad Tasks relating to the cad module codes Tasks relating to integration of external codes geometry Tasks relating to the geometry module

Comments

@OceanNuclear
Copy link
Contributor

OceanNuclear commented Feb 23, 2024

Description of issue / requirement to address

As a Reactor Designer/Developer, I want to draw arbitrary straight lines to cut up my reactor 2D cross-section made of BluemiraWires, so that I can cut down components for neutronics csg.

We do not currently have a straightforward method of finding where a piece of wire intersects with a straight-line. The reason is likely because we were not expecting the wires to be used this way in 2D when BluemiraWire was initially created.

Proposed solution

Make a method that creates a plane that is both perpendicular to the 2D plane that we are drawing the BluemiraWire in, and parallel to the line of interest; and use slice_shape to find all intersection points, then use parameter_at to find the corresponding parameter.

Alternative solutions 1

Derive the equation for determining the intersection point between a straight line and each of the following curve types:

  • Straight line: this one is trivial
  • Arc of circle:
  • Bezier curve
  • BSpline
  • Arc of ellipse

Then, for each edge in the BluemiraWire, apply the corresponding equation to determine where the intersection points are.

So the method should collect all of the intersection points from each edge, and return them as a list of coordinates.

Alternative solutions 2

Simply use scipy.optimize.bisect to perform a binary search using BluemiraWire.value_at(). The search range must be determined appropriately by the user beforehand.

Additional context

This is a very specific use case of BluemiraWire (which are inherently 3D objects) to represent 2D shapes. Should we make a subclass of BluemiraWire (e.g. called Bluemira2DWire)?

@CoronelBuendia
Copy link
Contributor

BluemiraWires are 3-D. If you want to intersect them with a line, you will likely run into problems. You can use geometry::tools.py::slice_shape with a BluemiraPlane if you want 3-D intersections.

If you are working in 2-D, I generally recommend using Coordinates which are generally better suited for such work. BluemiraWires with multiple sub-wires can quickly become tricky in many 2-D situations where you expect things to be ordered and they are not.

In the case that it is definitely 2-D and you use Coordinates, you can use geometry::coordinates.py::get_intersect for the intersection between two 2-D shapes.

@OceanNuclear
Copy link
Contributor Author

The wire that I'm dealing with is a BSpline curve, which means I can't use get_intersect without first discretizing, which makes the program equally slow anyways. (I've tried upping the discretization resolution from 10 to 50 points-per-wire elsewhere, and it managed to slow down the program runtime from 0.8s to 3.4s.)

Unfortunately there are no curved lines functionality in coordinates.py which is why I haven't been able to use it.

So far the issue of misordering hasn't come up again after dealing with #3037, which seemed more like a serialization bug anyways, and we've managed to solve part of it by using .OrderedEdges so it hasn't happened again. But please do draw my attention to any misordering bug if you know of it and I'll assess whether that's going to be a problem or not!

@OceanNuclear OceanNuclear added geometry Tasks relating to the geometry module cad Tasks relating to the cad module codes Tasks relating to integration of external codes labels Mar 16, 2024
@CoronelBuendia
Copy link
Contributor

Right, but can you not get what you need using slice_shape(spline_wire, my_line_plane: BluemiraPlane)?

@OceanNuclear
Copy link
Contributor Author

Yeah, I kind of solved my own issue in the ocean/csg branch using that. I used slice_shape() to make bluemira.geometry.tools.get_wire_plane_intersect. I'll resolve/close this issue once that branch is merged.

@OceanNuclear
Copy link
Contributor Author

ocean/csg is merged. Issue resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cad Tasks relating to the cad module codes Tasks relating to integration of external codes geometry Tasks relating to the geometry module
Projects
None yet
Development

No branches or pull requests

2 participants