1

我有一个列表列表nLevels- 一个 3D 云点:

[nodeID, X, Y, Z]

多行。一些节点将具有相同的X坐标Z和不同的Y坐标。

我想,首先识别具有相同坐标和不同坐标的X不同Z节点Y

然后,使用这些(X,Z)对和不同的Y级别,我想更改x第二个列表 ( nodes) 的坐标。

更改应尊重以下内容:

For x,y,z in `nodes`, if x=X, z=Z and (Y level 1 <=y< Y level 2):
   change `x` coordinates between consecutive `Y` levels, for each pair of `(X,Z)` coordinates.
Additionally, the changes in `x` coordinates should depend on pairs of nodes with same `(X, Y)` coordinates for different `Z` levels.

这段代码背后的想法是:对于具有相同的节点,x and y根据它们的z坐标改变它们的值。这会更改垂直对齐的节点。这些变化x and y现在必须在水平对齐的节点(具有相同x and z或相同的y and z坐标)中传播。

因为水平对齐节点的变化取决于垂直对齐节点的变化,所以我很难让代码正常工作。我必须在水平节点上循环并在该循环内,在垂直节点上循环......

编辑:已解决。此代码有效!

nLevels=[['173', '0.', '0.', '0.'], ['183', '1000.', '0.', '0.'], ['184', '0.', '1000.', '0.'], ['194', '1000.', '1000.', '0.'], ['195', '0.', '0.', '1000.'], ['205', '1000.', '0.', '1000.'], ['206', '0.', '1000.', '1000.'], ['216', '1000.', '1000.', '1000.'], ['217', '0.', '0.', '2000.'], ['227', '1000.', '0.', '2000.'], ['228', '0.', '1000.', '2000.'], ['238', '1000.', '1000.', '2000.'], ['239', '0.', '0.', '3000.'], ['249', '1000.', '0.', '3000.'], ['250', '0.', '1000.', '3000.'], ['260', '1000.', '1000.', '3000.'], ['261', '0.', '0.', '4000.'], ['271', '1000.', '0.', '4000.'], ['272', '0.', '1000.', '4000.'], ['282', '1000.', '1000.', '4000.'], ['283', '0.', '0.', '0.'], ['293', '0.', '1000.', '0.'], ['294', '1000.', '0.', '0.'], ['304', '1000.', '1000.', '0.'], ['305', '0.', '0.', '1000.'], ['315', '0.', '1000.', '1000.'], ['316', '1000.', '0.', '1000.'], ['326', '1000.', '1000.', '1000.'], ['327', '0.', '0.', '2000.'], ['337', '0.', '1000.', '2000.'], ['338', '1000.', '0.', '2000.'], ['348', '1000.', '1000.', '2000.'], ['349', '0.', '0.', '3000.'], ['359', '0.', '1000.', '3000.'], ['360', '1000.', '0.', '3000.'], ['370', '1000.', '1000.', '3000.'], ['371', '0.', '0.', '4000.'], ['381', '0.', '1000.', '4000.'], ['382', '1000.', '0.', '4000.'], ['392', '1000.', '1000.', '4000.'], ['436', '-1000.', '0.', '0.'], ['446', '0.', '0.', '0.'], ['447', '-1000.', '1000.', '0.'], ['457', '0.', '1000.', '0.'], ['458', '-1000.', '1000.', '1000.'], ['468', '0.', '1000.', '1000.'], ['469', '-1000.', '1000.', '2000.'], ['479', '0.', '1000.', '2000.'], ['480', '-1000.', '1000.', '3000.'], ['490', '0.', '1000.', '3000.'], ['491', '-1000.', '0.', '0.'], ['501', '-1000.', '1000.', '0.'], ['502', '-1000.', '1000.', '4000.'], ['512', '0.', '1000.', '4000.'], ['513', '-1000.', '0.', '1000.'], ['523', '0.', '0.', '1000.'], ['524', '-1000.', '0.', '2000.'], ['534', '0.', '0.', '2000.'], ['535', '-1000.', '0.', '3000.'], ['545', '0.', '0.', '3000.'], ['546', '-1000.', '0.', '4000.'], ['556', '0.', '0.', '4000.'], ['557', '-1000.', '0.', '1000.'], ['567', '-1000.', '1000.', '1000.'], ['568', '-1000.', '0.', '3000.'], ['578', '-1000.', '1000.', '3000.'], ['579', '-1000.', '0.', '2000.'], ['589', '-1000.', '1000.', '2000.'], ['590', '-1000.', '0.', '4000.'], ['600', '-1000.', '1000.', '4000.'], ['687', '0.', '2000.', '0.'], ['697', '1000.', '2000.', '0.'], ['698', '0.', '2000.', '1000.'], ['708', '1000.', '2000.', '1000.'], ['709', '0.', '2000.', '2000.'], ['719', '1000.', '2000.', '2000.'], ['720', '0.', '2000.', '3000.'], ['730', '1000.', '2000.', '3000.'], ['731', '0.', '2000.', '4000.'], ['741', '1000.', '2000.', '4000.'], ['742', '0.', '1000.', '0.'], ['752', '0.', '2000.', '0.'], ['753', '1000.', '1000.', '1000.'], ['763', '1000.', '2000.', '1000.'], ['764', '1000.', '1000.', '3000.'], ['774', '1000.', '2000.', '3000.'], ['775', '1000.', '1000.', '0.'], ['785', '1000.', '2000.', '0.'], ['786', '1000.', '1000.', '2000.'], ['796', '1000.', '2000.', '2000.'], ['797', '1000.', '1000.', '4000.'], ['807', '1000.', '2000.', '4000.'], ['808', '-1000.', '1000.', '0.'], ['818', '-1000.', '2000.', '0.'], ['819', '0.', '1000.', '1000.'], ['829', '0.', '2000.', '1000.'], ['830', '0.', '1000.', '2000.'], ['840', '0.', '2000.', '2000.'], ['841', '0.', '1000.', '3000.'], ['851', '0.', '2000.', '3000.'], ['852', '0.', '1000.', '4000.'], ['862', '0.', '2000.', '4000.'], ['863', '-1000.', '2000.', '0.'], ['873', '0.', '2000.', '0.'], ['874', '-1000.', '2000.', '1000.'], ['884', '0.', '2000.', '1000.'], ['885', '-1000.', '2000.', '2000.'], ['895', '0.', '2000.', '2000.'], ['896', '-1000.', '2000.', '3000.'], ['906', '0.', '2000.', '3000.'], ['907', '-1000.', '2000.', '4000.'], ['917', '0.', '2000.', '4000.'], ['918', '-1000.', '1000.', '1000.'], ['928', '-1000.', '2000.', '1000.'], ['929', '-1000.', '1000.', '3000.'], ['939', '-1000.', '2000.', '3000.'], ['940', '-1000.', '1000.', '2000.'], ['950', '-1000.', '2000.', '2000.'], ['951', '-1000.', '1000.', '4000.'], ['961', '-1000.', '2000.', '4000.']]
nodes=[['1', '0.', '0.', '-100.'], ['2', '0.', '0.', '0.'], ['3', '0.', '0.', '4000.'], ['4', '0.', '0.', '4100.'], ['5', '0.', '0.', '100.'], ['6', '0.', '0.', '200.'], ['7', '0.', '0.', '300.'], ['8', '0.', '0.', '400.'], ['9', '0.', '0.', '500.'], ['10', '0.', '0.', '600.'], ['11', '0.', '0.', '700.'], ['12', '0.', '0.', '800.'], ['13', '0.', '0.', '900.'], ['14', '0.', '0.', '1000.'], ['15', '0.', '0.', '1100.'], ['16', '0.', '0.', '1200.'], ['17', '0.', '0.', '1300.'], ['18', '0.', '0.', '1400.'], ['19', '0.', '0.', '1500.'], ['20', '0.', '0.', '1600.'], ['21', '0.', '0.', '1700.'], ['22', '0.', '0.', '1800.'], ['23', '0.', '0.', '1900.'], ['24', '0.', '0.', '2000.'], ['25', '0.', '0.', '2100.'], ['26', '0.', '0.', '2200.'], ['27', '0.', '0.', '2300.'], ['28', '0.', '0.', '2400.'], ['29', '0.', '0.', '2500.'], ['30', '0.', '0.', '2600.'], ['31', '0.', '0.', '2700.'], ['32', '0.', '0.', '2800.'], ['33', '0.', '0.', '2900.'], ['34', '0.', '0.', '3000.'], ['35', '0.', '0.', '3100.'], ['36', '0.', '0.', '3200.'], ['37', '0.', '0.', '3300.'], ['38', '0.', '0.', '3400.'], ['39', '0.', '0.', '3500.'], ['40', '0.', '0.', '3600.'], ['41', '0.', '0.', '3700.'], ['42', '0.', '0.', '3800.'], ['43', '0.', '0.', '3900.'], ['44', '0.', '1000.', '-100.'], ['45', '0.', '1000.', '0.'], ['46', '0.', '1000.', '4000.'], ['47', '0.', '1000.', '4100.'], ['48', '0.', '1000.', '100.'], ['49', '0.', '1000.', '200.'], ['50', '0.', '1000.', '300.'], ['51', '0.', '1000.', '400.'], ['52', '0.', '1000.', '500.'], ['53', '0.', '1000.', '600.'], ['54', '0.', '1000.', '700.'], ['55', '0.', '1000.', '800.'], ['56', '0.', '1000.', '900.'], ['57', '0.', '1000.', '1000.'], ['58', '0.', '1000.', '1100.'], ['59', '0.', '1000.', '1200.'], ['60', '0.', '1000.', '1300.'], ['61', '0.', '1000.', '1400.'], ['62', '0.', '1000.', '1500.'], ['63', '0.', '1000.', '1600.'], ['64', '0.', '1000.', '1700.'], ['65', '0.', '1000.', '1800.'], ['66', '0.', '1000.', '1900.'], ['67', '0.', '1000.', '2000.'], ['68', '0.', '1000.', '2100.'], ['69', '0.', '1000.', '2200.'], ['70', '0.', '1000.', '2300.'], ['71', '0.', '1000.', '2400.'], ['72', '0.', '1000.', '2500.'], ['73', '0.', '1000.', '2600.'], ['74', '0.', '1000.', '2700.'], ['75', '0.', '1000.', '2800.'], ['76', '0.', '1000.', '2900.'], ['77', '0.', '1000.', '3000.'], ['78', '0.', '1000.', '3100.'], ['79', '0.', '1000.', '3200.'], ['80', '0.', '1000.', '3300.'], ['81', '0.', '1000.', '3400.'], ['82', '0.', '1000.', '3500.'], ['83', '0.', '1000.', '3600.'], ['84', '0.', '1000.', '3700.'], ['85', '0.', '1000.', '3800.'], ['86', '0.', '1000.', '3900.'], ['87', '1000.', '0.', '-100.'], ['88', '1000.', '0.', '0.'], ['89', '1000.', '0.', '4000.'], ['90', '1000.', '0.', '4100.'], ['91', '1000.', '0.', '100.'], ['92', '1000.', '0.', '200.'], ['93', '1000.', '0.', '300.'], ['94', '1000.', '0.', '400.'], ['95', '1000.', '0.', '500.'], ['96', '1000.', '0.', '600.'], ['97', '1000.', '0.', '700.'], ['98', '1000.', '0.', '800.'], ['99', '1000.', '0.', '900.'], ['100', '1000.', '0.', '1000.'], ['101', '1000.', '0.', '1100.'], ['102', '1000.', '0.', '1200.'], ['103', '1000.', '0.', '1300.'], ['104', '1000.', '0.', '1400.'], ['105', '1000.', '0.', '1500.'], ['106', '1000.', '0.', '1600.'], ['107', '1000.', '0.', '1700.'], ['108', '1000.', '0.', '1800.'], ['109', '1000.', '0.', '1900.'], ['110', '1000.', '0.', '2000.'], ['111', '1000.', '0.', '2100.'], ['112', '1000.', '0.', '2200.'], ['113', '1000.', '0.', '2300.'], ['114', '1000.', '0.', '2400.'], ['115', '1000.', '0.', '2500.'], ['116', '1000.', '0.', '2600.'], ['117', '1000.', '0.', '2700.'], ['118', '1000.', '0.', '2800.'], ['119', '1000.', '0.', '2900.'], ['120', '1000.', '0.', '3000.'], ['121', '1000.', '0.', '3100.'], ['122', '1000.', '0.', '3200.'], ['123', '1000.', '0.', '3300.'], ['124', '1000.', '0.', '3400.'], ['125', '1000.', '0.', '3500.'], ['126', '1000.', '0.', '3600.'], ['127', '1000.', '0.', '3700.'], ['128', '1000.', '0.', '3800.'], ['129', '1000.', '0.', '3900.'], ['130', '1000.', '1000.', '-100.'], ['131', '1000.', '1000.', '0.'], ['132', '1000.', '1000.', '4000.'], ['133', '1000.', '1000.', '4100.'], ['134', '1000.', '1000.', '100.'], ['135', '1000.', '1000.', '200.'], ['136', '1000.', '1000.', '300.'], ['137', '1000.', '1000.', '400.'], ['138', '1000.', '1000.', '500.'], ['139', '1000.', '1000.', '600.'], ['140', '1000.', '1000.', '700.'], ['141', '1000.', '1000.', '800.'], ['142', '1000.', '1000.', '900.'], ['143', '1000.', '1000.', '1000.'], ['144', '1000.', '1000.', '1100.'], ['145', '1000.', '1000.', '1200.'], ['146', '1000.', '1000.', '1300.'], ['147', '1000.', '1000.', '1400.'], ['148', '1000.', '1000.', '1500.'], ['149', '1000.', '1000.', '1600.'], ['150', '1000.', '1000.', '1700.'], ['151', '1000.', '1000.', '1800.'], ['152', '1000.', '1000.', '1900.'], ['153', '1000.', '1000.', '2000.'], ['154', '1000.', '1000.', '2100.'], ['155', '1000.', '1000.', '2200.'], ['156', '1000.', '1000.', '2300.'], ['157', '1000.', '1000.', '2400.'], ['158', '1000.', '1000.', '2500.'], ['159', '1000.', '1000.', '2600.'], ['160', '1000.', '1000.', '2700.'], ['161', '1000.', '1000.', '2800.'], ['162', '1000.', '1000.', '2900.'], ['163', '1000.', '1000.', '3000.'], ['164', '1000.', '1000.', '3100.'], ['165', '1000.', '1000.', '3200.'], ['166', '1000.', '1000.', '3300.'], ['167', '1000.', '1000.', '3400.'], ['168', '1000.', '1000.', '3500.'], ['169', '1000.', '1000.', '3600.'], ['170', '1000.', '1000.', '3700.'], ['171', '1000.', '1000.', '3800.'], ['172', '1000.', '1000.', '3900.'], ['173', '0.', '0.', '0.'], ['174', '100.', '0.', '0.'], ['175', '200.', '0.', '0.'], ['176', '300.', '0.', '0.'], ['177', '400.', '0.', '0.'], ['178', '500.', '0.', '0.'], ['179', '600.', '0.', '0.'], ['180', '700.', '0.', '0.'], ['181', '800.', '0.', '0.'], ['182', '900.', '0.', '0.'], ['183', '1000.', '0.', '0.'], ['184', '0.', '1000.', '0.'], ['185', '100.', '1000.', '0.'], ['186', '200.', '1000.', '0.'], ['187', '300.', '1000.', '0.'], ['188', '400.', '1000.', '0.'], ['189', '500.', '1000.', '0.'], ['190', '600.', '1000.', '0.'], ['191', '700.', '1000.', '0.'], ['192', '800.', '1000.', '0.'], ['193', '900.', '1000.', '0.'], ['194', '1000.', '1000.', '0.'], ['195', '0.', '0.', '1000.'], ['196', '100.', '0.', '1000.'], ['197', '200.', '0.', '1000.'], ['198', '300.', '0.', '1000.'], ['199', '400.', '0.', '1000.'], ['200', '500.', '0.', '1000.'], ['201', '600.', '0.', '1000.'], ['202', '700.', '0.', '1000.'], ['203', '800.', '0.', '1000.'], ['204', '900.', '0.', '1000.'], ['205', '1000.', '0.', '1000.'], ['206', '0.', '1000.', '1000.'], ['207', '100.', '1000.', '1000.'], ['208', '200.', '1000.', '1000.'], ['209', '300.', '1000.', '1000.'], ['210', '400.', '1000.', '1000.'], ['211', '500.', '1000.', '1000.'], ['212', '600.', '1000.', '1000.'], ['213', '700.', '1000.', '1000.'], ['214', '800.', '1000.', '1000.'], ['215', '900.', '1000.', '1000.'], ['216', '1000.', '1000.', '1000.'], ['217', '0.', '0.', '2000.'], ['218', '100.', '0.', '2000.'], ['219', '200.', '0.', '2000.'], ['220', '300.', '0.', '2000.'], ['221', '400.', '0.', '2000.'], ['222', '500.', '0.', '2000.'], ['223', '600.', '0.', '2000.'], ['224', '700.', '0.', '2000.'], ['225', '800.', '0.', '2000.'], ['226', '900.', '0.', '2000.'], ['227', '1000.', '0.', '2000.'], ['228', '0.', '1000.', '2000.'], ['229', '100.', '1000.', '2000.'], ['230', '200.', '1000.', '2000.'], ['231', '300.', '1000.', '2000.'], ['232', '400.', '1000.', '2000.'], ['233', '500.', '1000.', '2000.'], ['234', '600.', '1000.', '2000.'], ['235', '700.', '1000.', '2000.'], ['236', '800.', '1000.', '2000.'], ['237', '900.', '1000.', '2000.'], ['238', '1000.', '1000.', '2000.'], ['239', '0.', '0.', '3000.'], ['240', '100.', '0.', '3000.'], ['241', '200.', '0.', '3000.'], ['242', '300.', '0.', '3000.'], ['243', '400.', '0.', '3000.'], ['244', '500.', '0.', '3000.'], ['245', '600.', '0.', '3000.'], ['246', '700.', '0.', '3000.'], ['247', '800.', '0.', '3000.'], ['248', '900.', '0.', '3000.'], ['249', '1000.', '0.', '3000.'], ['250', '0.', '1000.', '3000.'], ['251', '100.', '1000.', '3000.'], ['252', '200.', '1000.', '3000.'], ['253', '300.', '1000.', '3000.'], ['254', '400.', '1000.', '3000.'], ['255', '500.', '1000.', '3000.'], ['256', '600.', '1000.', '3000.'], ['257', '700.', '1000.', '3000.'], ['258', '800.', '1000.', '3000.'], ['259', '900.', '1000.', '3000.'], ['260', '1000.', '1000.', '3000.'], ['261', '0.', '0.', '4000.'], ['262', '100.', '0.', '4000.'], ['263', '200.', '0.', '4000.'], ['264', '300.', '0.', '4000.'], ['265', '400.', '0.', '4000.'], ['266', '500.', '0.', '4000.'], ['267', '600.', '0.', '4000.'], ['268', '700.', '0.', '4000.'], ['269', '800.', '0.', '4000.'], ['270', '900.', '0.', '4000.'], ['271', '1000.', '0.', '4000.'], ['272', '0.', '1000.', '4000.'], ['273', '100.', '1000.', '4000.'], ['274', '200.', '1000.', '4000.'], ['275', '300.', '1000.', '4000.'], ['276', '400.', '1000.', '4000.'], ['277', '500.', '1000.', '4000.'], ['278', '600.', '1000.', '4000.'], ['279', '700.', '1000.', '4000.'], ['280', '800.', '1000.', '4000.'], ['281', '900.', '1000.', '4000.'], ['282', '1000.', '1000.', '4000.'], ['283', '0.', '0.', '0.'], ['284', '0.', '100.', '0.'], ['285', '0.', '200.', '0.'], ['286', '0.', '300.', '0.'], ['287', '0.', '400.', '0.'], ['288', '0.', '500.', '0.'], ['289', '0.', '600.', '0.'], ['290', '0.', '700.', '0.'], ['291', '0.', '800.', '0.'], ['292', '0.', '900.', '0.'], ['293', '0.', '1000.', '0.'], ['294', '1000.', '0.', '0.'], ['295', '1000.', '100.', '0.'], ['296', '1000.', '200.', '0.'], ['297', '1000.', '300.', '0.'], ['298', '1000.', '400.', '0.'], ['299', '1000.', '500.', '0.'], ['300', '1000.', '600.', '0.'], ['301', '1000.', '700.', '0.'], ['302', '1000.', '800.', '0.'], ['303', '1000.', '900.', '0.'], ['304', '1000.', '1000.', '0.'], ['305', '0.', '0.', '1000.'], ['306', '0.', '100.', '1000.'], ['307', '0.', '200.', '1000.'], ['308', '0.', '300.', '1000.'], ['309', '0.', '400.', '1000.'], ['310', '0.', '500.', '1000.'], ['311', '0.', '600.', '1000.'], ['312', '0.', '700.', '1000.'], ['313', '0.', '800.', '1000.'], ['314', '0.', '900.', '1000.'], ['315', '0.', '1000.', '1000.'], ['316', '1000.', '0.', '1000.'], ['317', '1000.', '100.', '1000.'], ['318', '1000.', '200.', '1000.'], ['319', '1000.', '300.', '1000.'], ['320', '1000.', '400.', '1000.'], ['321', '1000.', '500.', '1000.'], ['322', '1000.', '600.', '1000.'], ['323', '1000.', '700.', '1000.'], ['324', '1000.', '800.', '1000.'], ['325', '1000.', '900.', '1000.'], ['326', '1000.', '1000.', '1000.'], ['327', '0.', '0.', '2000.'], ['328', '0.', '100.', '2000.'], ['329', '0.', '200.', '2000.'], ['330', '0.', '300.', '2000.'], ['331', '0.', '400.', '2000.'], ['332', '0.', '500.', '2000.'], ['333', '0.', '600.', '2000.'], ['334', '0.', '700.', '2000.'], ['335', '0.', '800.', '2000.'], ['336', '0.', '900.', '2000.'], ['337', '0.', '1000.', '2000.'], ['338', '1000.', '0.', '2000.'], ['339', '1000.', '100.', '2000.'], ['340', '1000.', '200.', '2000.'], ['341', '1000.', '300.', '2000.'], ['342', '1000.', '400.', '2000.'], ['343', '1000.', '500.', '2000.'], ['344', '1000.', '600.', '2000.'], ['345', '1000.', '700.', '2000.'], ['346', '1000.', '800.', '2000.'], ['347', '1000.', '900.', '2000.'], ['348', '1000.', '1000.', '2000.'], ['349', '0.', '0.', '3000.'], ['350', '0.', '100.', '3000.'], ['351', '0.', '200.', '3000.'], ['352', '0.', '300.', '3000.'], ['353', '0.', '400.', '3000.'], ['354', '0.', '500.', '3000.'], ['355', '0.', '600.', '3000.'], ['356', '0.', '700.', '3000.'], ['357', '0.', '800.', '3000.'], ['358', '0.', '900.', '3000.'], ['359', '0.', '1000.', '3000.'], ['360', '1000.', '0.', '3000.'], ['361', '1000.', '100.', '3000.'], ['362', '1000.', '200.', '3000.'], ['363', '1000.', '300.', '3000.'], ['364', '1000.', '400.', '3000.'], ['365', '1000.', '500.', '3000.'], ['366', '1000.', '600.', '3000.'], ['367', '1000.', '700.', '3000.'], ['368', '1000.', '800.', '3000.'], ['369', '1000.', '900.', '3000.'], ['370', '1000.', '1000.', '3000.'], ['371', '0.', '0.', '4000.'], ['372', '0.', '100.', '4000.'], ['373', '0.', '200.', '4000.'], ['374', '0.', '300.', '4000.'], ['375', '0.', '400.', '4000.'], ['376', '0.', '500.', '4000.'], ['377', '0.', '600.', '4000.'], ['378', '0.', '700.', '4000.'], ['379', '0.', '800.', '4000.'], ['380', '0.', '900.', '4000.'], ['381', '0.', '1000.', '4000.'], ['382', '1000.', '0.', '4000.'], ['383', '1000.', '100.', '4000.'], ['384', '1000.', '200.', '4000.'], ['385', '1000.', '300.', '4000.'], ['386', '1000.', '400.', '4000.'], ['387', '1000.', '500.', '4000.'], ['388', '1000.', '600.', '4000.'], ['389', '1000.', '700.', '4000.'], ['390', '1000.', '800.', '4000.'], ['391', '1000.', '900.', '4000.'], ['392', '1000.', '1000.', '4000.'], ['393', '-1000.', '0.', '-100.'], ['394', '-1000.', '0.', '0.'], ['395', '-1000.', '0.', '4000.'], ['396', '-1000.', '0.', '4100.'], ['397', '-1000.', '0.', '100.'], ['398', '-1000.', '0.', '200.'], ['399', '-1000.', '0.', '300.'], ['400', '-1000.', '0.', '400.']]

