|
9 | 9 | import ruamel.yaml |
10 | 10 | import moorpy as mp |
11 | 11 | from moorpy.helpers import loadPointProps, getPointProps |
| 12 | +import shapely as sh |
12 | 13 |
|
13 | 14 |
|
14 | 15 | def cart2pol(x, y): |
@@ -211,7 +212,6 @@ def check_headings(m_headings,c_heading,rad_buff): |
211 | 212 | # convert negative headings to positive headings |
212 | 213 | for i,mh in enumerate(m_headings): |
213 | 214 | if mh<0: |
214 | | - #breakpoint() |
215 | 215 | m_headings[i] = 2*np.pi + mh |
216 | 216 | elif mh>2*np.pi: |
217 | 217 | m_headings[i] = mh - 2*np.pi |
@@ -249,7 +249,6 @@ def head_adjust(att,heading,rad_buff=np.radians(30),endA_dir=1): |
249 | 249 | headnew = np.pi*2 + heading |
250 | 250 | else: |
251 | 251 | headnew = heading |
252 | | - #breakpoint() |
253 | 252 | attheadings = [] |
254 | 253 | flipheads = False # whether to flip headings ( for if you are looking at mooring headings of platform on the other end) |
255 | 254 | for at in att: |
@@ -849,6 +848,57 @@ def getAnchors(lineAnch, arrayAnchor, proj): |
849 | 848 |
|
850 | 849 | return(ad, mass) |
851 | 850 |
|
| 851 | +def route_around_anchors(proj, anchor=True, cable=True, padding=50): |
| 852 | + |
| 853 | + # make anchor buffers with 50m radius |
| 854 | + if anchor: |
| 855 | + anchor_buffs = [] |
| 856 | + for anch in proj.anchorList.values(): |
| 857 | + anchor_buffs.append(anch.makeBuffer()) |
| 858 | + |
| 859 | + # make cable linestrings including joint locs and static cable (no dynamic cable for simplicity) |
| 860 | + if cable: |
| 861 | + cable_line = {} |
| 862 | + for name, cab in proj.cableList.items(): |
| 863 | + cable_line[name] = cab.makeLine(include_dc=False) |
| 864 | + |
| 865 | + # Function to calculate angle of a point relative to a center |
| 866 | + def angle(pt): |
| 867 | + return np.arctan2(pt[1] - center[1], pt[0] - center[0]) |
| 868 | + |
| 869 | + # Loop through each cable linestring and anchor buffer |
| 870 | + for name,cab in cable_line.items(): |
| 871 | + for anch in anchor_buffs: |
| 872 | + if cab.intersects(anch): |
| 873 | + # Get the start and end of the detour (the two closest points to the buffer) |
| 874 | + segments = [] |
| 875 | + # make additional points on the line on either side of anchor |
| 876 | + dist_to_anch = cab.line_locate_point(anch.centroid) |
| 877 | + if dist_to_anch > 100: |
| 878 | + segments.append(cab.interpolate(dist_to_anch - 100)) |
| 879 | + if cab.length - dist_to_anch > 100: |
| 880 | + segments.append(cab.interpolate(dist_to_anch + 100)) |
| 881 | + |
| 882 | + start = np.array(segments[0].coords[-1]) |
| 883 | + |
| 884 | + # Get buffer center and radius |
| 885 | + center = np.array(anch.centroid.coords[0]) |
| 886 | + radius = anch.boundary.distance(sh.Point(center))+padding |
| 887 | + |
| 888 | + # Calculate angle for start point relative to center |
| 889 | + angle_start = angle(start) |
| 890 | + |
| 891 | + # Generate point along the arc (detour) |
| 892 | + arc_point = [center[0] + radius * np.cos(angle_start+np.pi/2), center[1] + radius * np.sin(angle_start+np.pi/2)] |
| 893 | + |
| 894 | + # add new routing point in cable object |
| 895 | + proj.cableList[name].subcomponents[2].updateRouting([list(segments[0].coords[1:]) + arc_point + list(segments[1].coords[:-1])]) |
| 896 | + |
| 897 | + |
| 898 | + |
| 899 | + |
| 900 | + |
| 901 | + |
852 | 902 | def configureAdjuster(mooring, adjuster=None, method='horizontal', |
853 | 903 | i_line=0, span=None, project=None, target=None): |
854 | 904 | '''Configures adjuster function for mooring object |
|
0 commit comments