Calculating distance between two obstacles from a Lidar vertical scan

71 Views Asked by At

I have a 2D Lidar scanner that is scanning vertically (see photo Graphical Representation of Data). The center point is the scanner. The bottom is the floor, top is the ceiling, and the left and right sides are selves. I am trying to figure out, from the scan data, what the width of the largest box is that I can push down this isle. The shelves can be variable length, and items on them can stick out into the isle way.

If I look at 90 and 180 degrees I can see that their is 852mm plus 1,090mm totaling 1,942mm. But, their is no guarantee that what is scanned at 90 and 180 degrees are the limiting points. Because it is a circle, I know tangent is involved, but I can not rap my head around the formula. Additionally, the floor (which in this scan from about 140 degrees to 220 degrees) should not be included in the width calculation. I'm sure a single formula will not solve this, and that a program will need to iterate through the data. Help with the mathematics would be appreciated.

Thank you.

Download link to data below

Graphical Representation of Data |Bearing in degrees |Distance in mm| |------------------:|---------------:| |0.0439|5752| |0.3406|5752| |0.6207|5760| |0.9009|5752| |1.1865|5768| |1.4832|5792| |1.7633|5776| |2.0435|5776| |2.3236|5784| |2.6202|5800| |2.9059|5792| |3.186|5792| |3.4662|5808| |3.7628|5816| |4.043|5816| |4.3231|5816| |4.6198|5816| |4.9054|5800| |5.1855|5808| |5.4657|5808| |5.7623|5808| |6.0425|5808| |6.3281|5816| |6.6248|5824| |6.9049|5824| |7.1851|5824| |7.4652|5808| |7.7618|5808| |8.042|5816| |8.3276|5816| |8.6243|5816| |8.9044|5832| |9.1846|5856| |9.4812|5872| |9.7614|5888| |10.0415|5896| |10.3271|5896| |10.6238|5896| |10.9039|5896| |11.7609|5912| |12.453|3736| |12.7332|3696| |13.0133|3660| |13.5901|3676| |15.1831|6056| |16.1554|3740| |17.0123|3712| |17.309|3724| |17.5891|3732| |17.8748|3736| |18.1549|3780| |18.4515|3816| |18.7317|3804| |19.0118|3784| |19.3085|3780| |19.5886|3792| |23.5931|3960| |23.8733|3944| |24.1699|3972| |24.4501|3996| |24.7302|3980| |25.0104|3980| |25.3125|4008| |25.5927|3996| |25.8728|3992| |26.1694|3996| |26.4496|4000| |26.7297|4020| |27.312|4052| |30.108|4128| |30.3882|4216| |30.6848|4272| |31.7175|6848| |31.9977|6864| |32.2778|6920| |33.1512|6952| |34.0741|6112| |34.3103|7048| |34.5905|7160| |34.8871|7192| |35.1672|7232| |35.4639|7256| |35.7495|7312| |36.0461|7360| |36.3263|7384| |36.6229|7424| |36.9031|7416| |37.1997|7416| |37.4799|7432| |37.7765|7456| |38.0621|7488| |38.3588|7512| |38.6389|7528| |38.9355|7592| |39.2322|7664| |39.5123|7680| |39.809|7704| |40.0891|7736| |40.3857|7768| |40.6714|7808| |40.968|7840| |41.2482|7808| |41.5448|7792| |41.825|7880| |42.1216|7960| |42.4017|8080| |42.6984|8144| |42.984|8136| |43.2806|8160| |43.5608|8168| |44.1376|7792| |44.4342|7880| |45.2966|7976| |46.4337|1816| |46.7303|1812| |47.0105|1808| |47.3071|1806| |47.5928|1804| |47.8894|1800| |48.1696|1796| |48.4662|1802| |48.7463|1802| |49.043|1798| |49.3231|1798| |49.6198|1798| |49.9054|1814| |50.202|1834| |50.4822|1850| |50.7788|1852| |51.059|1842| |51.9324|1840| |52.4652|10168| |53.042|10208| |53.3386|9304| |53.9209|10064| |54.201|10264| |54.4977|10448| |54.7778|10536| |55.0745|10632| |55.3546|10736| |55.6512|10792| |55.9369|10848| |56.2335|10984| |56.5302|10920| |58.5571|1026| |58.9032|1022| |59.1998|1022| |59.48|1020| |59.7766|1018| |60.0623|1016| |60.3589|1012| |60.639|1008| |60.9357|1006| |61.2158|1004| |61.5125|1002| |61.7926|1000| |62.0892|998| |62.3749|994| |62.655|990| |62.9517|988| |63.2318|988| |63.5284|986| |63.8086|984| |64.1547|980| |64.4348|978| |64.7314|976| |65.0116|974| |65.2917|972| |65.5884|970| |65.874|970| |66.4508|968| |66.7969|922| |67.077|914| |67.4176|908| |67.7142|898| |67.9999|892| |68.28|892| |69.2633|1024| |69.5599|1024| |69.8401|1012| |70.1202|1010| |70.4169|1010| |70.7025|1010| |71.6858|1170| |71.9165|1196| |72.2021|1206| |73.0591|1202| |73.3557|1228| |73.6359|1228| |73.9215|1228| |74.9652|1360| |75.2454|1362| |75.542|1364| |75.7617|1368| |76.0583|1372| |76.3385|1372| |76.6406|1370| |76.9812|1366| |77.2614|1364| |77.5415|1366| |77.8436|1366| |78.1238|1360| |78.4039|1358| |78.7006|1356| |78.9807|1356| |79.2773|1354| |79.5575|1352| |79.8431|1352| |80.1398|1350| |80.4199|1350| |80.7166|1350| |80.9967|1346| |81.2769|1344| |81.5735|1344| |81.8591|1344| |82.1393|1344| |82.4359|1342| |82.7161|1342| |83.0127|1342| |83.2928|1342| |83.573|1340| |84.1553|1344| |84.6716|1078| |85.0122|1068| |85.2924|1064| |85.589|1058| |85.8746|1056| |86.1548|1054| |86.4514|1050| |86.7316|1050| |87.0282|1050| |87.3083|1054| |87.5885|1056| |87.8906|1056| |89.0277|852| |89.3079|852| |89.5935|850| |89.8901|850| |90.1703|852| |90.4504|852| |90.7471|852| |91.0272|850| |91.3074|850| |91.593|850| |91.8896|850| |92.1698|850| |92.45|850| |92.7466|852| |93.0267|852| |93.3124|852| |93.5925|852| |93.8892|852| |94.1693|852| |94.4495|854| |94.7461|854| |95.0262|854| |95.3119|856| |95.592|856| |95.8887|856| |96.1688|856| |96.449|856| |96.7456|856| |97.0313|858| |97.3114|858| |97.608|860| |97.8882|862| |98.1683|862| |98.4485|862| |98.7451|862| |99.0308|864| |99.3109|866| |99.6075|866| |99.8877|862| |100.1678|854| |100.448|856| |100.7446|870| |101.0303|872| |101.3104|862| |101.6071|856| |101.8872|856| |102.1674|854| |102.453|852| |102.7496|854| |103.1561|1186| |103.4363|1174| |103.7769|1170| |104.0625|1164| |104.3591|1158| |104.6393|1160| |104.9194|1162| |105.2161|1166| |105.4358|1174| |105.7324|1178| |106.0126|1176| |106.2927|1178| |106.5729|1186| |106.875|1192| |107.1552|1202| |107.4353|1218| |107.6715|1230| |108.0121|1228| |108.2922|1222| |108.5889|1220| |108.8745|1222| |109.1547|1222| |110.0116|1216| |110.528|990| |110.8081|984| |111.1542|980| |111.4343|972| |111.7145|968| |112.0111|966| |112.2968|960| |112.5769|962| |112.8735|964| |113.1537|960| |113.4338|956| |113.714|952| |114.0106|956| |114.2963|958| |114.5764|958| |114.873|960| |115.1532|956| |115.4333|948| |115.7135|946| |116.0156|946| |116.2958|948| |116.5759|952| |116.8561|954| |117.1527|956| |117.4329|958| |117.7185|962| |117.9987|966| |118.2788|968| |118.5754|970| |118.8556|974| |119.1357|976| |119.4214|980| |119.6521|984| |119.9323|988| |120.2179|996| |120.498|994| |120.7782|988| |121.0748|988| |121.355|988| |121.6406|988| |122.2009|996| |122.9041|1472| |123.1842|1476| |123.4644|1476| |124.0906|1394| |124.4366|1364| |124.9365|1424| |125.2332|1442| |126.0736|1112| |126.3593|1104| |126.6394|1098| |126.9196|1094| |127.2162|1090| |127.4963|1086| |127.7765|1086| |128.0621|1088| |128.3423|1086| |128.6389|1086| |128.9191|1086| |129.1992|1086| |129.4794|1086| |129.765|1088| |130.0616|1090| |130.3418|1094| |130.6219|1094| |130.9021|1098| |131.1823|1104| |131.4679|1108| |131.7645|1116| |131.9843|1120| |132.2644|1122| |132.561|1130| |132.8412|1138| |133.1213|1140| |133.4015|1146| |133.6871|1154| |133.9838|1160| |134.2639|1168| |134.4836|1178| |134.7803|1174| |135.0604|1180| |135.3406|1198| |135.6207|1192| |135.9009|1180| |136.1865|1178| |136.4832|1180| |136.7633|1174| |137.1094|1164| |137.3895|1156| |137.6697|1160| |137.9498|1168| |138.23|1168| |138.5266|1168| |138.8123|1170| |139.0265|1178| |141.2018|1366| |141.4819|1362| |141.7621|1348| |142.0422|1344| |142.3279|1342| |142.6245|1338| |142.9047|1330| |143.1848|1324| |143.465|1320| |143.7451|1316| |144.0417|1312| |144.3274|1308| |144.6075|1304| |144.8877|1298| |145.2338|1294| |145.5139|1292| |145.7941|1288| |146.0742|1284| |146.3708|1280| |146.651|1274| |146.9366|1268| |147.2168|1268| |147.4969|1264| |147.7936|1262| |148.0737|1258| |148.3594|1252| |148.6395|1248| |148.9197|1246| |149.2163|1244| |149.4965|1240| |149.7766|1236| |150.0623|1232| |150.4028|1228| |150.683|1224| |150.9686|1220| |151.2488|1218| |151.5454|1216| |151.8256|1214| |152.1057|1210| |152.3859|1208| |152.6715|1204| |152.9681|1202| |153.2483|1200| |153.5284|1198| |153.8086|1194| |154.0887|1190| |154.3744|1188| |154.671|1186| |154.9512|1184| |155.2313|1182| |155.5115|1178| |155.7916|1176| |156.0938|1174| |156.3739|1172| |156.7145|1168| |156.9946|1168| |157.2803|1166| |157.5604|1162| |157.8406|1160| |158.1207|1158| |158.4174|1156| |158.703|1154| |158.9832|1154| |159.2633|1150| |159.5435|1148| |159.8401|1146| |160.1202|1144| |160.4059|1142| |160.686|1142| |160.9662|1140| |161.2628|1138| |161.543|1136| |161.8231|1136| |162.1088|1134| |162.3889|1130| |162.6691|1128| |162.9657|1128| |163.2458|1126| |163.526|1124| |163.8116|1124| |164.0918|1122| |164.3884|1120| |164.6686|1118| |164.9487|1118| |165.2948|1116| |165.575|1114| |165.8551|1114| |166.1353|1112| |166.4374|1112| |166.7175|1112| |166.9977|1110| |167.2778|1108| |167.558|1108| |167.8436|1106| |168.1403|1104| |168.4204|1104| |168.7006|1104| |168.9807|1104| |169.2609|1102| |169.5575|1100| |169.8431|1100| |170.1233|1100| |170.4034|1100| |170.6836|1098| |170.9802|1098| |171.2604|1098| |171.546|1096| |171.8262|1096| |172.1063|1096| |172.3865|1094| |172.6831|1094| |172.9688|1094| |173.2489|1092| |173.5291|1092| |173.8092|1092| |174.1058|1092| |174.386|1090| |174.6716|1090| |174.9518|1092| |175.2319|1090| |175.5286|1090| |175.8087|1090| |176.0889|1090| |176.3745|1090| |176.6547|1090| |176.9348|1090| |177.2314|1090| |177.5116|1090| |177.7917|1090| |178.0774|1090| |178.3575|1090| |178.6542|1090| |178.9343|1090| |179.2145|1090| |179.4946|1090| |179.7803|1090| |180.0769|1090| |180.3571|1090| |180.6372|1090| |180.9174|1090| |181.203|1092| |181.4832|1092| |181.7798|1092| |182.0599|1092| |182.3401|1092| |182.6202|1092| |182.9059|1096| |183.2025|1096| |183.4827|1096| |183.7628|1096| |184.043|1098| |184.3231|1098| |184.6198|1098| |184.9054|1100| |185.1855|1100| |185.4657|1100| |185.7458|1100| |186.026|1102| |186.3281|1102| |186.6083|1102| |186.8884|1102| |187.1686|1104| |187.4487|1106| |187.7454|1108| |188.031|1108| |188.3112|1108| |188.5913|1110| |188.8715|1110| |189.1681|1112| |189.4482|1112| |189.7339|1112| |190.014|1114| |190.2942|1116| |190.5304|1118| |190.8105|1120| |191.0907|1120| |191.3708|1122| |191.6675|1124| |191.9531|1124| |192.2333|1126| |192.5134|1128| |192.7936|1128| |193.0902|1130| |193.3704|1132| |193.656|1134| |193.9362|1136| |194.2163|1138| |194.4965|1138| |194.7931|1140| |195.0732|1142| |195.3589|1142| |195.639|1144| |195.9192|1146| |196.2158|1148| |196.496|1152| |196.7761|1154| |197.0618|1154| |197.3419|1156| |197.6385|1158| |197.9187|1162| |198.1989|1164| |198.479|1164| |198.7811|1166| |199.0613|1170| |199.292|1172| |199.5776|1174| |199.8578|1178| |200.1379|1180| |200.4346|1182| |200.7147|1184| |200.9949|1188| |201.2915|1192| |201.5771|1194| |201.8573|1196| |202.1375|1196| |202.4341|1198| |202.7142|1204| |202.9999|1208| |203.28|1210| |203.5767|1212| |203.8568|1214| |204.137|1216| |204.4336|1220| |204.7137|1224| |204.9994|1228| |205.2301|1230| |205.5103|1232| |205.7959|1236| |206.0925|1238| |206.3727|1244| |206.6528|1246| |206.9495|1250| |207.2296|1252| |207.5153|1256| |207.7954|1262| |208.092|1264| |208.3722|1268| |208.6523|1272| |208.949|1276| |209.2291|1278| |209.5148|1282| |209.7949|1286| |210.0916|1292| |210.3113|1296| |210.6079|1298| |210.8881|1304| |211.1682|1310| |211.4484|1316| |211.745|1318| |212.0306|1320| |212.3108|1324| |212.6074|1332| |212.8876|1338| |213.1677|1342| |213.4479|1348| |213.75|1350| |214.0302|1354| |214.3103|1358| |214.5465|1368| |214.8267|1374| |215.1233|1376| |215.4034|1380| |215.6836|1384| |215.9637|1392| |216.2604|1398| |216.546|1404| |216.8262|1410| |217.1228|1414| |217.403|1420| |217.6831|1426| |217.9688|1436| |218.2654|1442| |218.5455|1444| |218.7762|1448| |219.0619|1456| |219.342|1468| |219.6222|1490| |219.9188|1494| |220.4791|1474| |220.7813|1460| |221.0614|1454| |221.792|1290| |222.0776|1280| |222.3743|1278| |222.6544|1272| |222.9346|1270| |223.2312|1276| |223.5114|1278| |223.7915|1258| |224.3738|1282| |224.6539|1270| |224.9341|1264| |225.2307|1258| |225.5109|1250| |225.7965|1242| |226.0931|1238| |226.3733|1232| |226.7139|1222| |226.9995|1216| |227.2961|1214| |227.5763|1210| |227.8729|1204| |228.1531|1196| |228.4332|1190| |228.7299|1184| |229.0155|1180| |229.3121|1178| |229.6527|1170| |229.9329|1164| |230.2185|1160| |230.5151|1156| |230.7953|1150| |231.0754|1144| |231.3721|1138| |231.6522|1136| |231.9489|1130| |232.229|1126| |232.5146|1122| |232.8113|1118| |233.1519|1112| |233.4375|1110| |233.7177|1106| |234.0143|1102| |234.2944|1098| |234.5911|1094| |234.8712|1090| |235.1514|1096| |235.448|1102| |235.7336|1110| |235.9644|1118| |236.25|1126| |236.5466|1136| |236.8268|1144| |237.1234|1152| |237.4036|1142| |237.6837|1122| |238.0298|1112| |238.3264|1110| |238.6066|1108| |238.8867|1098| |239.1833|1098| |239.9799|1118| |241.2488|1052| |241.5289|1046| |241.8256|1042| |242.1057|1038| |242.4023|1036| |242.6825|1034| |242.9681|1030| |243.2648|1028| |243.5449|1028| |243.8416|1028| |244.1217|1026| |244.4678|1024| |244.6985|1026| |244.9841|1026| |245.2643|1028| |245.5609|1032| |245.8411|1034| |246.1377|1034| |246.4178|1034| |246.698|1038| |246.9946|1042| |247.2803|1046| |247.5769|1050| |247.8571|1054| |248.1372|1060| |248.4338|1062| |248.714|1066| |249.527|1074| |249.9994|1554| |250.2795|1546| |250.5597|1548| |250.8563|1548| |251.1365|1544| |251.4331|1540| |251.7792|1536| |252.0593|1532| |252.6361|1532| |253.3722|988| |253.6523|986| |253.9325|986| |254.2291|988| |254.5587|982| |254.8553|980| |255.0751|996| |255.3717|1004| |255.6519|994| |255.9375|990| |256.2341|988| |256.5143|986| |256.7944|986| |257.0746|986| |257.3712|986| |257.6514|986| |257.937|984| |258.2336|984| |258.5138|984| |258.7939|984| |259.0741|984| |259.3707|984| |259.9365|984| |261.7767|1470| |262.0624|1468| |262.3425|1470| |262.6392|1468| |262.9193|1468| |263.1995|1468| |263.4961|1468| |263.7762|1466| |264.0619|1466| |264.342|1466| |264.6387|1466| |264.9188|1468| |265.199|1468| |265.4791|1466| |265.7813|1474| |266.8579|954| |267.1381|952| |267.4182|952| |267.6984|954| |267.995|950| |268.2806|954| |268.5608|970| |268.8574|974| |269.1376|966| |269.4177|964| |269.6979|962| |270|962| |270.2802|964| |270.5603|964| |270.8405|966| |271.1371|968| |271.4172|970| |271.7029|970| |271.9995|970| |272.2797|970| |272.5598|972| |272.84|972| |273.1366|974| |273.4167|974| |273.7024|976| |273.999|976| |274.2792|978| |274.5593|978| |274.8395|980| |275.1361|982| |275.3558|984| |275.6525|984| |275.9326|984| |276.2183|986| |277.2015|1482| |277.4817|1482| |277.7783|1484| |278.3386|1484| |279.0308|1316| |279.3109|1302| |279.6515|1286| |280.2777|1224| |280.5579|1222| |280.8545|1224| |281.1401|1228| |281.4203|1228| |281.651|1232| |281.9366|1236| |282.2168|1240| |282.5134|1240| |282.7936|1242| |283.0737|1244| |283.3704|1248| |283.656|1250| |283.9362|1250| |284.2163|1252| |284.5129|1254| |284.7931|1256| |285.0732|1264| |285.3589|1276| |285.6555|1280| |285.9357|1286| |286.2158|1290| |286.5125|1292| |286.7926|1292| |287.0728|1292| |287.3584|1294| |287.5891|1300| |287.8748|1310| |288.7317|1312| |289.8248|1404| |290.105|1390| |290.3906|1370| |290.7312|1354| |291.0114|1354| |291.308|1346| |291.5936|1338| |291.8738|1340| |292.1539|1324| |292.4506|1308| |292.7307|1310| |293.0109|1300| |293.3569|1280| |293.6371|1280| |293.9337|1288| |294.2139|1292| |294.7797|1294| |295.0104|1356| |295.2466|1372| |295.5267|1376| |295.8124|1384| |296.109|1388| |296.3892|1394| |297.2461|1410| |298.125|10984| |298.4052|10888| |298.6853|10984| |298.9655|10984| |299.5422|9784| |299.8279|9784| |300.4047|10336| |300.6848|10376| |300.965|10376| |301.5417|9736| |301.8274|9792| |302.1075|9968| |302.4042|10040| |302.6843|9936| |302.9645|9808| |303.2446|9712| |303.5468|9632| |303.8269|9592| |304.1071|9584| |304.3872|9584| |304.6838|9552| |304.964|9472| |305.2496|9408| |305.5463|9384| |305.8264|9336| |306.1066|9280| |306.6833|9200| |307.2491|8304| |307.5458|8480| |307.8259|8608| |308.1061|8696| |308.3862|8728| |308.6829|8720| |308.9685|8712| |309.2487|8664| |309.5288|8584| |309.8254|8520| |310.1056|8464| |310.3857|8408| |310.6714|8368| |310.968|8368| |311.2482|8296| |311.5887|8152| |311.8744|8112| |312.1545|8120| |312.4512|8104| |312.7313|8096| |313.0115|8064| |313.2916|7984| |313.5938|7920| |313.8739|7912| |314.1541|7864| |314.4507|7808| |314.7308|7776| |315.011|7680| |315.2966|7640| |315.5933|7624| |315.8734|7632| |316.1536|7632| |316.4337|7584| |316.7303|7552| |317.0105|7512| |317.8729|7472| |318.1531|6456| |318.7299|6376| |319.2957|7168| |319.5758|7192| |319.8724|7168| |320.1526|7160| |320.4327|7160| |320.7294|7056| |321.015|6896| |321.2952|6904| |321.5753|6976| |321.8719|6976| |322.1521|6960| |322.4323|6912| |322.7179|6888| |323.0145|6904| |323.2947|6912| |323.5748|6912| |323.8715|6912| |324.1516|6872| |324.4373|6856| |324.7174|6816| |325.014|6792| |325.2942|6800| |325.5743|6768| |325.8545|6760| |326.1511|6768| |326.4368|6744| |326.7169|6696| |326.9971|6680| |327.2937|6664| |328.1561|6160| |328.4802|6128| |328.7769|6120| |328.9966|6216| |329.2932|6208| |329.6228|6040| |329.9194|5904| |330.1996|5848| |330.4797|5816| |330.7764|5784| |331.062|5872| |331.5729|6304| |331.8585|6352| |332.1387|6352| |332.4353|6336| |332.7155|6328| |332.9956|6312| |333.2813|6232| |333.9185|5456| |334.1986|5376| |334.4843|5352| |335.061|5408| |335.6213|6072| |335.8575|6168| |336.1377|6184| |336.4343|6152| |336.7639|6104| |337.0605|6064| |337.3407|6048| |337.6208|6048| |337.9175|6056| |338.2031|6048| |338.4833|6040| |338.7634|6048| |339.0601|6024| |339.3402|6032| |339.6204|6056| |339.906|6048| |340.2026|6032| |340.4828|6000| |340.7629|5984| |341.0596|5976| |341.3397|5952| |341.6199|5960| |341.9055|5944| |342.2021|5928| |342.4823|5928| |342.7625|5912| |343.0591|5904| |343.3392|5896| |343.6249|5888| |343.905|5864| |344.2017|5864| |344.4818|5864| |344.762|5856| |345.0586|5856| |345.3387|5848| |345.6244|5840| |345.9045|5848| |346.2012|5848| |346.4813|5848| |346.7615|5856| |347.0581|5848| |347.3438|5856| |347.6239|5848| |347.9041|5840| |348.2007|5832| |348.4808|5840| |348.761|5840| |349.0466|5832| |349.3433|5816| |349.6234|5816| |349.9036|5808| |350.2002|5800| |350.4803|5808| |350.7605|5792| |351.0461|5776| |351.3428|5784| |351.6229|5768| |351.9031|5760| |352.0624|5768| |352.3425|5768| |352.6392|5744| |352.9193|5752| |353.1995|5752| |353.4796|5760| |353.7762|5776| |354.6222|5032| |354.9188|5000| |355.4791|4960| |356.0614|5648| |356.3416|5752| |356.6217|5784| |356.9183|5792| |357.1985|5784| |357.4841|5760| |357.7643|5768| |358.0609|5784| |358.3411|5752| |358.6212|5736| |358.9014|5752| |359.198|5768| |359.4836|5760| |359.7638|5760|