from ast import literal_eval
from collections import defaultdict
nLevels=[[literal_eval(x) for x in item] for item in nLevels] #transform list of strings to list of floats
nodes=[[literal_eval(x) for x in item] for item in nodes]
#=================================================================================================
NewNodesCoord = []
dirX=1 #integer that changes the direction (X,Y) of the vector to change the x and y coordinates
dirY=1-dirX
newy1=0 #float that stores the new y coordinate at x=X1 and z=Z 
newy2=0 #float that stores the new y coordinate at x=X2 (X2>X1) and z=Z 
newx1=0 #float that stores the new x coordinate at y=Y1 and z=Z 
newx2=0 #float that stores the new x coordinate at y=Y2 (Y2>Y1) and z=Z 

dic1=defaultdict(list) #dictionary of X and Y pairs

for nodeID,x,y,z in nLevels:
    dic1[(x,y)].append((nodeID,z))
for key in dic1:
    dic1[key].sort( key=lambda x:float(x[1]) )

newNodes=[] #list with changed coordinates
deformed=[]
alocal=40.
aglobal=80.
for i,row in enumerate(nodes): #same X,Y, different Z
    nodeID,x,y,z=row
    z_levels=[item[1] for item in dic1[(x,y)]]
    for k,l in zip(z_levels,z_levels[1:]):
        if k<z<l:
            nodes[i][1]=(x+((l-k)/alocal*sin(pi*(z-k)/(l-k))+
                float(max(z_levels)-min(z_levels))/aglobal*float(z-min(z_levels))/float(max(z_levels)-min(z_levels)))*dirX)
            nodes[i][2]=(y+((l-k)/alocal*sin(pi*(z-k)/(l-k))+
                float(max(z_levels)-min(z_levels))/aglobal*float(z-min(z_levels))/float(max(z_levels)-min(z_levels)))*dirY)
            nodes[i][3]=z
            if len(newNodes)==0:
                newNodes.append([nodes[i][0], nodes[i][1], nodes[i][2], nodes[i][3]]) 
                deformed.append([x, y, z, nodes[i][1]-x, nodes[i][2]-y])
            else:
                for newID in newNodes:
                    fexID=0
                    if newID[0]==nodes[i][0]:
                        fexID=1
                        break
                if fexID!=1:
                    newNodes.append([nodes[i][0], nodes[i][1], nodes[i][2], nodes[i][3]])
                    deformed.append([x, y, z, nodes[i][1]-x, nodes[i][2]-y])
        if z==l and l!=k:
            nodes[i][1]=(x+((l-k)/alocal*sin(pi*(z-k)/(l-k))+
                float(max(z_levels)-min(z_levels))/aglobal*float(z-min(z_levels))/float(max(z_levels)-min(z_levels)))*dirX)
            nodes[i][2]=(y+((l-k)/alocal*sin(pi*(z-k)/(l-k))+
                float(max(z_levels)-min(z_levels))/aglobal*float(z-min(z_levels))/float(max(z_levels)-min(z_levels)))*dirY)
            nodes[i][3]=z
            if len(newNodes)==0:
                newNodes.append([nodes[i][0], nodes[i][1], nodes[i][2], nodes[i][3]]) 
                deformed.append([x, y, z, nodes[i][1]-x, nodes[i][2]-y])
            else:
                for newID in newNodes:
                    fexID=0
                    if newID[0]==nodes[i][0]:
                        fexID=1
                        break
                if fexID!=1:
                    newNodes.append([nodes[i][0], nodes[i][1], nodes[i][2], nodes[i][3]])
                    deformed.append([x, y, z, nodes[i][1]-x, nodes[i][2]-y])

yv=[]
for i,row in enumerate(nodes):  #same X, different Y
    nodeID,x,y,z=row
    yv=[]
    for j, line in enumerate(deformed):
        x2,y2,z2,nx,ny=line
        if x==x2 and z==z2:
            yv.append([y2, nx, ny])
    yv=sorted(yv, key=lambda yv: yv[0])
    for i2, row2 in enumerate(yv):
        k=yv[i2][0]
        if i2==len(yv)-1:
            l=k
        else:
            l=yv[i2+1][0]
        if k<y<l:
            newx1=yv[i2][1]
            newx2=yv[i2+1][1]
            nodes[i][1]=x+(y-k)*(newx2-newx1)/(l-k)+newx1
            nodes[i][2]=y
            nodes[i][3]=z
            if len(newNodes)==0:
                newNodes.append([nodes[i][0], nodes[i][1], nodes[i][2], nodes[i][3]]) 
            else:
                for newID in newNodes:
                    fexID=0
                    if newID[0]==nodes[i][0]:
                        fexID=1
                        break
                if fexID!=1:
                    newNodes.append([nodes[i][0], nodes[i][1], nodes[i][2], nodes[i][3]])

已解决:有效!

4

0 回答 0