I am trying to understand how to calculate the angle between two curves on a rail so that I can avoid the overlap.
The process for the application is: 1) Two lines are set. Each line has a defined ‘width’. 2) A spline is created by selecting the first line endpoint, the intersection of the two lines, and the second lines endpoint. 3) A sweep1 command is applied on the spline using the two ‘width’ definitions.
In the image below, the given lines are E1 and E2, with the required ‘widths’ as C1 and C2. The top row shows the sweep will overlap.
In the bottom portion, C1 and C2 are moved further away from the intersection point. Then the sweep works. I can not change the angle between E1 and E2, and can not change the length of C1 and C2, but can change the distance from C1 and C2 from the intersection.
What is the formula to calculate the minimum distance each line can be from the intersection for the sweep to not have an overlapping portion? The goal is to have them equal distance from the intersection (meaning I can naturally move C1 by itself away from the intersection, but then it would be at a different distance than C2 to the intersection). The angle between E1 and E2 can change as well as the ‘widths’, so that is why I am looking for a formula.
Hello - do you really need to work it out ahead of time, or just have it work? Running Sweep1 with History enabled will allow you to edit the inputs and change the sweep on the fly.
This is just a simplified example, but yes I need to calculate it ahead of time. Likely will use python but posted here as the question could just be about how the tool can be calculated without code example
Well, there is some mathematics involved, but I would say this might be one way to look at it:
Considering the length of either of the two legs and the angle between them could vary, as well as the “width” of each cross-section (profile) curve, this will also produce a spline curve (the rail) that will have varying curvature over its length. The key is that the radius at the point of sharpest curvature should be larger than half the profile width at that point (assuming the profile(s) are more ore less centered on the rail). If it’s less then you might get a fold there.
So I might look at getting the linear ratio of your two profile “widths” extrapolated along the length of the curve - i.e. at any point on the length of the curve you have the proportional linear average width of the profiles - then check that against the curvature radius at that point. If the radius is less than half of the calculated profile width at the length parameter along the curve, you may get a fold.
All the above said, sweeps are difficult to predict, so I couldn’t guarantee this will always work. I would also have a tendency to run the sweep first “virtually” and then try to analyze the resulting surface to see if there are folds. But I have no idea how to do that mathematically.
Hello - well, there is a linear interpolation for the length of the shape curve - the line in this case- along the length of the rail, so you can check the radius of your path and make sure it is always larger at every point than the length of the line being swept at the same point… That would be a thing to look for but how that relates to your angle…
Actually I thought of a method that might work to check for a folded surface once it has been created - this could be done in RhinoCommon I suppose so that you don’t actually have to add the surface to the document…
Get the domain of the “across” (profile) direction of the surface and march along it at a relatively fine increment, extracting the isocurves in the “along” (rail) direction. If there is a fold in the surface somewhere, at least one of the isocurves will be self-intersecting. In RhinoCommon the Intersection.CurveSelf method can detect this (there is no equivalent for surfaces, that’s why you would have to extract curves). Depending on the fineness of the divisions, it might take a little time for each check.
I suspect that the author of sweep1 is the only person who could have a stab at a formula for this. For a start, the offset distance does not vary linearly along the spline.
But here is a Grasshopper program that allows you to set C1, C2 and the angle and vary E1 and E2 to find a solution. It works by comparing the area of the swept surface with the area of a surface bounded by the sweep edges. By starting with short E1 and E2 and increasing the length until the area difference reduces to zero you get your minimal E length.
Note that there is a simple minimal E length below which sweep cannot work (where C1 or C2 intersects the angle bisector) so the program ignores E entries below that.
My understanding of your requirement is that E1 = E2 so the program works on that basis.
You may wish to increase the length of E1 and E2 slightly beyond the minimum on aesthetic grounds to get a smoother surface edge.
The program draws the geometry in the top view, starting from the world origin. You have the opportunity to bake it there and transform the result into the appropriate place in your model.
I’m new to Grasshopper, so I imagine the program could benefit from some refactoring, but rough and ready as it is, it seems to work within my limited testing.