1

There are 1 best solutions below

2
On BEST ANSWER

Follows a MATHEMATICA script easily understood by itself.

data = Import["/home/test/Downloads/scan.csv", "Data"];
data0 = Take[data, {2, Length[data]}];

ceiling = 2000;
floor = -1000;
near = {};
For[k = 1, k <= Length[data0], k++, 
 If[data0[[k, 2]] < ceiling, 
   r = data0[[k, 2]]; 
   a = Pi data0[[k, 1]]/180 + Pi/2; 
   AppendTo[near, {r Cos[a], r Sin[a]}]
 ]
]

gr0 = ListPlot[near, Axes -> False, PlotStyle -> {Black, Thick}];

near2 = {};
For[k = 1, k <= Length[near], k++, 
 If[near[[k, 2]] > floor, AppendTo[near2, near[[k]]]]
]

leftmax = -20000;
rightmin = 20000;
For[k = 1, k <= Length[near2], k++, 
 If[near2[[k, 1]] < 0 && near2[[k, 1]] > leftmax, 
   leftmax = near2[[k, 1]]
 ]
]

For[k = 1, k <= Length[near2], k++, 
 If[near2[[k, 1]] > 0 && near2[[k, 1]] < rightmin, 
 rightmin = near2[[k, 1]]
 ]
]

safe = {{leftmax, ceiling}, {leftmax, floor}, {rightmin, floor},{rightmin, ceiling}, {leftmax, ceiling}};
gr2 = ListLinePlot[safe, PlotStyle -> Red, Axes -> False];
Show[gr0, gr2, PlotRange -> All, AspectRatio -> 1]

enter image description here