| | |
| | | # 割草机地块障碍物配置文件 |
| | | # 生成时间:2025-12-26T18:49:19.310900300 |
| | | # 生成时间:2025-12-26T19:35:23.812685900 |
| | | # 坐标系:WGS84(度分格式) |
| | | |
| | | # ============ 地块基准站配置 ============ |
| | |
| | | #Dikuai Properties |
| | | #Fri Dec 26 18:49:19 CST 2025 |
| | | #Fri Dec 26 19:35:23 CST 2025 |
| | | LAND1.angleThreshold=-1 |
| | | LAND1.baseStationCoordinates=3949.89151752,N,11616.79267501,E |
| | | LAND1.boundaryCoordinates=4.30,87.65;-2.36,-65.51;44.25,-66.72;49.70,-14.05;98.13,-15.87;99.34,-69.75;137.48,-67.93;134.45,90.07;4.30,87.65 |
| | |
| | | LAND1.mowingSafetyDistance=0.53 |
| | | LAND1.mowingTrack=-1 |
| | | LAND1.mowingWidth=0.50 |
| | | LAND1.obstacleCoordinates=25.17,9.94;17.74,67.19;113.88,72.00;120.00,19.12;74.99,-4.48 |
| | | LAND1.plannedPath=-1.807069,-64.994176;43.773311,-66.177447;49.223902,-13.501734;98.648661,-15.359117;99.857663,-69.194695;136.940221,-67.425155;133.930254,89.530244;-1.807069,-64.994176;133.937363,89.159526;-1.481732,-65.002621;-0.831059,-65.019513;133.951582,88.418089;133.965800,87.676653;-0.180385,-65.036404;0.470288,-65.053296;133.980019,86.935216;133.994238,86.193779;1.120962,-65.070188;1.771635,-65.087079;134.008456,85.452343;134.022675,84.710906;2.422309,-65.103971;3.072982,-65.120862;134.036894,83.969470;134.051112,83.228033;3.723656,-65.137754;4.374329,-65.154645;49.154019,-14.177100;49.730548,-13.520774;134.065331,82.486596;134.079550,81.745160;50.374792,-13.544985;49.065156,-15.035885;5.025003,-65.171537;5.675676,-65.188428;48.976294,-15.894669;51.019037,-13.569195;134.093768,81.003723;134.107987,80.262286;51.663281,-13.593406;48.887432,-16.753454;6.326350,-65.205320;6.977023,-65.222211;48.798569,-17.612239;52.307525,-13.617617;134.122206,79.520850;134.136425,78.779413;52.951769,-13.641827;48.709707,-18.471024;7.627697,-65.239103;8.278370,-65.255995;48.620845,-19.329809;53.596013,-13.666038;134.150643,78.037977;134.164862,77.296540;54.240258,-13.690249;48.531983,-20.188593;8.929044,-65.272886;9.579717,-65.289778;48.443120,-21.047378;54.884502,-13.714460;134.179081,76.555103;134.193299,75.813667;55.528746,-13.738670;48.354258,-21.906163;10.230391,-65.306669;10.881064,-65.323561;48.265396,-22.764948;56.172990,-13.762881;134.207518,75.072230;134.221737,74.330793;56.817234,-13.787092;48.176533,-23.623733;11.531738,-65.340452;12.182411,-65.357344;48.087671,-24.482518;57.461479,-13.811302;134.235955,73.589357;134.250174,72.847920;58.105723,-13.835513;47.998809,-25.341302;12.833084,-65.374235;13.483758,-65.391127;47.909946,-26.200087;58.749967,-13.859724;134.264393,72.106484;134.278611,71.365047;59.394211,-13.883934;47.821084,-27.058872;14.134431,-65.408018;14.785105,-65.424910;47.732222,-27.917657;60.038455,-13.908145;134.292830,70.623610;134.307049,69.882174;60.682700,-13.932356;47.643360,-28.776442;15.435778,-65.441802;16.086452,-65.458693;47.554497,-29.635226;61.326944,-13.956567;134.321268,69.140737;134.335486,68.399300;61.971188,-13.980777;47.465635,-30.494011;16.737125,-65.475585;17.387799,-65.492476;47.376773,-31.352796;62.615432,-14.004988;134.349705,67.657864;134.363924,66.916427;63.259676,-14.029199;47.287910,-32.211581;18.038472,-65.509368;18.689146,-65.526259;47.199048,-33.070366;63.903921,-14.053409;134.378142,66.174991;134.392361,65.433554;64.548165,-14.077620;47.110186,-33.929151;19.339819,-65.543151;19.990493,-65.560042;47.021323,-34.787935;65.192409,-14.101831;134.406580,64.692117;134.420798,63.950681;65.836653,-14.126042;46.932461,-35.646720;20.641166,-65.576934;21.291840,-65.593825;46.843599,-36.505505;66.480897,-14.150252;134.435017,63.209244;134.449236,62.467807;67.125142,-14.174463;46.754737,-37.364290;21.942513,-65.610717;22.593187,-65.627609;46.665874,-38.223075;67.769386,-14.198674;134.463454,61.726371;134.477673,60.984934;68.413630,-14.222884;46.577012,-39.081859;23.243860,-65.644500;23.894534,-65.661392;46.488150,-39.940644;69.057874,-14.247095;134.491892,60.243498;134.506110,59.502061;69.702118,-14.271306;46.399287,-40.799429;24.545207,-65.678283;25.195881,-65.695175;46.310425,-41.658214;70.346363,-14.295516;134.520329,58.760624;134.534548,58.019188;70.990607,-14.319727;46.221563,-42.516999;25.846554,-65.712066;26.497228,-65.728958;46.132700,-43.375784;71.634851,-14.343938;134.548767,57.277751;134.562985,56.536314;72.279095,-14.368149;46.043838,-44.234568;27.147901,-65.745849;27.798575,-65.762741;45.954976,-45.093353;72.923339,-14.392359;134.577204,55.794878;134.591423,55.053441;73.567584,-14.416570;45.866114,-45.952138;28.449248,-65.779632;29.099922,-65.796524;45.777251,-46.810923;74.211828,-14.440781;134.605641,54.312005;134.619860,53.570568;74.856072,-14.464991;45.688389,-47.669708;29.750595,-65.813416;30.401269,-65.830307;45.599527,-48.528493;75.500316,-14.489202;134.634079,52.829131;134.648297,52.087695;76.144560,-14.513413;45.510664,-49.387277;31.051942,-65.847199;31.702616,-65.864090;45.421802,-50.246062;76.788805,-14.537623;134.662516,51.346258;134.676735,50.604821;77.433049,-14.561834;45.332940,-51.104847;32.353289,-65.880982;33.003963,-65.897873;45.244077,-51.963632;78.077293,-14.586045;134.690953,49.863385;134.705172,49.121948;78.721537,-14.610256;45.155215,-52.822417;33.654636,-65.914765;34.305310,-65.931656;45.066353,-53.681201;79.365781,-14.634466;134.719391,48.380512;134.733610,47.639075;80.010026,-14.658677;44.977491,-54.539986;34.955983,-65.948548;35.606657,-65.965439;44.888628,-55.398771;80.654270,-14.682888;134.747828,46.897638;134.762047,46.156202;81.298514,-14.707098;44.799766,-56.257556;36.257330,-65.982331;36.908004,-65.999223;44.710904,-57.116341;81.942758,-14.731309;134.776266,45.414765;134.790484,44.673329;82.587002,-14.755520;44.622041,-57.975126;37.558677,-66.016114;38.209351,-66.033006;44.533179,-58.833910;83.231247,-14.779731;134.804703,43.931892;134.818922,43.190455;83.875491,-14.803941;44.444317,-59.692695;38.860024,-66.049897;39.510698,-66.066789;44.355455,-60.551480;84.519735,-14.828152;134.833140,42.449019;134.847359,41.707582;85.163979,-14.852363;44.266592,-61.410265;40.161371,-66.083680;40.812045,-66.100572;44.177730,-62.269050;85.808223,-14.876573;134.861578,40.966145;134.875796,40.224709;86.452468,-14.900784;44.088868,-63.127834;41.462718,-66.117463;42.113392,-66.134355;44.000005,-63.986619;87.096712,-14.924995;134.890015,39.483272;134.904234,38.741836;87.740956,-14.949205;43.911143,-64.845404;42.764065,-66.151246;43.414739,-66.168138;43.822281,-65.704189;88.385200,-14.973416;134.918452,38.000399;134.932671,37.258962;89.029444,-14.997627;89.673689,-15.021838;134.946890,36.517526;134.961109,35.776089;90.317933,-15.046048;90.962177,-15.070259;134.975327,35.034652;134.989546,34.293216;91.606421,-15.094470;92.250665,-15.118680;135.003765,33.551779;135.017983,32.810343;92.894909,-15.142891;93.539154,-15.167102;135.032202,32.068906;135.046421,31.327469;94.183398,-15.191313;94.827642,-15.215523;135.060639,30.586033;135.074858,29.844596;95.471886,-15.239734;96.116130,-15.263945;135.089077,29.103159;135.103295,28.361723;96.760375,-15.288155;97.404619,-15.312366;135.117514,27.620286;135.131733,26.878850;98.048863,-15.336577;98.649805,-15.410083;135.145952,26.137413;135.160170,25.395976;98.666395,-16.148820;98.682985,-16.887557;135.174389,24.654540;135.188608,23.913103;98.699575,-17.626294;98.716165,-18.365031;135.202826,23.171666;135.217045,22.430230;98.732755,-19.103768;98.749345,-19.842505;135.231264,21.688793;135.245482,20.947357;98.765935,-20.581242;98.782526,-21.319979;135.259701,20.205920;135.273920,19.464483;98.799116,-22.058716;98.815706,-22.797453;135.288138,18.723047;135.302357,17.981610;98.832296,-23.536190;98.848886,-24.274928;135.316576,17.240173;135.330794,16.498737;98.865476,-25.013665;98.882066,-25.752402;135.345013,15.757300;135.359232,15.015864;98.898656,-26.491139;98.915246,-27.229876;135.373451,14.274427;135.387669,13.532990;98.931836,-27.968613;98.948426,-28.707350;135.401888,12.791554;135.416107,12.050117;98.965016,-29.446087;98.981606,-30.184824;135.430325,11.308680;135.444544,10.567244;98.998196,-30.923561;99.014786,-31.662298;135.458763,9.825807;135.472981,9.084371;99.031376,-32.401035;99.047966,-33.139772;135.487200,8.342934;135.501419,7.601497;99.064556,-33.878509;99.081146,-34.617246;135.515637,6.860061;135.529856,6.118624;99.097736,-35.355983;99.114326,-36.094720;135.544075,5.377187;135.558294,4.635751;99.130917,-36.833457;99.147507,-37.572194;135.572512,3.894314;135.586731,3.152878;99.164097,-38.310932;99.180687,-39.049669;135.600950,2.411441;135.615168,1.670004;99.197277,-39.788406;99.213867,-40.527143;135.629387,0.928568;135.643606,0.187131;99.230457,-41.265880;99.247047,-42.004617;135.657824,-0.554306;135.672043,-1.295742;99.263637,-42.743354;99.280227,-43.482091;135.686262,-2.037179;135.700480,-2.778615;99.296817,-44.220828;99.313407,-44.959565;135.714699,-3.520052;135.728918,-4.261489;99.329997,-45.698302;99.346587,-46.437039;135.743136,-5.002925;135.757355,-5.744362;99.363177,-47.175776;99.379767,-47.914513;135.771574,-6.485799;135.785793,-7.227235;99.396357,-48.653250;99.412947,-49.391987;135.800011,-7.968672;135.814230,-8.710108;99.429537,-50.130724;99.446127,-50.869461;135.828449,-9.451545;135.842667,-10.192982;99.462718,-51.608198;99.479308,-52.346935;135.856886,-10.934418;135.871105,-11.675855;99.495898,-53.085673;99.512488,-53.824410;135.885323,-12.417292;135.899542,-13.158728;99.529078,-54.563147;99.545668,-55.301884;135.913761,-13.900165;135.927979,-14.641601;99.562258,-56.040621;99.578848,-56.779358;135.942198,-15.383038;135.956417,-16.124475;99.595438,-57.518095;99.612028,-58.256832;135.970636,-16.865911;135.984854,-17.607348;99.628618,-58.995569;99.645208,-59.734306;135.999073,-18.348785;136.013292,-19.090221;99.661798,-60.473043;99.678388,-61.211780;136.027510,-19.831658;136.041729,-20.573094;99.694978,-61.950517;99.711568,-62.689254;136.055948,-21.314531;136.070166,-22.055968;99.728158,-63.427991;99.744748,-64.166728;136.084385,-22.797404;136.098604,-23.538841;99.761338,-64.905465;99.777928,-65.644202;136.112822,-24.280278;136.127041,-25.021714;99.794518,-66.382939;99.811109,-67.121676;136.141260,-25.763151;136.155478,-26.504587;99.827699,-67.860414;99.844289,-68.599151;136.169697,-27.246024;136.183916,-27.987461;99.992306,-69.188270;100.686934,-69.155123;136.198135,-28.728897;136.212353,-29.470334;101.381563,-69.121976;102.076191,-69.088829;136.226572,-30.211771;136.240791,-30.953207;102.770819,-69.055682;103.465448,-69.022535;136.255009,-31.694644;136.269228,-32.436080;104.160076,-68.989388;104.854704,-68.956241;136.283447,-33.177517;136.297665,-33.918954;105.549332,-68.923094;106.243961,-68.889947;136.311884,-34.660390;136.326103,-35.401827;106.938589,-68.856800;107.633217,-68.823653;136.340321,-36.143264;136.354540,-36.884700;108.327845,-68.790507;109.022474,-68.757360;136.368759,-37.626137;136.382978,-38.367573;109.717102,-68.724213;110.411730,-68.691066;136.397196,-39.109010;136.411415,-39.850447;111.106359,-68.657919;111.800987,-68.624772;136.425634,-40.591883;136.439852,-41.333320;112.495615,-68.591625;113.190243,-68.558478;136.454071,-42.074757;136.468290,-42.816193;113.884872,-68.525331;114.579500,-68.492184;136.482508,-43.557630;136.496727,-44.299066;115.274128,-68.459037;115.968756,-68.425890;136.510946,-45.040503;136.525164,-45.781940;116.663385,-68.392744;117.358013,-68.359597;136.539383,-46.523376;136.553602,-47.264813;118.052641,-68.326450;118.747270,-68.293303;136.567821,-48.006249;136.582039,-48.747686;119.441898,-68.260156;120.136526,-68.227009;136.596258,-49.489123;136.610477,-50.230559;120.831154,-68.193862;121.525783,-68.160715;136.624695,-50.971996;136.638914,-51.713433;122.220411,-68.127568;122.915039,-68.094421;136.653133,-52.454869;136.667351,-53.196306;123.609667,-68.061274;124.304296,-68.028127;136.681570,-53.937742;136.695789,-54.679179;124.998924,-67.994981;125.693552,-67.961834;136.710007,-55.420616;136.724226,-56.162052;126.388181,-67.928687;127.082809,-67.895540;136.738445,-56.903489;136.752663,-57.644926;127.777437,-67.862393;128.472065,-67.829246;136.766882,-58.386362;136.781101,-59.127799;129.166694,-67.796099;129.861322,-67.762952;136.795320,-59.869235;136.809538,-60.610672;130.555950,-67.729805;131.250578,-67.696658;136.823757,-61.352109;136.837976,-62.093545;131.945207,-67.663511;132.639835,-67.630364;136.852194,-62.834982;136.866413,-63.576419;133.334463,-67.597217;134.029092,-67.564071;136.880632,-64.317855;136.894850,-65.059292;134.723720,-67.530924;135.418348,-67.497777;136.909069,-65.800728;136.923288,-66.542165;136.112976,-67.464630 |
| | | LAND1.obstacleCoordinates=(25.17,9.94;17.74,67.19;113.88,72.00;120.00,19.12;74.99,-4.48) |
| | | LAND1.plannedPath=134.969746,90.609756;4.290147,88.179908;3.770500,87.673025;3.769779,87.656435;3.769779,-66.199308;4.269779,-66.212288;4.269779,88.160041;4.290147,88.179908;4.769779,88.188827;4.769779,-66.225268;5.269779,-66.238248;5.269779,88.198124;5.769779,88.207421;5.769779,-66.251228;6.269779,-66.264208;6.269779,88.216718;6.769779,88.226015;6.769779,-66.277188;7.269779,-66.290169;7.269779,88.235311;7.769779,88.244608;7.769779,-66.303149;8.269779,-66.316129;8.269779,88.253905;8.769779,88.263202;8.769779,-66.329109;9.269779,-66.342089;9.269779,88.272499;9.769779,88.281796;9.769779,-66.355069;10.269779,-66.368049;10.269779,88.291093;10.769779,88.300390;10.769779,-66.381029;11.269779,-66.394009;11.269779,88.309687;11.769779,88.318984;11.769779,-66.406989;12.269779,-66.419969;12.269779,88.328281;12.769779,88.337578;12.769779,-66.432949;13.269779,-66.445929;13.269779,88.346875;13.769779,88.356172;13.769779,-66.458909;14.269779,-66.471889;14.269779,88.365469;14.769779,88.374766;14.769779,-66.484869;15.269779,-66.497849;15.269779,88.384063;15.769779,88.393360;15.769779,-66.510829;16.269779,-66.523809;16.269779,88.402657;16.769779,88.411954;16.769779,-66.536789;17.269779,-66.549769;17.269779,88.421251;17.769779,88.430548;17.769779,-66.562750;18.269779,-66.575730;18.269779,88.439845;18.769779,88.449142;18.769779,66.710858;19.269779,66.735874;19.269779,88.458439;19.769779,88.467736;19.769779,66.760889;20.269779,66.785905;20.269779,88.477033;20.769779,88.486330;20.769779,66.810921;21.269779,66.835936;21.269779,88.495626;21.769779,88.504923;21.769779,66.860952;22.269779,66.885967;22.269779,88.514220;22.769779,88.523517;22.769779,66.910983;23.269779,66.935999;23.269779,88.532814;23.769779,88.542111;23.769779,66.961014;24.269779,66.986030;24.269779,88.551408;24.769779,88.560705;24.769779,67.011045;25.269779,67.036061;25.269779,88.570002;25.769779,88.579299;25.769779,67.061077;26.269779,67.086092;26.269779,88.588596;26.769779,88.597893;26.769779,67.111108;27.269779,67.136123;27.269779,88.607190;27.769779,88.616487;27.769779,67.161139;28.269779,67.186155;28.269779,88.625784;28.769779,88.635081;28.769779,67.211170;29.269779,67.236186;29.269779,88.644378;29.769779,88.653675;29.769779,67.261201;30.269779,67.286217;30.269779,88.662972;30.769779,88.672269;30.769779,67.311233;31.269779,67.336248;31.269779,88.681566;31.769779,88.690863;31.769779,67.361264;32.269779,67.386279;32.269779,88.700160;32.769779,88.709457;32.769779,67.411295;33.269779,67.436311;33.269779,88.718754;33.769779,88.728051;33.769779,67.461326;34.269779,67.486342;34.269779,88.737348;34.769779,88.746645;34.769779,67.511357;35.269779,67.536373;35.269779,88.755942;35.769779,88.765238;35.769779,67.561389;36.269779,67.586404;36.269779,88.774535;36.769779,88.783832;36.769779,67.611420;37.269779,67.636435;37.269779,88.793129;37.769779,88.802426;37.769779,67.661451;38.269779,67.686467;38.269779,88.811723;38.769779,88.821020;38.769779,67.711482;39.269779,67.736498;39.269779,88.830317;39.769779,88.839614;39.769779,67.761513;40.269779,67.786529;40.269779,88.848911;40.769779,88.858208;40.769779,67.811545;41.269779,67.836560;41.269779,88.867505;41.769779,88.876802;41.769779,67.861576;42.269779,67.886591;42.269779,88.886099;42.769779,88.895396;42.769779,67.911607;43.269779,67.936623;43.269779,88.904693;43.769779,88.913990;43.769779,67.961638;44.269779,67.986654;44.269779,88.923287;44.769779,88.932584;44.769779,68.011669;45.269779,68.036685;45.269779,88.941881;45.769779,88.951178;45.769779,68.061701;46.269779,68.086716;46.269779,88.960475;46.769779,88.969772;46.769779,68.111732;47.269779,68.136747;47.269779,88.979069;47.769779,88.988366;47.769779,68.161763;48.269779,68.186779;48.269779,88.997663;48.769779,89.006960;48.769779,68.211794;49.269779,68.236810;49.269779,89.016257;49.769779,89.025554;49.769779,68.261826;50.269779,68.286841;50.269779,89.034850;50.769779,89.044147;50.769779,68.311857;51.269779,68.336872;51.269779,89.053444;51.769779,89.062741;51.769779,68.361888;52.269779,68.386904;52.269779,89.072038;52.769779,89.081335;52.769779,68.411919;53.269779,68.436935;53.269779,89.090632;53.769779,89.099929;53.769779,68.461950;54.269779,68.486966;54.269779,89.109226;54.769779,89.118523;54.769779,68.511982;55.269779,68.536997;55.269779,89.127820;55.769779,89.137117;55.769779,68.562013;56.269779,68.587028;56.269779,89.146414;56.769779,89.155711;56.769779,68.612044;57.269779,68.637060;57.269779,89.165008;57.769779,89.174305;57.769779,68.662075;58.269779,68.687091;58.269779,89.183602;58.769779,89.192899;58.769779,68.712106;59.269779,68.737122;59.269779,89.202196;59.769779,89.211493;59.769779,68.762138;60.269779,68.787153;60.269779,89.220790;60.769779,89.230087;60.769779,68.812169;61.269779,68.837184;61.269779,89.239384;61.769779,89.248681;61.769779,68.862200;62.269779,68.887216;62.269779,89.257978;62.769779,89.267275;62.769779,68.912231;63.269779,68.937247;63.269779,89.276572;63.769779,89.285869;63.769779,68.962262;64.269779,68.987278;64.269779,89.295165;64.769779,89.304462;64.769779,69.012294;65.269779,69.037309;65.269779,89.313759;65.769779,89.323056;65.769779,69.062325;66.269779,69.087340;66.269779,89.332353;66.769779,89.341650;66.769779,69.112356;67.269779,69.137372;67.269779,89.350947;67.769779,89.360244;67.769779,69.162387;68.269779,69.187403;68.269779,89.369541;68.769779,89.378838;68.769779,69.212418;69.269779,69.237434;69.269779,89.388135;69.769779,89.397432;69.769779,69.262450;70.269779,69.287465;70.269779,89.406729;70.769779,89.416026;70.769779,69.312481;71.269779,69.337496;71.269779,89.425323;71.769779,89.434620;71.769779,69.362512;72.269779,69.387528;72.269779,89.443917;72.769779,89.453214;72.769779,69.412543;73.269779,69.437559;73.269779,89.462511;73.769779,89.471808;73.769779,69.462574;74.269779,69.487590;74.269779,89.481105;74.769779,89.490402;74.769779,69.512606;75.269779,69.537621;75.269779,89.499699;75.769779,89.508996;75.769779,69.562637;76.269779,69.587652;76.269779,89.518293;76.769779,89.527590;76.769779,69.612668;77.269779,69.637684;77.269779,89.536887;77.769779,89.546184;77.769779,69.662699;78.269779,69.687715;78.269779,89.555481;78.769779,89.564777;78.769779,69.712730;79.269779,69.737746;79.269779,89.574074;79.769779,89.583371;79.769779,69.762762;80.269779,69.787777;80.269779,89.592668;80.769779,89.601965;80.769779,69.812793;81.269779,69.837808;81.269779,89.611262;81.769779,89.620559;81.769779,69.862824;82.269779,69.887840;82.269779,89.629856;82.769779,89.639153;82.769779,69.912855;83.269779,69.937871;83.269779,89.648450;83.769779,89.657747;83.769779,69.962886;84.269779,69.987902;84.269779,89.667044;84.769779,89.676341;84.769779,70.012918;85.269779,70.037933;85.269779,89.685638;85.769779,89.694935;85.769779,70.062949;86.269779,70.087964;86.269779,89.704232;86.769779,89.713529;86.769779,70.112980;87.269779,70.137996;87.269779,89.722826;87.769779,89.732123;87.769779,70.163011;88.269779,70.188027;88.269779,89.741420;88.769779,89.750717;88.769779,70.213042;89.269779,70.238058;89.269779,89.760014;89.769779,89.769311;89.769779,70.263074;90.269779,70.288089;90.269779,89.778608;90.769779,89.787905;90.769779,70.313105;91.269779,70.338120;91.269779,89.797202;91.769779,89.806499;91.769779,70.363136;92.269779,70.388152;92.269779,89.815796;92.769779,89.825092;92.769779,70.413167;93.269779,70.438183;93.269779,89.834389;93.769779,89.843686;93.769779,70.463199;94.269779,70.488214;94.269779,89.852983;94.769779,89.862280;94.769779,70.513230;95.269779,70.538245;95.269779,89.871577;95.769779,89.880874;95.769779,70.563261;96.269779,70.588277;96.269779,89.890171;96.769779,89.899468;96.769779,70.613292;97.269779,70.638308;97.269779,89.908765;97.769779,89.918062;97.769779,70.663323;98.269779,70.688339;98.269779,89.927359;98.769779,89.936656;98.769779,70.713355;99.269779,70.738370;99.269779,89.945953;99.769779,89.955250;99.769779,70.763386;100.269779,70.788401;100.269779,89.964547;100.769779,89.973844;100.769779,70.813417;101.269779,70.838433;101.269779,89.983141;101.769779,89.992438;101.769779,70.863448;102.269779,70.888464;102.269779,90.001735;102.769779,90.011032;102.769779,70.913479;103.269779,70.938495;103.269779,90.020329;103.769779,90.029626;103.769779,70.963511;104.269779,70.988526;104.269779,90.038923;104.769779,90.048220;104.769779,71.013542;105.269779,71.038557;105.269779,90.057517;105.769779,90.066814;105.769779,71.063573;106.269779,71.088589;106.269779,90.076111;106.769779,90.085408;106.769779,71.113604;107.269779,71.138620;107.269779,90.094704;107.769779,90.104001;107.769779,71.163635;108.269779,71.188651;108.269779,90.113298;108.769779,90.122595;108.769779,71.213667;109.269779,71.238682;109.269779,90.131892;109.769779,90.141189;109.769779,71.263698;110.269779,71.288713;110.269779,90.150486;110.769779,90.159783;110.769779,71.313729;111.269779,71.338745;111.269779,90.169080;111.769779,90.178377;111.769779,71.363760;112.269779,71.388776;112.269779,90.187674;112.769779,90.196971;112.769779,71.413791;113.269779,71.438807;113.269779,90.206268;113.769779,90.215565;113.769779,68.342323;114.269779,64.022061;114.269779,90.224862;114.769779,90.234159;114.769779,59.701800;115.269779,55.381538;115.269779,90.243456;115.769779,90.252753;115.769779,51.061277;116.269779,46.741016;116.269779,90.262050;116.769779,90.271347;116.769779,42.420754;117.269779,38.100493;117.269779,90.280644;117.769779,90.289941;117.769779,33.780231;118.269779,29.459970;118.269779,90.299238;118.769779,90.308535;118.769779,25.139708;119.269779,20.819447;119.269779,90.317832;119.769779,90.327129;119.769779,-69.305716;119.269779,-69.329575;119.269779,19.335560;118.769779,19.073396;118.769779,-69.353435;118.269779,-69.377294;118.269779,18.811232;117.769779,18.549068;117.769779,-69.401154;117.269779,-69.425013;117.269779,18.286904;116.769779,18.024740;116.769779,-69.448873;116.269779,-69.472732;116.269779,17.762576;115.769779,17.500412;115.769779,-69.496592;115.269779,-69.520451;115.269779,17.238248;114.769779,16.976084;114.769779,-69.544311;114.269779,-69.568170;114.269779,16.713921;113.769779,16.451757;113.769779,-69.592029;113.269779,-69.615889;113.269779,16.189593;112.769779,15.927429;112.769779,-69.639748;112.269779,-69.663608;112.269779,15.665265;111.769779,15.403101;111.769779,-69.687467;111.269779,-69.711327;111.269779,15.140937;110.769779,14.878773;110.769779,-69.735186;110.269779,-69.759046;110.269779,14.616609;109.769779,14.354445;109.769779,-69.782905;109.269779,-69.806765;109.269779,14.092281;108.769779,13.830117;108.769779,-69.830624;108.269779,-69.854484;108.269779,13.567953;107.769779,13.305789;107.769779,-69.878343;107.269779,-69.902203;107.269779,13.043625;106.769779,12.781461;106.769779,-69.926062;106.269779,-69.949921;106.269779,12.519297;105.769779,12.257133;105.769779,-69.973781;105.269779,-69.997640;105.269779,11.994969;104.769779,11.732805;104.769779,-70.021500;104.269779,-70.045359;104.269779,11.470641;103.769779,11.208477;103.769779,-70.069219;103.269779,-70.093078;103.269779,10.946313;102.769779,10.684149;102.769779,-70.116938;102.269779,-70.140797;102.269779,10.421985;101.769779,10.159821;101.769779,-70.164657;101.269779,-70.188516;101.269779,9.897657;100.769779,9.635494;100.769779,-70.212376;100.269779,-70.236235;100.269779,9.373330;99.769779,9.111166;99.769779,-70.260094;99.269779,-70.283954;99.269779,8.849002;98.769779,8.586838;98.769779,-67.964952;120.269779,-69.281856;120.269779,90.336426;120.769779,90.345723;120.769779,-69.257997;121.269779,-69.234137;121.269779,90.355020;121.769779,90.364316;121.769779,-69.210278;122.269779,-69.186419;122.269779,90.373613;122.769779,90.382910;122.769779,-69.162559;123.269779,-69.138700;123.269779,90.392207;123.769779,90.401504;123.769779,-69.114840;124.269779,-69.090981;124.269779,90.410801;124.769779,90.420098;124.769779,-69.067121;125.269779,-69.043262;125.269779,90.429395;125.769779,90.438692;125.769779,-69.019402;126.269779,-68.995543;126.269779,90.447989;126.769779,90.457286;126.769779,-68.971683;127.269779,-68.947824;127.269779,90.466583;127.769779,90.475880;127.769779,-68.923964;128.269779,-68.900105;128.269779,90.485177;128.769779,90.494474;128.769779,-68.876246;129.269779,-68.852386;129.269779,90.503771;129.769779,90.513068;129.769779,-68.828527;130.269779,-68.804667;130.269779,90.522365;130.769779,90.531662;130.769779,-68.780808;131.269779,-68.756948;131.269779,90.540959;131.769779,90.550256;131.769779,-68.733089;132.269779,-68.709229;132.269779,90.559553;132.769779,90.568850;132.769779,-68.685370;133.269779,-68.661510;133.269779,90.578147;133.769779,90.587444;133.769779,-68.637651;134.269779,-68.613791;134.269779,90.596741;134.769779,90.606038;134.769779,-68.589932;135.269779,-68.566072;135.269779,74.964495;135.769779,48.891887;135.769779,-68.542213;136.269779,-68.518354;136.269779,22.819280;136.769779,-3.253327;136.769779,-68.494494;137.269779,-68.470635;137.269779,-29.325935;137.769779,-55.398542;137.769779,-68.446775;98.269779,-45.700489;98.269779,8.324674;97.769779,8.062510;97.769779,-23.436026;97.269779,-16.368047;97.269779,7.800346;96.769779,7.538182;96.769779,-16.349257;96.269779,-16.330467;96.269779,7.276018;95.769779,7.013854;95.769779,-16.311677;95.269779,-16.292887;95.269779,6.751690;94.769779,6.489526;94.769779,-16.274097;94.269779,-16.255307;94.269779,6.227362;93.769779,5.965198;93.769779,-16.236517;93.269779,-16.217727;93.269779,5.703034;92.769779,5.440870;92.769779,-16.198937;92.269779,-16.180147;92.269779,5.178706;91.769779,4.916542;91.769779,-16.161357;91.269779,-16.142567;91.269779,4.654378;90.769779,4.392214;90.769779,-16.123777;90.269779,-16.104987;90.269779,4.130050;89.769779,3.867886;89.769779,-16.086197;89.269779,-16.067407;89.269779,3.605722;88.769779,3.343558;88.769779,-16.048617;88.269779,-16.029827;88.269779,3.081394;87.769779,2.819230;87.769779,-16.011037;87.269779,-15.992247;87.269779,2.557066;86.769779,2.294903;86.769779,-15.973457;86.269779,-15.954667;86.269779,2.032739;85.769779,1.770575;85.769779,-15.935877;85.269779,-15.917087;85.269779,1.508411;84.769779,1.246247;84.769779,-15.898297;84.269779,-15.879507;84.269779,0.984083;83.769779,0.721919;83.769779,-15.860717;83.269779,-15.841927;83.269779,0.459755;82.769779,0.197591;82.769779,-15.823137;82.269779,-15.804347;82.269779,-0.064573;81.769779,-0.326737;81.769779,-15.785557;81.269779,-15.766767;81.269779,-0.588901;80.769779,-0.851065;80.769779,-15.747977;80.269779,-15.729187;80.269779,-1.113229;79.769779,-1.375393;79.769779,-15.710397;79.269779,-15.691607;79.269779,-1.637557;78.769779,-1.899721;78.769779,-15.672817;78.269779,-15.654027;78.269779,-2.161885;77.769779,-2.424049;77.769779,-15.635237;77.269779,-15.616447;77.269779,-2.686213;76.769779,-2.948377;76.769779,-15.597657;76.269779,-15.578867;76.269779,-3.210541;75.769779,-3.472705;75.769779,-15.560077;74.769779,-3.864504;74.269779,-15.503707;74.269779,-3.719783;73.769779,-3.575062;73.769779,-15.484917;73.269779,-15.466127;73.269779,-3.430341;72.769779,-3.285620;72.769779,-15.447337;72.269779,-15.428547;72.269779,-3.140899;71.769779,-2.996178;71.769779,-15.409757;71.269779,-15.390967;71.269779,-2.851457;70.769779,-2.706736;70.769779,-15.372177;70.269779,-15.353387;70.269779,-2.562015;69.769779,-2.417294;69.769779,-15.334597;69.269779,-15.315807;69.269779,-2.272573;68.769779,-2.127852;68.769779,-15.297017;68.269779,-15.278227;68.269779,-1.983131;67.769779,-1.838410;67.769779,-15.259437;67.269779,-15.240647;67.269779,-1.693690;66.769779,-1.548969;66.769779,-15.221857;66.269779,-15.203067;66.269779,-1.404248;65.769779,-1.259527;65.769779,-15.184277;65.269779,-15.165487;65.269779,-1.114806;64.769779,-0.970085;64.769779,-15.146697;64.269779,-15.127907;64.269779,-0.825364;63.769779,-0.680643;63.769779,-15.109117;63.269779,-15.090327;63.269779,-0.535922;62.769779,-0.391201;62.769779,-15.071537;62.269779,-15.052747;62.269779,-0.246480;61.769779,-0.101759;61.769779,-15.033957;61.269779,-15.015167;61.269779,0.042962;60.769779,0.187683;60.769779,-14.996377;60.269779,-14.977587;60.269779,0.332404;59.769779,0.477125;59.769779,-14.958797;59.269779,-14.940007;59.269779,0.621846;58.769779,0.766567;58.769779,-14.921217;58.269779,-14.902427;58.269779,0.911288;57.769779,1.056009;57.769779,-14.883637;57.269779,-14.864847;57.269779,1.200730;56.769779,1.345451;56.769779,-14.846056;56.269779,-14.827266;56.269779,1.490172;55.769779,1.634893;55.769779,-14.808476;55.269779,-14.789686;55.269779,1.779614;54.769779,1.924335;54.769779,-14.770896;54.269779,-14.752106;54.269779,2.069056;53.769779,2.213777;53.769779,-14.733316;53.269779,-14.714526;53.269779,2.358498;52.769779,2.503219;52.769779,-14.695736;52.269779,-14.676946;52.269779,2.647940;51.769779,2.792661;51.769779,-14.658156;51.269779,-14.639366;51.269779,2.937382;50.769779,3.082103;50.769779,-14.620576;50.269779,-14.601786;50.269779,3.226824;49.769779,3.371545;49.769779,-18.525025;49.269779,-23.357135;49.269779,3.516266;48.769779,3.660987;48.769779,-28.189245;48.269779,-33.021355;48.269779,3.805708;47.769779,3.950429;47.769779,-37.853465;47.269779,-42.685575;47.269779,4.095150;46.769779,4.239871;46.769779,-47.517686;46.269779,-52.349796;46.269779,4.384592;45.769779,4.529313;45.769779,-57.181906;45.269779,-62.014016;45.269779,4.674034;44.769779,4.818755;44.769779,-66.846126;44.269779,-67.250692;44.269779,4.963476;43.769779,5.108197;43.769779,-67.237712;43.269779,-67.224732;43.269779,5.252918;42.769779,5.397639;42.769779,-67.211752;42.269779,-67.198772;42.269779,5.542360;41.769779,5.687081;41.769779,-67.185792;41.269779,-67.172812;41.269779,5.831802;40.769779,5.976523;40.769779,-67.159832;40.269779,-67.146852;40.269779,6.121244;39.769779,6.265965;39.769779,-67.133872;39.269779,-67.120892;39.269779,6.410686;38.769779,6.555407;38.769779,-67.107912;38.269779,-67.094931;38.269779,6.700128;37.769779,6.844849;37.769779,-67.081951;37.269779,-67.068971;37.269779,6.989570;36.769779,7.134291;36.769779,-67.055991;36.269779,-67.043011;36.269779,7.279012;35.769779,7.423733;35.769779,-67.030031;35.269779,-67.017051;35.269779,7.568454;34.769779,7.713175;34.769779,-67.004071;34.269779,-66.991091;34.269779,7.857896;33.769779,8.002617;33.769779,-66.978111;33.269779,-66.965131;33.269779,8.147338;32.769779,8.292059;32.769779,-66.952151;32.269779,-66.939171;32.269779,8.436780;31.769779,8.581501;31.769779,-66.926191;31.269779,-66.913211;31.269779,8.726222;30.769779,8.870943;30.769779,-66.900231;30.269779,-66.887251;30.269779,9.015664;29.769779,9.160385;29.769779,-66.874271;29.269779,-66.861291;29.269779,9.305106;28.769779,9.449827;28.769779,-66.848311;28.269779,-66.835331;28.269779,9.594548;27.769779,9.739269;27.769779,-66.822350;27.269779,-66.809370;27.269779,9.883990;26.769779,10.028711;26.769779,-66.796390;26.269779,-66.783410;26.269779,10.173432;25.769779,10.318153;25.769779,-66.770430;25.269779,-66.757450;25.269779,13.289209;24.769779,17.141833;24.769779,-66.744470;24.269779,-66.731490;24.269779,20.994458;23.769779,24.847082;23.769779,-66.718510;23.269779,-66.705530;23.269779,28.699707;22.769779,32.552331;22.769779,-66.692550;22.269779,-66.679570;22.269779,36.404956;21.769779,40.257580;21.769779,-66.666590;21.269779,-66.653610;21.269779,44.110205;20.769779,47.962829;20.769779,-66.640630;20.269779,-66.627650;20.269779,51.815454;19.769779,55.668078;19.769779,-66.614670;19.269779,-66.601690;19.269779,59.520703;18.769779,63.373327;18.769779,-66.588710;3.269779,-66.186328;3.269779,76.157936;2.769779,64.659438;2.769779,-66.173348;2.269779,-66.160368;2.269779,53.160939;1.769779,41.662441;1.769779,-66.147388;1.269779,-66.134408;1.269779,30.163942;0.769779,18.665444;0.769779,-66.121428;0.269779,-66.108448;0.269779,7.166945;-0.230221,-4.331553;-0.230221,-66.095468;-0.730221,-66.082488;-0.730221,-15.830052;-1.230221,-27.328550;-1.230221,-66.069508;-1.730221,-66.056528;-1.730221,-38.827049;-2.230221,-50.325547;-2.230221,-66.043548 |
| | | LAND1.returnPathCoordinates=-1 |
| | | LAND1.returnPathRawCoordinates=-1 |
| | | LAND1.returnPointCoordinates=-1 |
| | | LAND1.updateTime=2025-12-26 18\:49\:19 |
| | | LAND1.updateTime=2025-12-26 19\:35\:23 |
| | | LAND1.userId=-1 |
| | |
| | | #Mower Configuration Properties - Updated |
| | | #Fri Dec 26 18:57:41 CST 2025 |
| | | #Fri Dec 26 19:35:45 CST 2025 |
| | | appVersion=-1 |
| | | boundaryLengthVisible=false |
| | | currentWorkLandNumber=LAND1 |
| | |
| | | handheldMarkerId=1872 |
| | | idleTrailDurationSeconds=60 |
| | | manualBoundaryDrawingMode=false |
| | | mapScale=2.29 |
| | | mapScale=6.83 |
| | | measurementModeEnabled=false |
| | | mowerId=6258 |
| | | serialAutoConnect=true |
| | | serialBaudRate=115200 |
| | | serialPortName=COM15 |
| | | simCardNumber=-1 |
| | | viewCenterX=-67.56 |
| | | viewCenterY=-10.16 |
| | | viewCenterX=-81.98 |
| | | viewCenterY=18.79 |
| | |
| | | */ |
| | | public class ApiConfig { |
| | | |
| | | private static final String DEFAULT_BASE_URL = "http://192.168.100.96:9000"; |
| | | private static final String DEFAULT_BASE_URL = "http://39.99.43.227:9000"; |
| | | private static final int DEFAULT_CONNECT_TIMEOUT = 30000; // 30秒 |
| | | private static final int DEFAULT_READ_TIMEOUT = 60000; // 60秒 |
| | | private static final String DEFAULT_USER_AGENT = "LoginClient/1.0"; |
| | |
| | | |
| | | import java.util.*; |
| | | import java.util.regex.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 异形草地路径规划 - 凹多边形修复版 V12.0 |
| | | * 修改说明: |
| | | * 1. 按照用户要求,先生成无障碍物的完整路径(围边+扫描+连接)。 |
| | | * 2. 对完整路径进行障碍物裁剪。 |
| | | * 3. 对裁剪产生的断点,尝试沿障碍物边界进行连接。 |
| | | * 异形草地路径规划 - 优化完善版 |
| | | * 采用更完善的算法: |
| | | * 1. 使用多边形裁剪库计算更精确的内缩边界 |
| | | * 2. 使用扫描线填充算法生成更优化的路径 |
| | | * 3. 使用可见图算法寻找最优绕行路径 |
| | | * 4. 使用路径优化算法减少空行和转弯 |
| | | */ |
| | | public class YixinglujingHaveObstacel { |
| | | |
| | | private static final double EPS = 1e-8; |
| | | private static final double MIN_SEG_LEN = 0.02; // 忽略小于2cm的碎线 |
| | | |
| | | private static final double EPS = 1e-10; |
| | | private static final double MIN_SEG_LEN = 0.01; // 忽略小于1cm的碎线 |
| | | private static final double CORNER_THRESHOLD = Math.toRadians(30); // 30度以下的角度合并 |
| | | |
| | | public static List<PathSegment> planPath(String coordinates, String obstaclesStr, String widthStr, String marginStr) { |
| | | List<Point> rawPoints = parseCoordinates(coordinates); |
| | | if (rawPoints.size() < 3) return new ArrayList<>(); |
| | | |
| | | double mowWidth = Double.parseDouble(widthStr); |
| | | double safeMargin = Double.parseDouble(marginStr); |
| | | |
| | | // 1. 统一多边形方向为逆时针 (CCW) |
| | | ensureCCW(rawPoints); |
| | | |
| | | // 2. 生成作业内缩边界 |
| | | List<Point> mowingBoundary = getOffsetPolygon(rawPoints, safeMargin); |
| | | if (mowingBoundary.size() < 3) return new ArrayList<>(); |
| | | |
| | | // 3. 解析并外扩障碍物 |
| | | List<Obstacle> obstacles = parseObstacles(obstaclesStr, safeMargin); |
| | | |
| | | // 4. 生成全覆盖路径(不考虑障碍物) |
| | | List<PathSegment> fullPath = generateFullPath(mowingBoundary, mowWidth); |
| | | |
| | | // 5. 裁剪并连接 |
| | | return processObstacles(fullPath, obstacles); |
| | | try { |
| | | // 解析输入参数 |
| | | double mowWidth = Double.parseDouble(widthStr); |
| | | double safeMargin = Double.parseDouble(marginStr); |
| | | |
| | | // 解析多边形和障碍物 |
| | | List<Point> boundary = parseCoordinates(coordinates); |
| | | if (boundary.size() < 3) { |
| | | throw new IllegalArgumentException("地块边界至少需要3个点"); |
| | | } |
| | | |
| | | // 确保多边形为逆时针方向 |
| | | makeCCW(boundary); |
| | | |
| | | // 解析障碍物并外扩 |
| | | List<Obstacle> obstacles = parseAndExpandObstacles(obstaclesStr, safeMargin); |
| | | |
| | | // 生成内缩作业边界(考虑障碍物) |
| | | List<Point> workingArea = computeWorkingArea(boundary, obstacles, safeMargin); |
| | | if (workingArea.isEmpty()) { |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | // 生成完整的全覆盖路径(不考虑障碍物) |
| | | List<PathSegment> fullPath = generateCompleteCoverage(workingArea, mowWidth); |
| | | |
| | | // 用障碍物裁剪路径 |
| | | List<PathSegment> clippedPath = clipPathWithObstacles(fullPath, obstacles); |
| | | |
| | | // 连接和优化路径(限制在作业边界内) |
| | | List<PathSegment> finalPath = connectAndOptimizePath(clippedPath, obstacles, mowWidth, workingArea); |
| | | |
| | | return finalPath; |
| | | |
| | | } catch (Exception e) { |
| | | System.err.println("路径规划错误: " + e.getMessage()); |
| | | e.printStackTrace(); |
| | | return new ArrayList<>(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 生成全覆盖路径(围边 + 扫描 + 连接),不考虑障碍物 |
| | | * 计算作业区域(考虑障碍物) |
| | | */ |
| | | private static List<PathSegment> generateFullPath(List<Point> boundary, double width) { |
| | | private static List<Point> computeWorkingArea(List<Point> boundary, List<Obstacle> obstacles, double margin) { |
| | | // 首先生成内缩边界 |
| | | List<Point> offsetBoundary = offsetPolygon(boundary, -margin); |
| | | |
| | | if (obstacles.isEmpty()) { |
| | | return offsetBoundary; |
| | | } |
| | | |
| | | // 如果存在障碍物,从内缩边界中减去障碍物区域 |
| | | // 简化处理:工作区域仍以内缩边界为主,具体裁剪在路径层面完成 |
| | | makeCCW(offsetBoundary); |
| | | return offsetBoundary; |
| | | } |
| | | |
| | | /** |
| | | * 生成完整的全覆盖路径 |
| | | */ |
| | | private static List<PathSegment> generateCompleteCoverage(List<Point> polygon, double width) { |
| | | List<PathSegment> path = new ArrayList<>(); |
| | | |
| | | // A. 围边路径(首圈) |
| | | for (int i = 0; i < boundary.size(); i++) { |
| | | path.add(new PathSegment(boundary.get(i), boundary.get((i + 1) % boundary.size()), true)); |
| | | } |
| | | |
| | | // B. 扫描路径生成 |
| | | double angle = findOptimalAngle(boundary); |
| | | List<Point> rotPoly = rotatePoints(boundary, -angle); |
| | | // 1. 生成边界路径 |
| | | List<PathSegment> borderPath = generateBorderPath(polygon, width); |
| | | path.addAll(borderPath); |
| | | |
| | | double minY = Double.MAX_VALUE, maxY = -Double.MAX_VALUE; |
| | | for (Point p : rotPoly) { minY = Math.min(minY, p.y); maxY = Math.max(maxY, p.y); } |
| | | |
| | | boolean l2r = true; |
| | | List<PathSegment> scanSegments = new ArrayList<>(); |
| | | for (double y = minY + width / 2; y <= maxY - width / 2; y += width) { |
| | | List<Double> xInters = getXIntersections(rotPoly, y); |
| | | if (xInters.size() < 2) continue; |
| | | Collections.sort(xInters); |
| | | |
| | | List<PathSegment> row = new ArrayList<>(); |
| | | // 凹多边形核心:成对取出交点,跳过中间的空洞 |
| | | for (int i = 0; i < xInters.size() - 1; i += 2) { |
| | | Point s = rotatePoint(new Point(xInters.get(i), y), angle); |
| | | Point e = rotatePoint(new Point(xInters.get(i + 1), y), angle); |
| | | row.add(new PathSegment(s, e, true)); |
| | | } |
| | | |
| | | if (!l2r) { |
| | | Collections.reverse(row); |
| | | for (PathSegment s : row) { Point t = s.start; s.start = s.end; s.end = t; } |
| | | } |
| | | scanSegments.addAll(row); |
| | | l2r = !l2r; |
| | | } |
| | | |
| | | // C. 连接扫描线 |
| | | if (!scanSegments.isEmpty()) { |
| | | Point currentPos = path.isEmpty() ? scanSegments.get(0).start : path.get(path.size() - 1).end; |
| | | for (PathSegment seg : scanSegments) { |
| | | if (distance(currentPos, seg.start) > MIN_SEG_LEN) { |
| | | path.add(new PathSegment(currentPos, seg.start, false)); |
| | | // 2. 生成扫描线路径 |
| | | List<PathSegment> scanLines = generateScanLines(polygon, width); |
| | | |
| | | // 3. 连接扫描线 |
| | | if (!scanLines.isEmpty()) { |
| | | Point currentPos = path.isEmpty() ? scanLines.get(0).start : |
| | | path.get(path.size() - 1).end; |
| | | |
| | | for (PathSegment scanLine : scanLines) { |
| | | // 添加空行连接 |
| | | if (distance(currentPos, scanLine.start) > MIN_SEG_LEN) { |
| | | path.add(new PathSegment(currentPos, scanLine.start, false)); |
| | | } |
| | | path.add(seg); |
| | | currentPos = seg.end; |
| | | path.add(scanLine); |
| | | currentPos = scanLine.end; |
| | | } |
| | | |
| | | // 连接回起点 |
| | | if (distance(currentPos, path.get(0).start) > MIN_SEG_LEN) { |
| | | path.add(new PathSegment(currentPos, path.get(0).start, false)); |
| | | } |
| | | } |
| | | |
| | | |
| | | return path; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 处理障碍物:裁剪路径并生成绕行连接 |
| | | * 生成边界路径(一圈或多圈) |
| | | */ |
| | | private static List<PathSegment> processObstacles(List<PathSegment> fullPath, List<Obstacle> obstacles) { |
| | | List<PathSegment> result = new ArrayList<>(); |
| | | if (fullPath.isEmpty()) return result; |
| | | |
| | | Point currentPos = fullPath.get(0).start; |
| | | |
| | | for (PathSegment seg : fullPath) { |
| | | // 裁剪单条线段 |
| | | List<PathSegment> pieces = clipSegment(seg, obstacles); |
| | | private static List<PathSegment> generateBorderPath(List<Point> polygon, double width) { |
| | | List<PathSegment> border = new ArrayList<>(); |
| | | |
| | | // 根据宽度确定需要多少圈边界 |
| | | int borderPasses = 1; // 至少一圈 |
| | | if (width < 0.3) { |
| | | borderPasses = 2; // 宽度较小,增加边界圈数 |
| | | } |
| | | |
| | | for (int pass = 0; pass < borderPasses; pass++) { |
| | | double offset = pass * width; |
| | | List<Point> offsetPoly = offsetPolygon(polygon, -offset); |
| | | |
| | | for (PathSegment piece : pieces) { |
| | | // 如果有断点,尝试连接 |
| | | if (distance(currentPos, piece.start) > MIN_SEG_LEN) { |
| | | List<PathSegment> detour = findDetour(currentPos, piece.start, obstacles); |
| | | result.addAll(detour); |
| | | } |
| | | result.add(piece); |
| | | currentPos = piece.end; |
| | | if (offsetPoly.size() < 3) break; |
| | | |
| | | for (int i = 0; i < offsetPoly.size(); i++) { |
| | | Point start = offsetPoly.get(i); |
| | | Point end = offsetPoly.get((i + 1) % offsetPoly.size()); |
| | | border.add(new PathSegment(start, end, true)); |
| | | } |
| | | } |
| | | return result; |
| | | |
| | | return border; |
| | | } |
| | | |
| | | private static List<PathSegment> findDetour(Point p1, Point p2, List<Obstacle> obstacles) { |
| | | // 检查断点是否在同一个障碍物上 |
| | | for (Obstacle obs : obstacles) { |
| | | if (obs.isOnBoundary(p1) && obs.isOnBoundary(p2)) { |
| | | return obs.getBoundaryPath(p1, p2); |
| | | } |
| | | } |
| | | // 如果不在同一个障碍物上(理论上较少见,除非跨越了多个障碍物),直接连接 |
| | | List<PathSegment> res = new ArrayList<>(); |
| | | res.add(new PathSegment(p1, p2, false)); |
| | | return res; |
| | | } |
| | | |
| | | private static List<PathSegment> clipSegment(PathSegment seg, List<Obstacle> obstacles) { |
| | | List<PathSegment> result = new ArrayList<>(); |
| | | result.add(seg); |
| | | for (Obstacle obs : obstacles) { |
| | | List<PathSegment> next = new ArrayList<>(); |
| | | for (PathSegment s : result) { |
| | | next.addAll(obs.clip(s)); |
| | | } |
| | | result = next; |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | // --- 几何修正算法 --- |
| | | |
| | | |
| | | /** |
| | | * 修正后的方向判定:鞋带公式 Sum (x2-x1)(y2+y1) |
| | | * 在标准笛卡尔坐标系中,Sum < 0 为逆时针 |
| | | * 生成扫描线路径 |
| | | */ |
| | | private static void ensureCCW(List<Point> pts) { |
| | | double s = 0; |
| | | for (int i = 0; i < pts.size(); i++) { |
| | | Point p1 = pts.get(i), p2 = pts.get((i + 1) % pts.size()); |
| | | s += (p2.x - p1.x) * (p2.y + p1.y); |
| | | private static List<PathSegment> generateScanLines(List<Point> polygon, double width) { |
| | | List<PathSegment> scanLines = new ArrayList<>(); |
| | | |
| | | // 计算最优扫描方向 |
| | | double optimalAngle = calculateOptimalScanAngle(polygon); |
| | | |
| | | // 旋转多边形到扫描方向 |
| | | List<Point> rotatedPoly = rotatePolygon(polygon, -optimalAngle); |
| | | |
| | | // 计算包围盒 |
| | | Bounds bounds = calculateBounds(rotatedPoly); |
| | | |
| | | // 生成扫描线 |
| | | boolean leftToRight = true; |
| | | for (double y = bounds.minY + width / 2; y <= bounds.maxY - width / 2 + EPS; y += width) { |
| | | // 获取水平线与多边形的交点 |
| | | List<Double> intersections = getHorizontalIntersections(rotatedPoly, y); |
| | | |
| | | if (intersections.size() < 2) continue; |
| | | |
| | | // 交点排序并成对处理 |
| | | Collections.sort(intersections); |
| | | List<PathSegment> lineSegments = new ArrayList<>(); |
| | | |
| | | for (int i = 0; i < intersections.size(); i += 2) { |
| | | if (i + 1 >= intersections.size()) break; |
| | | |
| | | double x1 = intersections.get(i); |
| | | double x2 = intersections.get(i + 1); |
| | | |
| | | if (x2 - x1 < MIN_SEG_LEN) continue; |
| | | |
| | | // 旋转回原始坐标系 |
| | | Point start = rotatePoint(new Point(x1, y), optimalAngle); |
| | | Point end = rotatePoint(new Point(x2, y), optimalAngle); |
| | | |
| | | lineSegments.add(new PathSegment(start, end, true)); |
| | | } |
| | | |
| | | // 方向交替 |
| | | if (!leftToRight) { |
| | | Collections.reverse(lineSegments); |
| | | for (PathSegment seg : lineSegments) { |
| | | Point temp = seg.start; |
| | | seg.start = seg.end; |
| | | seg.end = temp; |
| | | } |
| | | } |
| | | |
| | | scanLines.addAll(lineSegments); |
| | | leftToRight = !leftToRight; |
| | | } |
| | | if (s > 0) Collections.reverse(pts); |
| | | |
| | | return scanLines; |
| | | } |
| | | |
| | | /** |
| | | * 用障碍物裁剪路径 |
| | | */ |
| | | private static List<PathSegment> clipPathWithObstacles(List<PathSegment> path, List<Obstacle> obstacles) { |
| | | if (obstacles.isEmpty()) return path; |
| | | |
| | | List<PathSegment> clipped = new ArrayList<>(); |
| | | |
| | | for (PathSegment segment : path) { |
| | | List<PathSegment> remaining = new ArrayList<>(); |
| | | remaining.add(segment); |
| | | |
| | | // 依次用每个障碍物裁剪 |
| | | for (Obstacle obstacle : obstacles) { |
| | | List<PathSegment> temp = new ArrayList<>(); |
| | | for (PathSegment seg : remaining) { |
| | | temp.addAll(obstacle.clipSegment(seg)); |
| | | } |
| | | remaining = temp; |
| | | } |
| | | |
| | | clipped.addAll(remaining); |
| | | } |
| | | |
| | | return clipped; |
| | | } |
| | | |
| | | /** |
| | | * 连接和优化路径 |
| | | */ |
| | | private static List<PathSegment> connectAndOptimizePath(List<PathSegment> segments, |
| | | List<Obstacle> obstacles, |
| | | double width, |
| | | List<Point> workingArea) { |
| | | if (segments.isEmpty()) return new ArrayList<>(); |
| | | |
| | | // 1. 先按类型分组:割草段和连接段 |
| | | List<PathSegment> mowingSegments = segments.stream() |
| | | .filter(s -> s.isMowing) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 2. 使用旅行商问题(TSP)的近似算法连接割草段 |
| | | List<PathSegment> connectedPath = connectSegmentsTSP(mowingSegments, obstacles, workingArea); |
| | | |
| | | // 3. 优化路径:合并小段、平滑转角 |
| | | connectedPath = optimizePath(connectedPath, width); |
| | | |
| | | return connectedPath; |
| | | } |
| | | |
| | | /** |
| | | * 使用旅行商问题近似算法连接路径段 |
| | | */ |
| | | private static List<PathSegment> connectSegmentsTSP(List<PathSegment> segments, List<Obstacle> obstacles, List<Point> workingArea) { |
| | | List<PathSegment> connected = new ArrayList<>(); |
| | | |
| | | if (segments.isEmpty()) return connected; |
| | | |
| | | // 构建点集(所有线段的端点) |
| | | List<Point> points = new ArrayList<>(); |
| | | for (PathSegment seg : segments) { |
| | | points.add(seg.start); |
| | | points.add(seg.end); |
| | | } |
| | | |
| | | // 使用最近邻算法构建路径 |
| | | boolean[] visited = new boolean[segments.size()]; |
| | | Point currentPos = segments.get(0).start; |
| | | |
| | | while (true) { |
| | | int bestIdx = -1; |
| | | double bestDist = Double.MAX_VALUE; |
| | | boolean useStart = true; |
| | | |
| | | // 寻找最近的未访问线段 |
| | | for (int i = 0; i < segments.size(); i++) { |
| | | if (visited[i]) continue; |
| | | |
| | | PathSegment seg = segments.get(i); |
| | | double distToStart = distance(currentPos, seg.start); |
| | | double distToEnd = distance(currentPos, seg.end); |
| | | |
| | | if (distToStart < bestDist) { |
| | | bestDist = distToStart; |
| | | bestIdx = i; |
| | | useStart = true; |
| | | } |
| | | if (distToEnd < bestDist) { |
| | | bestDist = distToEnd; |
| | | bestIdx = i; |
| | | useStart = false; |
| | | } |
| | | } |
| | | |
| | | if (bestIdx == -1) break; |
| | | |
| | | // 添加连接路径 |
| | | PathSegment bestSeg = segments.get(bestIdx); |
| | | Point targetPoint = useStart ? bestSeg.start : bestSeg.end; |
| | | |
| | | if (distance(currentPos, targetPoint) > MIN_SEG_LEN) { |
| | | // 寻找安全连接路径(受作业边界限制) |
| | | List<PathSegment> detour = findSafePath(currentPos, targetPoint, obstacles, workingArea); |
| | | connected.addAll(detour); |
| | | } |
| | | |
| | | // 添加割草线段(可能反转方向) |
| | | PathSegment toAdd = bestSeg; |
| | | if (!useStart) { |
| | | toAdd = new PathSegment(bestSeg.end, bestSeg.start, true); |
| | | } |
| | | connected.add(toAdd); |
| | | |
| | | currentPos = toAdd.end; |
| | | visited[bestIdx] = true; |
| | | } |
| | | |
| | | return connected; |
| | | } |
| | | |
| | | /** |
| | | * 寻找安全路径(A*算法) |
| | | */ |
| | | private static List<PathSegment> findSafePath(Point start, Point end, List<Obstacle> obstacles, List<Point> workingArea) { |
| | | // 如果直线路径安全,直接使用 |
| | | if (isLineSafe(start, end, obstacles, workingArea)) { |
| | | List<PathSegment> direct = new ArrayList<>(); |
| | | direct.add(new PathSegment(start, end, false)); |
| | | return direct; |
| | | } |
| | | |
| | | // 否则使用A*算法寻找绕行路径 |
| | | return aStarPathFinding(start, end, obstacles, workingArea); |
| | | } |
| | | |
| | | /** |
| | | * A*算法路径寻找 |
| | | */ |
| | | private static List<PathSegment> aStarPathFinding(Point start, Point end, List<Obstacle> obstacles, List<Point> workingArea) { |
| | | // 简化的A*算法实现 |
| | | // 这里我们使用障碍物边界上的关键点作为路径节点 |
| | | |
| | | List<Point> nodes = new ArrayList<>(); |
| | | nodes.add(start); |
| | | nodes.add(end); |
| | | |
| | | // 添加障碍物的顶点作为候选节点 |
| | | for (Obstacle obs : obstacles) { |
| | | nodes.addAll(obs.getKeyPoints()); |
| | | } |
| | | // 添加作业边界顶点,允许贴边绕行 |
| | | if (workingArea != null && workingArea.size() >= 3) { |
| | | nodes.addAll(workingArea); |
| | | } |
| | | |
| | | // 构建图 |
| | | Map<Point, Map<Point, Double>> graph = new HashMap<>(); |
| | | for (Point p1 : nodes) { |
| | | graph.put(p1, new HashMap<>()); |
| | | for (Point p2 : nodes) { |
| | | if (p1 == p2) continue; |
| | | if (isLineSafe(p1, p2, obstacles, workingArea)) { |
| | | graph.get(p1).put(p2, distance(p1, p2)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // A*搜索 |
| | | Map<Point, Double> gScore = new HashMap<>(); |
| | | Map<Point, Double> fScore = new HashMap<>(); |
| | | Map<Point, Point> cameFrom = new HashMap<>(); |
| | | PriorityQueue<Point> openSet = new PriorityQueue<>( |
| | | Comparator.comparingDouble(p -> fScore.getOrDefault(p, Double.MAX_VALUE)) |
| | | ); |
| | | |
| | | gScore.put(start, 0.0); |
| | | fScore.put(start, heuristic(start, end)); |
| | | openSet.add(start); |
| | | |
| | | while (!openSet.isEmpty()) { |
| | | Point current = openSet.poll(); |
| | | |
| | | if (current.equals(end)) { |
| | | return reconstructPath(cameFrom, current); |
| | | } |
| | | |
| | | for (Map.Entry<Point, Double> neighborEntry : graph.getOrDefault(current, new HashMap<>()).entrySet()) { |
| | | Point neighbor = neighborEntry.getKey(); |
| | | double tentativeGScore = gScore.get(current) + neighborEntry.getValue(); |
| | | |
| | | if (tentativeGScore < gScore.getOrDefault(neighbor, Double.MAX_VALUE)) { |
| | | cameFrom.put(neighbor, current); |
| | | gScore.put(neighbor, tentativeGScore); |
| | | fScore.put(neighbor, tentativeGScore + heuristic(neighbor, end)); |
| | | |
| | | if (!openSet.contains(neighbor)) { |
| | | openSet.add(neighbor); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 如果没有找到路径,不做不安全的连接 |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | /** |
| | | * 重构路径 |
| | | */ |
| | | private static List<PathSegment> reconstructPath(Map<Point, Point> cameFrom, Point current) { |
| | | List<Point> pathPoints = new ArrayList<>(); |
| | | while (current != null) { |
| | | pathPoints.add(current); |
| | | current = cameFrom.get(current); |
| | | } |
| | | Collections.reverse(pathPoints); |
| | | |
| | | List<PathSegment> path = new ArrayList<>(); |
| | | for (int i = 0; i < pathPoints.size() - 1; i++) { |
| | | path.add(new PathSegment(pathPoints.get(i), pathPoints.get(i + 1), false)); |
| | | } |
| | | return path; |
| | | } |
| | | |
| | | /** |
| | | * 启发函数 |
| | | */ |
| | | private static double heuristic(Point a, Point b) { |
| | | return distance(a, b); |
| | | } |
| | | |
| | | /** |
| | | * 优化路径 |
| | | */ |
| | | private static List<PathSegment> optimizePath(List<PathSegment> path, double width) { |
| | | if (path.size() <= 1) return path; |
| | | |
| | | List<PathSegment> optimized = new ArrayList<>(); |
| | | PathSegment current = path.get(0); |
| | | |
| | | for (int i = 1; i < path.size(); i++) { |
| | | PathSegment next = path.get(i); |
| | | |
| | | // 检查是否可以合并当前线段和下一线段 |
| | | if (canMergeSegments(current, next, width)) { |
| | | // 合并线段 |
| | | current = mergeSegments(current, next); |
| | | } else { |
| | | // 添加当前线段,开始新的合并 |
| | | optimized.add(current); |
| | | current = next; |
| | | } |
| | | } |
| | | |
| | | optimized.add(current); |
| | | |
| | | // 平滑转角 |
| | | optimized = smoothCorners(optimized, width); |
| | | |
| | | return optimized; |
| | | } |
| | | |
| | | /** |
| | | * 检查是否可以合并两个线段 |
| | | */ |
| | | private static boolean canMergeSegments(PathSegment a, PathSegment b, double width) { |
| | | if (!a.isMowing || !b.isMowing) return false; |
| | | |
| | | // 检查端点是否重合 |
| | | if (!a.end.equals(b.start) && !a.end.equals(b.end)) return false; |
| | | |
| | | // 检查方向是否一致 |
| | | Point dir1 = new Point(a.end.x - a.start.x, a.end.y - a.start.y); |
| | | Point dir2; |
| | | if (a.end.equals(b.start)) { |
| | | dir2 = new Point(b.end.x - b.start.x, b.end.y - b.start.y); |
| | | } else { |
| | | dir2 = new Point(b.start.x - b.end.x, b.start.y - b.end.y); |
| | | } |
| | | |
| | | double angle = angleBetween(dir1, dir2); |
| | | return angle < Math.toRadians(10); // 角度小于10度可以合并 |
| | | } |
| | | |
| | | /** |
| | | * 合并两个线段 |
| | | */ |
| | | private static PathSegment mergeSegments(PathSegment a, PathSegment b) { |
| | | Point newEnd = a.end.equals(b.start) ? b.end : b.start; |
| | | return new PathSegment(a.start, newEnd, true); |
| | | } |
| | | |
| | | /** |
| | | * 平滑转角 |
| | | */ |
| | | private static List<PathSegment> smoothCorners(List<PathSegment> path, double width) { |
| | | if (path.size() < 3) return path; |
| | | |
| | | List<PathSegment> smoothed = new ArrayList<>(); |
| | | smoothed.add(path.get(0)); |
| | | |
| | | for (int i = 1; i < path.size() - 1; i++) { |
| | | PathSegment prev = path.get(i - 1); |
| | | PathSegment curr = path.get(i); |
| | | PathSegment next = path.get(i + 1); |
| | | |
| | | if (!prev.isMowing || !curr.isMowing || !next.isMowing) { |
| | | smoothed.add(curr); |
| | | continue; |
| | | } |
| | | |
| | | // 计算转角 |
| | | Point inVec = new Point(curr.start.x - prev.end.x, curr.start.y - prev.end.y); |
| | | Point outVec = new Point(next.start.x - curr.end.x, next.start.y - curr.end.y); |
| | | |
| | | double angle = angleBetween(inVec, outVec); |
| | | |
| | | if (angle < CORNER_THRESHOLD) { |
| | | // 小角度,可以直接连接 |
| | | PathSegment direct = new PathSegment(prev.end, next.start, true); |
| | | smoothed.remove(smoothed.size() - 1); // 移除上一个线段 |
| | | smoothed.add(direct); |
| | | i++; // 跳过下一个线段 |
| | | } else { |
| | | smoothed.add(curr); |
| | | } |
| | | } |
| | | |
| | | if (path.size() > 1) { |
| | | smoothed.add(path.get(path.size() - 1)); |
| | | } |
| | | |
| | | return smoothed; |
| | | } |
| | | |
| | | // ==================== 几何计算工具 ==================== |
| | | |
| | | /** |
| | | * 多边形偏移算法 |
| | | */ |
| | | private static List<Point> offsetPolygon(List<Point> polygon, double d) { |
| | | // 基于“偏移边直线交点”的较稳健实现。约定polygon为CCW,左法向量为外侧。 |
| | | if (polygon == null || polygon.size() < 3) return new ArrayList<>(); |
| | | List<Point> poly = new ArrayList<>(polygon); |
| | | makeCCW(poly); |
| | | int n = poly.size(); |
| | | List<Point> out = new ArrayList<>(n); |
| | | |
| | | private static List<Point> getOffsetPolygon(List<Point> pts, double offset) { |
| | | List<Point> result = new ArrayList<>(); |
| | | int n = pts.size(); |
| | | for (int i = 0; i < n; i++) { |
| | | Point p1 = pts.get((i - 1 + n) % n), p2 = pts.get(i), p3 = pts.get((i + 1) % n); |
| | | double v1x = p2.x - p1.x, v1y = p2.y - p1.y; |
| | | double v2x = p3.x - p2.x, v2y = p3.y - p2.y; |
| | | double l1 = Math.hypot(v1x, v1y), l2 = Math.hypot(v2x, v2y); |
| | | if (l1 < EPS || l2 < EPS) continue; |
| | | Point A = poly.get((i - 1 + n) % n); |
| | | Point B = poly.get(i); |
| | | Point C = poly.get((i + 1) % n); |
| | | |
| | | // 法向量偏移(逆时针向左偏移即为内缩) |
| | | double n1x = -v1y / l1, n1y = v1x / l1; |
| | | double n2x = -v2y / l2, n2y = v2x / l2; |
| | | double bx = n1x + n2x, by = n1y + n2y; |
| | | double bl = Math.hypot(bx, by); |
| | | if (bl < EPS) { bx = n1x; by = n1y; } else { bx /= bl; by /= bl; } |
| | | double dist = offset / Math.max(Math.abs(n1x * bx + n1y * by), 0.1); |
| | | result.add(new Point(p2.x + bx * dist, p2.y + by * dist)); |
| | | Point e1 = normalize(subtract(B, A)); |
| | | Point e2 = normalize(subtract(C, B)); |
| | | Point n1 = new Point(-e1.y, e1.x); |
| | | Point n2 = new Point(-e2.y, e2.x); |
| | | |
| | | Point p1 = add(B, multiply(n1, d)); |
| | | Point p2 = add(B, multiply(n2, d)); |
| | | |
| | | Point dir1 = e1; |
| | | Point dir2 = e2; |
| | | |
| | | Point inter = intersectLines(p1, dir1, p2, dir2); |
| | | if (inter == null) { |
| | | // 平行或数值不稳定时退化 |
| | | Point avgN = add(n1, n2); |
| | | if (magnitude(avgN) < EPS) avgN = n1; |
| | | else avgN = normalize(avgN); |
| | | inter = add(B, multiply(avgN, d)); |
| | | } |
| | | out.add(inter); |
| | | } |
| | | return result; |
| | | return out; |
| | | } |
| | | |
| | | private static List<Double> getXIntersections(List<Point> poly, double y) { |
| | | List<Double> res = new ArrayList<>(); |
| | | for (int i = 0; i < poly.size(); i++) { |
| | | Point p1 = poly.get(i), p2 = poly.get((i + 1) % poly.size()); |
| | | // 标准相交判断:一开一闭避免重复计算顶点 |
| | | if ((p1.y <= y && p2.y > y) || (p2.y <= y && p1.y > y)) { |
| | | res.add(p1.x + (y - p1.y) * (p2.x - p1.x) / (p2.y - p1.y)); |
| | | // 计算两条参数直线的交点 p=p0+t*v, q=q0+s*w |
| | | private static Point intersectLines(Point p0, Point v, Point q0, Point w) { |
| | | double det = v.x * w.y - v.y * w.x; |
| | | if (Math.abs(det) < EPS) return null; |
| | | double t = ((q0.x - p0.x) * w.y - (q0.y - p0.y) * w.x) / det; |
| | | return new Point(p0.x + t * v.x, p0.y + t * v.y); |
| | | } |
| | | |
| | | /** |
| | | * 计算最优扫描角度 |
| | | */ |
| | | private static double calculateOptimalScanAngle(List<Point> polygon) { |
| | | double bestAngle = 0; |
| | | double minSpan = Double.MAX_VALUE; |
| | | |
| | | // 尝试多个角度 |
| | | for (int i = 0; i < 180; i += 5) { |
| | | double angle = Math.toRadians(i); |
| | | List<Point> rotated = rotatePolygon(polygon, angle); |
| | | |
| | | Bounds bounds = calculateBounds(rotated); |
| | | double span = bounds.maxY - bounds.minY; |
| | | |
| | | if (span < minSpan) { |
| | | minSpan = span; |
| | | bestAngle = angle; |
| | | } |
| | | } |
| | | return res; |
| | | |
| | | return bestAngle; |
| | | } |
| | | |
| | | /** |
| | | * 获取水平线与多边形的交点 |
| | | */ |
| | | private static List<Double> getHorizontalIntersections(List<Point> polygon, double y) { |
| | | List<Double> intersections = new ArrayList<>(); |
| | | int n = polygon.size(); |
| | | |
| | | for (int i = 0; i < n; i++) { |
| | | Point p1 = polygon.get(i); |
| | | Point p2 = polygon.get((i + 1) % n); |
| | | |
| | | // 检查边是否与水平线相交 |
| | | if ((p1.y <= y && p2.y >= y) || (p1.y >= y && p2.y <= y)) { |
| | | if (Math.abs(p2.y - p1.y) < EPS) { |
| | | // 水平边,跳过 |
| | | continue; |
| | | } |
| | | |
| | | double t = (y - p1.y) / (p2.y - p1.y); |
| | | if (t >= -EPS && t <= 1 + EPS) { |
| | | double x = p1.x + t * (p2.x - p1.x); |
| | | intersections.add(x); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 去重并排序 |
| | | intersections = intersections.stream() |
| | | .distinct() |
| | | .sorted() |
| | | .collect(Collectors.toList()); |
| | | |
| | | return intersections; |
| | | } |
| | | |
| | | /** |
| | | * 判断直线是否安全 |
| | | */ |
| | | private static boolean isLineSafe(Point p1, Point p2, List<Obstacle> obstacles, List<Point> workingArea) { |
| | | // 必须完全在作业内缩边界内 |
| | | if (workingArea != null && !isSegmentInsidePolygon(p1, p2, workingArea)) { |
| | | return false; |
| | | } |
| | | for (Obstacle obs : obstacles) { |
| | | if (obs.doesSegmentIntersect(p1, p2)) { |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | // --- 障碍物模型 --- |
| | | // 判断线段是否位于多边形内部(不越界) |
| | | private static boolean isSegmentInsidePolygon(Point a, Point b, List<Point> polygon) { |
| | | if (polygon == null || polygon.size() < 3) return true; |
| | | // 中点在内 |
| | | Point mid = new Point((a.x + b.x) / 2.0, (a.y + b.y) / 2.0); |
| | | if (!pointInPolygon(mid, polygon)) return false; |
| | | // 不与边界相交(允许端点接触) |
| | | int n = polygon.size(); |
| | | for (int i = 0; i < n; i++) { |
| | | Point p1 = polygon.get(i); |
| | | Point p2 = polygon.get((i + 1) % n); |
| | | if (lineSegmentIntersection(a, b, p1, p2)) { |
| | | // 忽略仅在端点处的小接触 |
| | | if (distance(a, p1) < EPS || distance(a, p2) < EPS || distance(b, p1) < EPS || distance(b, p2) < EPS) { |
| | | continue; |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | private static boolean pointInPolygon(Point p, List<Point> poly) { |
| | | boolean inside = false; |
| | | for (int i = 0, j = poly.size() - 1; i < poly.size(); j = i++) { |
| | | Point pi = poly.get(i), pj = poly.get(j); |
| | | boolean intersect = ((pi.y > p.y) != (pj.y > p.y)) && |
| | | (p.x < (pj.x - pi.x) * (p.y - pi.y) / (pj.y - pi.y + EPS) + pi.x); |
| | | if (intersect) inside = !inside; |
| | | } |
| | | return inside; |
| | | } |
| | | |
| | | // ==================== 向量运算工具 ==================== |
| | | |
| | | private static Point add(Point a, Point b) { |
| | | return new Point(a.x + b.x, a.y + b.y); |
| | | } |
| | | |
| | | private static Point subtract(Point a, Point b) { |
| | | return new Point(a.x - b.x, a.y - b.y); |
| | | } |
| | | |
| | | private static Point multiply(Point p, double scalar) { |
| | | return new Point(p.x * scalar, p.y * scalar); |
| | | } |
| | | |
| | | private static Point normalize(Point p) { |
| | | double mag = magnitude(p); |
| | | if (mag < EPS) return p; |
| | | return new Point(p.x / mag, p.y / mag); |
| | | } |
| | | |
| | | private static double magnitude(Point p) { |
| | | return Math.sqrt(p.x * p.x + p.y * p.y); |
| | | } |
| | | |
| | | private static double dot(Point a, Point b) { |
| | | return a.x * b.x + a.y * b.y; |
| | | } |
| | | |
| | | private static double angleBetween(Point a, Point b) { |
| | | double dotProd = dot(a, b); |
| | | double magA = magnitude(a); |
| | | double magB = magnitude(b); |
| | | |
| | | if (magA < EPS || magB < EPS) return 0; |
| | | |
| | | double cosAngle = dotProd / (magA * magB); |
| | | cosAngle = Math.max(-1, Math.min(1, cosAngle)); |
| | | return Math.acos(cosAngle); |
| | | } |
| | | |
| | | private static double distance(Point a, Point b) { |
| | | return magnitude(subtract(a, b)); |
| | | } |
| | | |
| | | private static Point rotatePoint(Point p, double angle) { |
| | | double cos = Math.cos(angle); |
| | | double sin = Math.sin(angle); |
| | | return new Point(p.x * cos - p.y * sin, p.x * sin + p.y * cos); |
| | | } |
| | | |
| | | private static List<Point> rotatePolygon(List<Point> polygon, double angle) { |
| | | return polygon.stream() |
| | | .map(p -> rotatePoint(p, angle)) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | private static Bounds calculateBounds(List<Point> points) { |
| | | double minX = Double.MAX_VALUE, maxX = -Double.MAX_VALUE; |
| | | double minY = Double.MAX_VALUE, maxY = -Double.MAX_VALUE; |
| | | |
| | | for (Point p : points) { |
| | | minX = Math.min(minX, p.x); |
| | | maxX = Math.max(maxX, p.x); |
| | | minY = Math.min(minY, p.y); |
| | | maxY = Math.max(maxY, p.y); |
| | | } |
| | | |
| | | return new Bounds(minX, maxX, minY, maxY); |
| | | } |
| | | |
| | | private static void makeCCW(List<Point> polygon) { |
| | | double area = 0; |
| | | int n = polygon.size(); |
| | | |
| | | for (int i = 0; i < n; i++) { |
| | | Point p1 = polygon.get(i); |
| | | Point p2 = polygon.get((i + 1) % n); |
| | | area += (p2.x - p1.x) * (p2.y + p1.y); |
| | | } |
| | | |
| | | if (area > 0) { |
| | | Collections.reverse(polygon); |
| | | } |
| | | } |
| | | |
| | | // ==================== 障碍物处理 ==================== |
| | | |
| | | private static List<Obstacle> parseAndExpandObstacles(String obstaclesStr, double margin) { |
| | | List<Obstacle> obstacles = new ArrayList<>(); |
| | | |
| | | if (obstaclesStr == null || obstaclesStr.trim().isEmpty()) { |
| | | return obstacles; |
| | | } |
| | | |
| | | // 解析障碍物字符串 |
| | | Pattern pattern = Pattern.compile("\\(([^)]+)\\)"); |
| | | Matcher matcher = pattern.matcher(obstaclesStr); |
| | | |
| | | while (matcher.find()) { |
| | | String coords = matcher.group(1); |
| | | List<Point> points = parseCoordinates(coords); |
| | | |
| | | if (points.size() == 2) { |
| | | // 圆形障碍物 |
| | | Point center = points.get(0); |
| | | double radius = distance(center, points.get(1)) + margin; |
| | | obstacles.add(new CircularObstacle(center, radius)); |
| | | } else if (points.size() >= 3) { |
| | | // 多边形障碍物 |
| | | makeCCW(points); |
| | | List<Point> expanded = offsetPolygon(points, margin); |
| | | obstacles.add(new PolygonalObstacle(expanded)); |
| | | } |
| | | } |
| | | |
| | | return obstacles; |
| | | } |
| | | |
| | | private static List<Point> parseCoordinates(String str) { |
| | | List<Point> points = new ArrayList<>(); |
| | | |
| | | if (str == null || str.trim().isEmpty()) { |
| | | return points; |
| | | } |
| | | |
| | | String[] tokens = str.split(";"); |
| | | for (String token : tokens) { |
| | | token = token.trim(); |
| | | if (token.isEmpty()) continue; |
| | | |
| | | String[] xy = token.split(","); |
| | | if (xy.length == 2) { |
| | | try { |
| | | double x = Double.parseDouble(xy[0].trim()); |
| | | double y = Double.parseDouble(xy[1].trim()); |
| | | points.add(new Point(x, y)); |
| | | } catch (NumberFormatException e) { |
| | | System.err.println("无效坐标: " + token); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return points; |
| | | } |
| | | |
| | | // ==================== 内部类定义 ==================== |
| | | |
| | | /** |
| | | * 障碍物基类 |
| | | */ |
| | | abstract static class Obstacle { |
| | | abstract List<PathSegment> clip(PathSegment seg); |
| | | abstract boolean isInside(Point p); |
| | | abstract boolean isOnBoundary(Point p); |
| | | abstract List<PathSegment> getBoundaryPath(Point p1, Point p2); |
| | | abstract List<PathSegment> clipSegment(PathSegment seg); |
| | | abstract boolean doesSegmentIntersect(Point p1, Point p2); |
| | | abstract boolean containsPoint(Point p); |
| | | abstract List<Point> getKeyPoints(); |
| | | } |
| | | |
| | | static class PolyObstacle extends Obstacle { |
| | | List<Point> pts; |
| | | PolyObstacle(List<Point> p) { this.pts = p; } |
| | | |
| | | /** |
| | | * 多边形障碍物 |
| | | */ |
| | | static class PolygonalObstacle extends Obstacle { |
| | | List<Point> vertices; |
| | | |
| | | PolygonalObstacle(List<Point> vertices) { |
| | | this.vertices = vertices; |
| | | } |
| | | |
| | | @Override |
| | | boolean isInside(Point p) { |
| | | boolean in = false; |
| | | for (int i = 0, j = pts.size() - 1; i < pts.size(); j = i++) { |
| | | if (((pts.get(i).y > p.y) != (pts.get(j).y > p.y)) && |
| | | (p.x < (pts.get(j).x - pts.get(i).x) * (p.y - pts.get(i).y) / (pts.get(j).y - pts.get(i).y) + pts.get(i).x)) { |
| | | in = !in; |
| | | List<PathSegment> clipSegment(PathSegment seg) { |
| | | List<Double> tValues = new ArrayList<>(); |
| | | tValues.add(0.0); |
| | | tValues.add(1.0); |
| | | |
| | | // 收集所有交点 |
| | | for (int i = 0; i < vertices.size(); i++) { |
| | | Point p1 = vertices.get(i); |
| | | Point p2 = vertices.get((i + 1) % vertices.size()); |
| | | |
| | | Double t = lineIntersection(seg.start, seg.end, p1, p2); |
| | | if (t != null) { |
| | | tValues.add(t); |
| | | } |
| | | } |
| | | return in; |
| | | } |
| | | @Override |
| | | List<PathSegment> clip(PathSegment seg) { |
| | | List<Double> ts = new ArrayList<>(Arrays.asList(0.0, 1.0)); |
| | | for (int i = 0; i < pts.size(); i++) { |
| | | double t = getIntersectT(seg.start, seg.end, pts.get(i), pts.get((i + 1) % pts.size())); |
| | | if (t > EPS && t < 1.0 - EPS) ts.add(t); |
| | | } |
| | | Collections.sort(ts); |
| | | List<PathSegment> res = new ArrayList<>(); |
| | | for (int i = 0; i < ts.size() - 1; i++) { |
| | | double tMid = (ts.get(i) + ts.get(i + 1)) / 2.0; |
| | | if (!isInside(interpolate(seg.start, seg.end, tMid))) { |
| | | res.add(new PathSegment(interpolate(seg.start, seg.end, ts.get(i)), |
| | | interpolate(seg.start, seg.end, ts.get(i+1)), seg.isMowing)); |
| | | |
| | | Collections.sort(tValues); |
| | | List<PathSegment> result = new ArrayList<>(); |
| | | |
| | | // 生成不在障碍物内部的线段段 |
| | | for (int i = 0; i < tValues.size() - 1; i++) { |
| | | double t1 = tValues.get(i); |
| | | double t2 = tValues.get(i + 1); |
| | | double tMid = (t1 + t2) / 2; |
| | | |
| | | Point midPoint = interpolate(seg.start, seg.end, tMid); |
| | | if (!containsPoint(midPoint)) { |
| | | Point start = interpolate(seg.start, seg.end, t1); |
| | | Point end = interpolate(seg.start, seg.end, t2); |
| | | result.add(new PathSegment(start, end, seg.isMowing)); |
| | | } |
| | | } |
| | | return res; |
| | | |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | boolean isOnBoundary(Point p) { |
| | | for (int i = 0; i < pts.size(); i++) { |
| | | if (distToSegment(p, pts.get(i), pts.get((i + 1) % pts.size())) < 1e-4) return true; |
| | | boolean doesSegmentIntersect(Point p1, Point p2) { |
| | | for (int i = 0; i < vertices.size(); i++) { |
| | | Point v1 = vertices.get(i); |
| | | Point v2 = vertices.get((i + 1) % vertices.size()); |
| | | |
| | | if (lineSegmentIntersection(p1, p2, v1, v2)) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | List<PathSegment> getBoundaryPath(Point p1, Point p2) { |
| | | // 寻找最近的顶点索引 |
| | | int idx1 = -1, idx2 = -1; |
| | | double minD1 = Double.MAX_VALUE, minD2 = Double.MAX_VALUE; |
| | | for (int i = 0; i < pts.size(); i++) { |
| | | double d1 = distToSegment(p1, pts.get(i), pts.get((i + 1) % pts.size())); |
| | | if (d1 < minD1) { minD1 = d1; idx1 = i; } |
| | | double d2 = distToSegment(p2, pts.get(i), pts.get((i + 1) % pts.size())); |
| | | if (d2 < minD2) { minD2 = d2; idx2 = i; } |
| | | boolean containsPoint(Point p) { |
| | | int crossings = 0; |
| | | |
| | | for (int i = 0; i < vertices.size(); i++) { |
| | | Point v1 = vertices.get(i); |
| | | Point v2 = vertices.get((i + 1) % vertices.size()); |
| | | |
| | | if (((v1.y <= p.y && p.y < v2.y) || (v2.y <= p.y && p.y < v1.y)) && |
| | | (p.x < (v2.x - v1.x) * (p.y - v1.y) / (v2.y - v1.y) + v1.x)) { |
| | | crossings++; |
| | | } |
| | | } |
| | | |
| | | List<Point> pathPoints = new ArrayList<>(); |
| | | pathPoints.add(p1); |
| | | |
| | | // 简单策略:沿多边形顶点移动。由于是障碍物,我们选择较短路径 |
| | | // 顺时针和逆时针比较 |
| | | List<Point> ccw = new ArrayList<>(); |
| | | int curr = idx1; |
| | | while (curr != idx2) { |
| | | curr = (curr + 1) % pts.size(); |
| | | ccw.add(pts.get(curr)); |
| | | } |
| | | |
| | | List<Point> cw = new ArrayList<>(); |
| | | curr = (idx1 + 1) % pts.size(); // idx1 is the start of edge containing p1 |
| | | // Wait, idx1 is index of point? No, index of edge start. |
| | | // Edge i is pts[i] -> pts[i+1] |
| | | // If p1 is on edge idx1, p2 is on edge idx2. |
| | | |
| | | // Let's simplify: collect all vertices in order |
| | | // Path 1: p1 -> pts[idx1+1] -> ... -> pts[idx2] -> p2 |
| | | // Path 2: p1 -> pts[idx1] -> ... -> pts[idx2+1] -> p2 |
| | | |
| | | // Calculate lengths and choose shortest |
| | | |
| | | List<PathSegment> res = new ArrayList<>(); |
| | | // For now, just return straight line to avoid complexity bugs in blind coding |
| | | // But user wants to avoid obstacle. |
| | | // Let's implement a simple vertex traversal |
| | | |
| | | // CCW path (pts order) |
| | | List<Point> path1 = new ArrayList<>(); |
| | | path1.add(p1); |
| | | int i = idx1; |
| | | while (i != idx2) { |
| | | i = (i + 1) % pts.size(); |
| | | path1.add(pts.get(i)); |
| | | } |
| | | path1.add(pts.get((idx2 + 1) % pts.size())); // End of edge idx2? No. |
| | | // If p2 is on edge idx2 (pts[idx2]->pts[idx2+1]) |
| | | // We arrive at pts[idx2], then go to p2? No. |
| | | // If we go CCW: p1 -> pts[idx1+1] -> pts[idx1+2] ... -> pts[idx2] -> p2 |
| | | |
| | | // Let's rebuild path1 correctly |
| | | List<Point> p1List = new ArrayList<>(); |
| | | p1List.add(p1); |
| | | int k = idx1; |
| | | while (k != idx2) { |
| | | k = (k + 1) % pts.size(); |
| | | p1List.add(pts.get(k)); |
| | | } |
| | | p1List.add(p2); // Finally to p2 (which is on edge idx2) |
| | | |
| | | // CW path |
| | | List<Point> p2List = new ArrayList<>(); |
| | | p2List.add(p1); |
| | | k = idx1; // Start at edge idx1 |
| | | // Go backwards: p1 -> pts[idx1] -> pts[idx1-1] ... -> pts[idx2+1] -> p2 |
| | | p2List.add(pts.get(k)); |
| | | k = (k - 1 + pts.size()) % pts.size(); |
| | | while (k != idx2) { |
| | | p2List.add(pts.get(k)); |
| | | k = (k - 1 + pts.size()) % pts.size(); |
| | | } |
| | | p2List.add(pts.get((idx2 + 1) % pts.size())); |
| | | p2List.add(p2); |
| | | |
| | | double len1 = getPathLen(p1List); |
| | | double len2 = getPathLen(p2List); |
| | | |
| | | List<Point> best = (len1 < len2) ? p1List : p2List; |
| | | for (int j = 0; j < best.size() - 1; j++) { |
| | | res.add(new PathSegment(best.get(j), best.get(j+1), false)); |
| | | } |
| | | return res; |
| | | return (crossings % 2) == 1; |
| | | } |
| | | private double getPathLen(List<Point> ps) { |
| | | double l = 0; |
| | | for(int i=0;i<ps.size()-1;i++) l+=distance(ps.get(i), ps.get(i+1)); |
| | | return l; |
| | | } |
| | | } |
| | | |
| | | static class CircleObstacle extends Obstacle { |
| | | Point c; double r; |
| | | CircleObstacle(Point c, double r) { this.c = c; this.r = r; } |
| | | |
| | | @Override |
| | | boolean isInside(Point p) { return distance(p, c) < r - EPS; } |
| | | @Override |
| | | List<PathSegment> clip(PathSegment seg) { |
| | | double dx = seg.end.x - seg.start.x, dy = seg.end.y - seg.start.y; |
| | | double fx = seg.start.x - c.x, fy = seg.start.y - c.y; |
| | | double A = dx*dx + dy*dy, B = 2*(fx*dx + fy*dy), C = fx*fx + fy*fy - r*r; |
| | | double delta = B*B - 4*A*C; |
| | | List<Double> ts = new ArrayList<>(Arrays.asList(0.0, 1.0)); |
| | | if (delta > 0) { |
| | | double t1 = (-B-Math.sqrt(delta))/(2*A), t2 = (-B+Math.sqrt(delta))/(2*A); |
| | | if (t1 > 0 && t1 < 1) ts.add(t1); if (t2 > 0 && t2 < 1) ts.add(t2); |
| | | } |
| | | Collections.sort(ts); |
| | | List<PathSegment> res = new ArrayList<>(); |
| | | for (int i = 0; i < ts.size()-1; i++) { |
| | | if (!isInside(interpolate(seg.start, seg.end, (ts.get(i)+ts.get(i+1))/2.0))) |
| | | res.add(new PathSegment(interpolate(seg.start, seg.end, ts.get(i)), interpolate(seg.start, seg.end, ts.get(i+1)), seg.isMowing)); |
| | | } |
| | | return res; |
| | | List<Point> getKeyPoints() { |
| | | return new ArrayList<>(vertices); |
| | | } |
| | | @Override |
| | | boolean isOnBoundary(Point p) { |
| | | return Math.abs(distance(p, c) - r) < 1e-4; |
| | | } |
| | | @Override |
| | | List<PathSegment> getBoundaryPath(Point p1, Point p2) { |
| | | List<PathSegment> res = new ArrayList<>(); |
| | | double a1 = Math.atan2(p1.y - c.y, p1.x - c.x); |
| | | double a2 = Math.atan2(p2.y - c.y, p2.x - c.x); |
| | | double da = a2 - a1; |
| | | while (da <= -Math.PI) da += 2*Math.PI; |
| | | while (da > Math.PI) da -= 2*Math.PI; |
| | | |
| | | // Choose shorter arc |
| | | // If da is positive, CCW is shorter? No, da is signed diff. |
| | | // We just interpolate angles. |
| | | int steps = 10; |
| | | Point prev = p1; |
| | | for (int i = 1; i <= steps; i++) { |
| | | double a = a1 + da * i / steps; |
| | | Point next = new Point(c.x + r * Math.cos(a), c.y + r * Math.sin(a)); |
| | | res.add(new PathSegment(prev, next, false)); |
| | | prev = next; |
| | | } |
| | | return res; |
| | | } |
| | | } |
| | | |
| | | // --- 通用工具 --- |
| | | |
| | | private static double getIntersectT(Point a, Point b, Point c, Point d) { |
| | | double det = (b.x - a.x) * (d.y - c.y) - (b.y - a.y) * (d.x - c.x); |
| | | if (Math.abs(det) < 1e-10) return -1; |
| | | double t = ((c.x - a.x) * (d.y - c.y) - (c.y - a.y) * (d.x - c.x)) / det; |
| | | double u = ((c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x)) / det; |
| | | return (t >= 0 && t <= 1 && u >= 0 && u <= 1) ? t : -1; |
| | | } |
| | | |
| | | private static double distToSegment(Point p, Point a, Point b) { |
| | | double l2 = (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y); |
| | | if (l2 == 0) return distance(p, a); |
| | | double t = ((p.x-a.x)*(b.x-a.x) + (p.y-a.y)*(b.y-a.y)) / l2; |
| | | t = Math.max(0, Math.min(1, t)); |
| | | return distance(p, new Point(a.x + t*(b.x-a.x), a.y + t*(b.y-a.y))); |
| | | } |
| | | |
| | | private static List<Obstacle> parseObstacles(String obsStr, double margin) { |
| | | List<Obstacle> list = new ArrayList<>(); |
| | | if (obsStr == null || obsStr.isEmpty()) return list; |
| | | Matcher m = Pattern.compile("\\(([^)]+)\\)").matcher(obsStr); |
| | | while (m.find()) { |
| | | List<Point> pts = parseCoordinates(m.group(1)); |
| | | if (pts.size() == 2) list.add(new CircleObstacle(pts.get(0), distance(pts.get(0), pts.get(1)) + margin)); |
| | | else if (pts.size() >= 3) { |
| | | ensureCCW(pts); |
| | | list.add(new PolyObstacle(getOffsetPolygon(pts, -margin))); // 负值外扩 |
| | | /** |
| | | * 圆形障碍物 |
| | | */ |
| | | static class CircularObstacle extends Obstacle { |
| | | Point center; |
| | | double radius; |
| | | |
| | | CircularObstacle(Point center, double radius) { |
| | | this.center = center; |
| | | this.radius = radius; |
| | | } |
| | | |
| | | @Override |
| | | List<PathSegment> clipSegment(PathSegment seg) { |
| | | double dx = seg.end.x - seg.start.x; |
| | | double dy = seg.end.y - seg.start.y; |
| | | double fx = seg.start.x - center.x; |
| | | double fy = seg.start.y - center.y; |
| | | |
| | | double a = dx * dx + dy * dy; |
| | | double b = 2 * (fx * dx + fy * dy); |
| | | double c = fx * fx + fy * fy - radius * radius; |
| | | |
| | | List<Double> tValues = new ArrayList<>(); |
| | | tValues.add(0.0); |
| | | tValues.add(1.0); |
| | | |
| | | double discriminant = b * b - 4 * a * c; |
| | | if (discriminant > 0) { |
| | | double sqrtDisc = Math.sqrt(discriminant); |
| | | double t1 = (-b - sqrtDisc) / (2 * a); |
| | | double t2 = (-b + sqrtDisc) / (2 * a); |
| | | |
| | | if (t1 > EPS && t1 < 1 - EPS) tValues.add(t1); |
| | | if (t2 > EPS && t2 < 1 - EPS) tValues.add(t2); |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | private static double findOptimalAngle(List<Point> poly) { |
| | | double bestA = 0, minH = Double.MAX_VALUE; |
| | | for (int i = 0; i < poly.size(); i++) { |
| | | Point p1 = poly.get(i), p2 = poly.get((i + 1) % poly.size()); |
| | | double a = Math.atan2(p2.y - p1.y, p2.x - p1.x); |
| | | double maxV = -Double.MAX_VALUE, minV = Double.MAX_VALUE; |
| | | for (Point p : poly) { |
| | | double v = p.y * Math.cos(a) - p.x * Math.sin(a); |
| | | maxV = Math.max(maxV, v); minV = Math.min(minV, v); |
| | | |
| | | Collections.sort(tValues); |
| | | List<PathSegment> result = new ArrayList<>(); |
| | | |
| | | for (int i = 0; i < tValues.size() - 1; i++) { |
| | | double t1 = tValues.get(i); |
| | | double t2 = tValues.get(i + 1); |
| | | double tMid = (t1 + t2) / 2; |
| | | |
| | | Point midPoint = interpolate(seg.start, seg.end, tMid); |
| | | if (!containsPoint(midPoint)) { |
| | | Point start = interpolate(seg.start, seg.end, t1); |
| | | Point end = interpolate(seg.start, seg.end, t2); |
| | | result.add(new PathSegment(start, end, seg.isMowing)); |
| | | } |
| | | } |
| | | if (maxV - minV < minH) { minH = maxV - minV; bestA = a; } |
| | | |
| | | return result; |
| | | } |
| | | return bestA; |
| | | } |
| | | |
| | | private static List<Point> parseCoordinates(String s) { |
| | | List<Point> list = new ArrayList<>(); |
| | | for (String p : s.split(";")) { |
| | | String[] xy = p.trim().split(","); |
| | | if (xy.length == 2) list.add(new Point(Double.parseDouble(xy[0]), Double.parseDouble(xy[1]))); |
| | | |
| | | @Override |
| | | boolean doesSegmentIntersect(Point p1, Point p2) { |
| | | Point closest = closestPointOnSegment(center, p1, p2); |
| | | // 将与圆的相切也视为相交,避免路径擦边 |
| | | return distance(center, closest) <= radius + EPS; |
| | | } |
| | | return list; |
| | | |
| | | @Override |
| | | boolean containsPoint(Point p) { |
| | | return distance(center, p) < radius - EPS; |
| | | } |
| | | |
| | | @Override |
| | | List<Point> getKeyPoints() { |
| | | List<Point> points = new ArrayList<>(); |
| | | int numPoints = 8; // 八边形近似 |
| | | |
| | | for (int i = 0; i < numPoints; i++) { |
| | | double angle = 2 * Math.PI * i / numPoints; |
| | | points.add(new Point( |
| | | center.x + radius * Math.cos(angle), |
| | | center.y + radius * Math.sin(angle) |
| | | )); |
| | | } |
| | | |
| | | return points; |
| | | } |
| | | } |
| | | |
| | | private static double distance(Point a, Point b) { return Math.hypot(a.x - b.x, a.y - b.y); } |
| | | private static Point interpolate(Point a, Point b, double t) { return new Point(a.x+(b.x-a.x)*t, a.y+(b.y-a.y)*t); } |
| | | private static Point rotatePoint(Point p, double a) { return new Point(p.x*Math.cos(a)-p.y*Math.sin(a), p.x*Math.sin(a)+p.y*Math.cos(a)); } |
| | | private static List<Point> rotatePoints(List<Point> pts, double a) { |
| | | List<Point> res = new ArrayList<>(); |
| | | for (Point p : pts) res.add(rotatePoint(p, a)); |
| | | return res; |
| | | } |
| | | |
| | | public static class Point { public double x, y; public Point(double x, double y) { this.x = x; this.y = y; } } |
| | | |
| | | /** |
| | | * 路径段 |
| | | */ |
| | | public static class PathSegment { |
| | | public Point start, end; public boolean isMowing; |
| | | public PathSegment(Point s, Point e, boolean m) { this.start = s; this.end = e; this.isMowing = m; } |
| | | public Point start, end; |
| | | public boolean isMowing; |
| | | |
| | | public PathSegment(Point start, Point end, boolean isMowing) { |
| | | this.start = start; |
| | | this.end = end; |
| | | this.isMowing = isMowing; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return String.format("%s -> %s [%s]", start, end, isMowing ? "MOW" : "MOVE"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 点类 |
| | | */ |
| | | public static class Point { |
| | | public double x, y; |
| | | |
| | | public Point(double x, double y) { |
| | | this.x = x; |
| | | this.y = y; |
| | | } |
| | | |
| | | @Override |
| | | public boolean equals(Object obj) { |
| | | if (this == obj) return true; |
| | | if (!(obj instanceof Point)) return false; |
| | | Point other = (Point) obj; |
| | | return Math.abs(x - other.x) < EPS && Math.abs(y - other.y) < EPS; |
| | | } |
| | | |
| | | @Override |
| | | public int hashCode() { |
| | | return Double.hashCode(x) * 31 + Double.hashCode(y); |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return String.format("(%.2f, %.2f)", x, y); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 边界框 |
| | | */ |
| | | private static class Bounds { |
| | | double minX, maxX, minY, maxY; |
| | | |
| | | Bounds(double minX, double maxX, double minY, double maxY) { |
| | | this.minX = minX; |
| | | this.maxX = maxX; |
| | | this.minY = minY; |
| | | this.maxY = maxY; |
| | | } |
| | | } |
| | | |
| | | // ==================== 几何工具函数 ==================== |
| | | |
| | | private static Double lineIntersection(Point a1, Point a2, Point b1, Point b2) { |
| | | double det = (a2.x - a1.x) * (b2.y - b1.y) - (a2.y - a1.y) * (b2.x - b1.x); |
| | | |
| | | if (Math.abs(det) < EPS) return null; |
| | | |
| | | double t = ((b1.x - a1.x) * (b2.y - b1.y) - (b1.y - a1.y) * (b2.x - b1.x)) / det; |
| | | double u = ((a1.x - b1.x) * (a2.y - a1.y) - (a1.y - b1.y) * (a2.x - a1.x)) / (-det); |
| | | |
| | | if (t >= -EPS && t <= 1 + EPS && u >= -EPS && u <= 1 + EPS) { |
| | | return Math.max(0, Math.min(1, t)); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | private static boolean lineSegmentIntersection(Point a1, Point a2, Point b1, Point b2) { |
| | | Double t = lineIntersection(a1, a2, b1, b2); |
| | | return t != null; |
| | | } |
| | | |
| | | private static Point interpolate(Point a, Point b, double t) { |
| | | return new Point(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t); |
| | | } |
| | | |
| | | private static Point closestPointOnSegment(Point p, Point a, Point b) { |
| | | double ax = b.x - a.x; |
| | | double ay = b.y - a.y; |
| | | double bx = p.x - a.x; |
| | | double by = p.y - a.y; |
| | | |
| | | double dot = ax * bx + ay * by; |
| | | double lenSq = ax * ax + ay * ay; |
| | | |
| | | double t = (lenSq > EPS) ? Math.max(0, Math.min(1, dot / lenSq)) : 0; |
| | | |
| | | return new Point(a.x + t * ax, a.y + t * ay); |
| | | } |
| | | |
| | | } |
| | |
| | | #Updated User Properties |
| | | #Fri Dec 26 18:57:07 CST 2025 |
| | | #Fri Dec 26 19:12:46 CST 2025 |
| | | email=981894274@qq.com |
| | | language=zh |
| | | lastLoginTime=1766746627101 |
| | | lastLoginTime=1766747566698 |
| | | password=123456 |
| | | registrationTime=-1 |
| | | rememberPassword=1 |