计算直线和水平轴之间的角度

问题描述 投票:3回答:1

考虑以下玩具数据集:

clear
input double(x y)
  -.03184700384736061                   .
 -.031028195071294902                   .
 -.030209386295229197                   .
  -.02939057751916349                   .
 -.028571768743097782                   .
 -.027752959967032073                   .
 -.026934151190966368                   .
 -.026115342414900662                   .
 -.025296533638834953                   .
 -.024477724862769244                   .
  -.02365891608670354                   .
 -.022840107310637833                   .
 -.022021298534572124                   .
 -.021202489758506415                   .
  -.02038368098244071                   .
 -.019564872206375004                   .
 -.018746063430309295  -374.9212686061859
  -.01792725465424359  -358.5450930848718
  -.01710844587817788  -342.1689175635576
 -.016289637102112176  -325.7927420422435
 -.015470828326046467 -309.41656652092934
 -.014652019549980761  -293.0403909996152
 -.013833210773915052 -276.66421547830106
 -.013014401997849347 -260.28803995698695
 -.012195593221783638 -243.91186443567275
 -.011376784445717929  -227.5356889143586
 -.010557975669652223 -211.15951339304448
 -.009739166893586518 -194.78333787173037
 -.008920358117520809 -178.40716235041617
   -.0081015493414551   -162.030986829102
 -.007282740565389394  -145.6548113077879
 -.006463931789323689 -129.27863578647379
  -.00564512301325798  -112.9024602651596
-.0048263142371922745   -96.5262847438455
 -.004007505461126569  -80.15010922253138
 -.003188696685060881 -63.773933701217615
