旋转椭圆的绘制点以给出圆

时间:2016-05-12 17:11:05

标签: r matrix plot trigonometry

我有一个椭圆形的分布,我认为是一个圆锥曲线。我想旋转这些点,使得分布变成圆形,好像我正在直接看到圆锥顶部的圆锥截面。

这是一些示例数据(使用函数here生成)

X_df <-
structure(list(x = c(550.685479223573, 411.808342674744, 125.337513241526, 
-46.6813176776531, 54.1090479024869, 335.045593380922, 538.806846993829, 
476.123346783785, 207.359201714354, -23.3704356149293, -1.06902389582398, 
252.471032092766, 502.461757269191, 522.09464005165, 290.954504794153, 
22.4116013413886, -37.4399705577234, 166.122770874069, 446.874779008936, 
547.271442128866, 372.271299246978, 84.7905677157295, -50.074206596271, 
90.757431249567, 378.201298931732, 547.145608993239, 443.947162007208, 
161.476775837252, -38.5517112166543, 25.2627436553199, 296.503160027896, 
524.775126009974, 500.784559912938, 245.712512645379, -4.31860487373257, 
-21.9661658669887, 211.218663607589, 479.198761786515, 535.314989389215, 
330.010941011427, 50.0215808044216, -46.3823119064223, 130.383487121344, 
416.170638042649, 549.268852072098, 407.813005658263, 119.940919946473, 
-46.978590114418, 57.7409750579334, 340.505587064792, 539.650771180236, 
472.254339573695, 201.890629521184, -25.163386210777, 1.25193046435474, 
256.776302252232, 506.305676724803, 520.004964534048, 284.257495593069, 
18.8183745840118, -35.9075114459174, 172.662124500953, 452.343060560759, 
546.468842888411, 367.193523099128, 81.9151159445705, -49.726312730029, 
95.1883131124973, 382.503271032958, 548.377552998115, 439.474201456606, 
157.248088356873, -39.8634174011649, 28.665422852919, 301.243788141946, 
526.815879166266, 497.683488701185, 240.939374274905, -7.78381612220116, 
-19.3411744866129, 217.640180353188, 483.134755325255, 534.947529479343, 
324.801587123232, 45.3957868762181, -45.0069945691924, 134.781896592204, 
420.833721926428, 550.278658272823, 403.464000037755, 116.273973349216, 
-48.5483252399878, 62.3918399072614, 345.924165684106, 540.282415561272, 
468.621672005007, 195.304995872248, -28.2738679786754, 4.25351768918281, 
262.272866287766, 509.296144374104), y = c(150.522375543584, 
317.792592638159, 332.783726315973, 177.890614907595, -1.30774215535761, 
-41.9959828735621, 94.0557252742373, 281.491416261009, 347.931229803675, 
232.411150772918, 41.2498141860971, -50.240758928064, 42.4333078345691, 
233.202857825371, 347.930304275537, 279.801242902484, 93.7702821671593, 
-42.9605564915062, -0.128821245055916, 179.228629398932, 331.853832274807, 
317.39347890031, 147.731418574477, -19.2449921421865, -31.3298018420377, 
123.222814177221, 301.499351173211, 340.662811705721, 204.270915882133, 
17.5570334546183, -47.8527634953491, 69.1925023774197, 260.846781070028, 
350.702299892942, 255.267980339802, 64.3048063206447, -47.7550214881633, 
21.0575085383169, 209.247480999408, 342.716023607699, 298.578792586917, 
118.053124236616, -33.3190320226709, -16.5618829502486, 154.097078032767, 
319.940208485997, 330.141085013461, 175.063055837321, -4.17911647131882, 
-40.77087978947, 96.7492568480405, 284.629419943293, 347.18869555741, 
228.951107374031, 37.6230640656836, -49.9549156886126, 45.2896584936418, 
236.96620488459, 349.2183672397, 277.259838492706, 88.5019845874813, 
-43.1419505604449, 1.98249146234145, 183.766146834555, 334.721418603224, 
314.869389642466, 144.917094343997, -21.0615467657252, -29.137753346726, 
126.928148173889, 305.196445845808, 339.338402720207, 201.609402013064, 
15.0779976117978, -47.1046400880924, 71.7191693530443, 263.543031729657, 
350.145628648054, 252.792513384296, 61.2531942049295, -49.0697852698499, 
24.2068045114243, 212.793083656477, 343.533262533366, 295.969945687212, 
115.135250419503, -34.4145910896749, -14.7817206225652, 156.282366465729, 
322.116360452784, 328.626788731125, 171.323808201914, -6.54021515590322, 
-40.1360134761796, 101.492490333309, 286.854230399582, 347.010792855229, 
226.829162028581, 35.3880363162166, -50.8418314561365, 48.893760376765
)), .Names = c("x", "y"), row.names = c(NA, -101L), class = "data.frame")

绘制椭圆,这类似于我的实际数据:

ggplot(X_df, aes(x, y)) +
  geom_point() +
  coord_equal()

enter image description here

我想对xy坐标应用一个函数来围绕它的长轴旋转椭圆,将椭圆的顶部朝我移动,椭圆的底部远离我,得到这样的东西(具有相同的尺寸)沿着x轴作为上面的椭圆,但是沿着y轴的不同尺寸):

enter image description here

我想像这样旋转我的数据椭圆被旋转以产生圆形,其中我看到形状的顶部和底部之间的最大距离(即,垂直于长轴的最长轴),作为形状围绕它长轴旋转。

我该怎么做?

1 个答案:

答案 0 :(得分:2)

看起来你说的是,如果我看过&#34;圈&#34;从边缘开始,比方说,x = -1000,y = 0,我会看到一条线逆时针旋转(离开xy平面)远离y轴。目标是将圆圈旋转回y轴。

旋转角度为acos(1/ratio)(在这种情况下为0.839弧度或48.06度),其中ratiodiff(range(X_df$x))/diff(range(X_df$y))(假设旋转轴位于xy平面并平行于x轴和您的数据包括圆圈两侧x轴上的点。

实际上,要将圆圈旋转回xy平面,您可以将y点乘以ratio,然后,为了保持相同的中心,减去(ratio - 1) * mean(X_df$y)(我在哪里&# 39;假设数据点均匀分布在圆周上)。

换句话说(或代码,实际上):

ratio = diff(range(X_df$x))/diff(range(X_df$y))
X_df$ynew = ratio * X_df$y - (ratio - 1) * mean(X_df$y)

ggplot(X_df, aes(x, ynew)) +
  geom_point() +
  coord_equal()

将原稿与&#34;旋转&#34;:

进行比较

enter image description here