-.0023698879089951753 -47.397758179903505
-.0015510791329294699   -31.0215826585894
-.0007322703568637644 -14.645407137275287
.00008653841920196886  1.7307683840393773
 .0009053471952676778  18.106943905353557
 .0017241559713333868  34.483119426667734
  .002542964747399089   50.85929494798177
 .0033617735234647977   67.23547046929596
  .004180582299530507   83.61164599061013
  .004999391075596209   99.98782151192417
  .005818199851661918  116.36399703323835
  .006637008627727627  132.74017255455254
  .007455817403793336   149.1163480758667
  .008274626179859072  165.49252359718145
  .009093434955924774   181.8686991184955
  .009912243731990483  198.24487463980967
  .010731052508056192  214.62105016112383
  .011549861284121894   230.9972256824379
  .012368670060187603  247.37340120375205
  .013187478836253312   263.7495767250662
  .014006287612319014   280.1257522463803
  .014825096388384723  296.50192776769444
  .015643905164450425   312.8781032890085
  .016462713940516162   329.2542788103232
   .01728152271658187   345.6304543316374
   .01810033149264758   362.0066298529516
   .01891914026871329   378.3828053742658
   .01973794904477899  394.75898089557984
    .0205567578208447    411.135156416894
   .02137556659691041   427.5113319382082
   .02219437537297611   443.8875074595222
   .02301318414904182   460.2636829808364
   .02383199292510753  476.63985850215056
   .02465080170117323   493.0160340234646
  .025469610477238967  509.39220954477935
  .026288419253304676   525.7683850660935
  .027107228029370385   542.1445605874077
  .027926036805436087   558.5207361087217
  .028744845581501796   574.8969116300359
  .029563654357567498     591.27308715135
  .030382463133633207   607.6492626726641
  .031201271909698916   624.0254381939783
   .03202008068576463   640.4016137152927
  .032838889461830334   656.7777892366066
   .03365769823789605    673.153964757921
   .03447650701396174   689.5301402792347
  .035295315790027454   705.9063158005491
  .036114124566093184   722.2824913218636
    .0369329333421589    738.658666843178
   .03775174211822459   755.0348423644917
  .038570550894290304    771.411017885806
  .039389359670356006   787.7871934071201
   .04020816844642172   804.1633689284345
   .04102697722248744   820.5395444497487
   .04184578599855314   836.9157199710628
   .04266459477461884   853.2918954923769
   .04348340355068454   869.6680710136909
   .04430221232675029   886.0442465350058
   .04512102110281599   902.4204220563198
  .045939829878881705   918.7965975776341
   .04675863865494739   935.1727730989479
   .04757744743101311   951.5489486202622
   .04839625620707881   967.9251241415762
   .04921506498314453   984.3012996628905
   .05003387375921024  1000.6774751842048
   .05085268253527593  1017.0536507055186
   .05167149131134165   1033.429826226833
   .05249030008740735   1049.806001748147
   .05330910886347309  1066.1821772694618
  .054127917639538795  1082.5583527907759
    .0549467264156045    1098.93452831209
    .0557655351916702   1115.310703833404
  .056584343967735914  1131.6868793547183
  .057403152743801616  1148.0630548760323
   .05822196151986733  1164.4392303973466
   .05904077029593305  1180.8154059186609
  .059859579071998736                   .
   .06067838784806445                   .
   .06149719662413018                   .
    .0623160054001959                   .
   .06313481417626159                   .
    .0639536229523273                   .
     .064772431728393                   .
   .06559124050445872                   .
   .06641004928052442                   .
   .06722885805659014                   .
   .06804766683265584                   .
   .06886647560872154                   .
   .06968528438478726                   .
   .07050409316085299                   .
    .0713229019369187                   .
   .07214171071298439                   .
   .07296051948905011                   .
   .07377932826511581                   .
   .07459813704118153                   .
   .07541694581724723                   .
   .07623575459331294                   .
   .07705456336937865                   .
   .07787337214544435                   .
   .07869218092151009                   .
   .07951098969757579                   .
    .0803297984736415                   .
    .0811486072497072                   .
   .08196741602577291                   .
   .08278622480183861                   .
   .08360503357790433                   .
   .08442384235397003                   .
   .08524265113003573                   .
   .08606145990610145                   .
   .08688026868216718                   .
    .0876990774582329                   .
    .0885178862342986                   .
    .0893366950103643                   .
      .09015550378643                   .
   .09097431256249572                   .
   .09179312133856142                   .
   .09261193011462714                   .
   .09343073889069284                   .
   .09424954766675855                   .
   .09506835644282427                   .
   .09588716521888999                   .
   .09670597399495567                   .
   .09752478277102139                   .
    .0983435915470871                   .
   .09916240032315282                   .
   .09998120909921851                   .
   .10080001787528423                   .
   .10161882665134994                   .
   .10243763542741566                   .
   .10325644420348135                   .
   .10407525297954706                   .
   .10489406175561278                   .
    .1057128705316785                   .
   .10653167930774421                   .
    .1073504880838099                   .
   .10816929685987561                   .
   .10898810563594133                   .
   .10980691441200705                   .
   .11062572318807273                   .
   .11144453196413845                   .
   .11226334074020417                   .
   .11308214951626988                   .
    .1139009582923356                   .
   .11471976706840128                   .
     .115538575844467                   .
   .11635738462053272                   .
   .11717619339659843                   .
   .11799500217266412                   .
   .11881381094872984                   .
   .11963261972479555                   .
   .12045142850086127                   .
   .12127023727692696                   .
   .12208904605299267                   .
   .12290785482905839                   .
    .1237266636051241                   .
   .12454547238118982                   .
    .1253642811572555                   .
   .12618308993332122                   .
   .12700189870938694                   .
   .12782070748545266                   .
   .12863951626151834                   .
   .12945832503758406                   .
   .13027713381364978                   .
    .1310959425897155                   .
   .13191475136578118                   .
    .1327335601418469                   .
    .1335523689179126                   .
   .13437117769397833                   .
   .13518998647004404                   .
   .13600879524610973                   .
   .13682760402217545                   .
   .13764641279824116                   .
   .13846522157430688                   .
   .13928403035037257                   .
   .14010283912643828                   .
     .140921647902504                   .
   .14174045667856972                   .
   .14255926545463543                   .
   .14337807423070112                   .
   .14419688300676684                   .
   .14501569178283255                   .
   .14583450055889827                   .
   .14665330933496395                   .
   .14747211811102967                   .
    .1482909268870954                   .
    .1491097356631611                   .
    .1499285444392268                   .
    .1507473532152925                   .
   .15156616199135822                   .
   .15238497076742394                   .
   .15320377954348965                   .
   .15402258831955534                   .
   .15484139709562106                   .
   .15566020587168677                   .
    .1564790146477525                   .
   .15729782342381818                   .
    .1581166321998839                   .
    .1589354409759496                   .
   .15975424975201533                   .
   .16057305852808104                   .
   .16139186730414673                   .
   .16221067608021245                   .
   .16302948485627816                   .
   .16384829363234388                   .
   .16466710240840957                   .
   .16548591118447528                   .
     .166304719960541                   .
    .1671235287366067                   .
    .1679423375126724                   .
   .16876114628873812                   .
   .16957995506480383                   .
   .17039876384086955                   .
   .17121757261693527                   .
   .17203638139300095                   .
   .17285519016906667                   .
   .17367399894513239                   .
    .1744928077211981                   .
    .1753116164972638                   .
    .1761304252733295                   .
   .17694923404939522                   .
   .17776804282546094                   .
   .17858685160152665                   .
   .17940566037759234                   .
   .18022446915365806                   .
   .18104327792972377                   .
    .1818620867057895                   .
   .18268089548185518                   .
    .1834997042579209                   .
    .1843185130339866                   .
   .18513732181005232                   .
     .185956130586118                   .
   .18677493936218373                   .
   .18759374813824944                   .
   .18841255691431516                   .
   .18923136569038088                   .
   .19005017446644656                   .
   .19086898324251228                   .
     .191687792018578                   .
    .1925066007946437                   .
    .1933254095707094                   .
   .19414421834677512                   .
   .19496302712284083                   .
   .19578183589890655                   .
   .19660064467497224                   .
   .19741945345103795                   .
   .19823826222710367                   .
   .19905707100316938                   .
    .1998758797792351                   .
    .2006946885553008                   .
    .2015134973313665                   .
   .20233230610743222                   .
   .20315111488349794                   .
   .20396992365956362                   .
   .20478873243562934                   .
   .20560754121169506                   .
   .20642634998776077                   .
    .2072451587638265                   .
   .20806396753989218                   .
    .2088827763159579                   .
    .2097015850920236                   .
   .21052039386808932                   .
     .211339202644155                   .
   .21215801142022073                   .
   .21297682019628644                   .
end

现在考虑以下图表:

twoway line y x || scatteri 0 0 "Line A", msymbol(none) msymbol(none) /// 
mlabgap(0) mlabposition(0) mlabangle(60) legend(off)

显然,直线A相对于x-axis的角度是60度(手动指定):

enter image description here

我试图按照我在similar post中找到的建议来计算这个角度:

summarize y
scalar y1 = r(min)
scalar y2 = r(max)

summarize x
scalar x1 = r(min)
scalar x2 = r(max)

scalar dy = y2 - y1
scalar dx = x2 - x1

display (180 / _pi) * atan2(dy, dx)
89.990983

为什么Stata会生成一个角度为60而不是90度的图形?

如果我将图形的纵横比设置为1,则角度似乎会更改为68,它仍然远不及计算值:

twoway line y x || scatteri 0 0 "Line A", msymbol(none) msymbol(none) /// 
mlabgap(0) mlabposition(0) mlabangle(68) legend(off) aspectratio(1)

enter image description here

如果给出尺度和纵横比的差异,我怎样才能始终如一地计算角度?

graphics stata trigonometry angle aspect-ratio
1个回答
0
投票

x和y轴在图中处于不同的比例,因此这不是1:1的纵横比,并且将绘制许多角度与具有相等轴比例的预期角度不同。这在几个图形包中是默认的,因为它通常更好地在图形中传播数据。

© www.soinside.com 2019 - 2024. All rights reserved.