[R] computing the radius of an arc

Nair, Murlidharan T mnair at iusb.edu
Fri Jul 24 16:53:07 CEST 2009


Thanks, for all the suggestions. Indeed I am interested in computing curvature (http://en.wikipedia.org/wiki/Curvature) of the curve that is given as a discrete set of points. I have the curve in 3D but I can certainly write it in 2D as well. Code is given at the bottom. I will try with the suggestions you have given, but if anyone has done this before, I would appreciate your help.
Cheers../Murli

#Here is a sample set of points I have
#==================================================
crv.data<-structure(list(x = c(0, -0.0306853139578441, -0.276628790412316,
-0.859263925181012, -1.62257352572431, -2.54180446175123, -3.58311939939041,
-4.47775302763648, -5.20672353385222, -5.70772453112355, -5.86816742805647,
-5.85512267805905, -5.86890303344411, -6.03794557630881, -6.54376527154449,
-7.41641977826233, -8.43426054441638, -9.4492150187861, -10.3229834196854,
-10.8864872721894, -11.2269318778479, -11.5288579439779, -11.8523643559968,
-12.3062647090069, -12.8891130463981, -13.6871932069788, -14.6899162228852,
-15.7287473861432, -16.7002007816017, -17.4938132085552, -17.9514808696215,
-18.053932638745, -18.0258585256897, -18.0578498339064, -18.3434728670261,
-19.0145666075197, -19.9730991767178, -21.0509725096314, -22.1446954950542,
-23.0471931075437, -23.5727562073003, -23.715867498552, -23.6195922949145,
-23.4861035380711, -23.5071669629897, -23.898410815596, -24.5639758381823,
-25.3076254206083, -26.0783238851903, -26.6892077157018, -27.1311258931034,
-27.3449823936267, -27.249150002813, -27.0545058438396, -27.0103154329439,
-27.2020188674197, -27.5519286704552, -28.0420691582227, -28.6103746365014,
-29.1122563482942, -29.4789785404513, -29.5674929800785, -29.3148911647401,
-28.914975555264, -28.6187800530022, -28.6370432754742, -28.9539799252036,
-29.4617813359781, -30.0615898030665, -30.6292462800728, -31.0689275799842,
-31.3385083273678, -31.3789924570699, -31.2272960016442, -31.128704031356,
-31.3078705126386, -31.8268127074634, -32.5439424355354, -33.3193799779814,
-34.0307855851372, -34.4993653978106, -34.7763903133622, -34.8490589091549,
-34.6680011479362, -34.4666206887368, -34.3787596301642, -34.5595906485356,
-35.0867179188119, -35.7919772116135, -36.4989190104089, -37.1107512492556,
-37.6424870360951, -37.9568139879938, -37.9757653972362, -37.9150771625784,
-37.9281726093341, -38.1944634520418, -38.7610575730089, -39.5040262440443,
-40.3176087416221, -41.0870196537372, -41.7643478760401, -42.2345289970129,
-42.5039346739085, -42.6930306845356, -42.9494622652336, -43.4890077075078,
-44.4174555070996, -45.6895055107694, -47.1058760353486, -48.5122541688846,
-49.8548821817968, -51.0509488787429, -52.0934514646431, -53.0116221406909,
-53.9145485072638, -55.0200512121761, -56.4672499524784, -58.1839857010893,
-59.9914990782636, -61.7853609692539, -63.4255613718866, -64.7959773778136,
-65.9596533245029, -66.9528598254492, -67.8490893408409, -68.8739256877024,
-70.2029889015309, -71.8045113541305, -73.528559020527, -75.291953618378,
-77.0339616160297, -78.724268979886, -80.3661960248193, -81.9351372324764,
-83.4018510826899, -84.8710880632654, -86.5354728947765, -88.4682460584468,
-90.6617956078957, -93.029691414366, -95.3869774535437, -97.6302401189617,
-99.786536199107, -101.771203989332, -103.529872324544, -105.227540505143,
-107.052906404638, -109.145057305443, -111.467645177217, -113.890960679165,
-116.341379587143, -118.74252344236, -121.040228988391, -123.124533926417,
-124.93953775714, -126.623665411559, -128.366187243154, -130.333687455083,
-132.526599906356, -134.835165761551, -137.206297108417, -139.583802711657,
-141.874627414456, -144.03929635661, -146.007211336702, -147.773055319761,
-149.509012550055, -151.39887828169, -153.526878273866, -155.816033718927,
-158.244259727776, -160.755222657523, -163.201053077633, -165.480429217722,
-167.591150591444, -169.556150618216, -171.426038843204, -173.380281246457,
-175.493511792785, -177.724917583692, -180.037534909459, -182.403131693597,
-184.748312532389, -187.032617861958, -189.100218125838, -190.828755082721,
-192.349182220121, -193.848100269167, -195.48816191652, -197.387726841549,
-199.493574821285, -201.673054767619, -203.872521445348, -205.931158853816,
-207.727084016302, -209.342990538417, -210.856654189965, -212.313575579945,
-213.862971087077, -215.671350884452, -217.804609693024, -220.202426668423,
-222.711295837281, -225.217978709394, -227.695835258591, -230.005754155057,
-232.147725993397, -234.264885954887, -236.43083281726, -238.733928619854,
-241.245808919882, -243.968593076576, -246.826193676256, -249.717582473949,
-252.557186847668, -255.233298527598, -257.652127092479, -259.868999243071,
-262.01895340338, -264.256680450372, -266.667457920138, -269.211857464596,
-271.904696839038, -274.713704741033, -277.513459223076, -280.2077965561,
-282.672910151811, -284.957413352384, -287.163001649806, -289.372351046137,
-291.734392274139, -294.223544308491, -296.872890147347, -299.683703334663,
-302.501122127545, -305.278793687888, -307.87109693941, -310.20174701787,
-312.403643427482, -314.561412510618, -316.728229924724, -318.960326154175,
-321.33506795047, -323.869818007113, -326.500664438919, -329.158785480494,
-331.769356231462, -334.305404217026, -336.76505187012), y = c(0,
-0.0988228609566324, -0.459587549142073, -1.00559478656415, -1.55867982345666,
-1.88411416344253, -1.84029741961191, -1.43621470850954, -0.818111438588918,
-0.237188812165149, 0.13495177204891, 0.100346410934382, -0.312337007247639,
-0.90365315842529, -1.51856696903737, -2.014069932191, -2.33937724092174,
-2.49208438972445, -2.45738462712336, -2.3294167071895, -2.21290217928957,
-2.13732624166669, -2.33161498075634, -2.88911300818133, -3.57169568034339,
-4.19717097858157, -4.73276270934725, -5.03123770211492, -4.9871364084944,
-4.77564277319346, -4.57378507641011, -4.52568012252156, -4.66013811403211,
-5.06667370370689, -5.78174448401641, -6.59092416940882, -7.31629910621849,
-7.82417480473871, -8.10960715126236, -8.20089852613682, -8.1708578456016,
-8.26735191385882, -8.68908875814637, -9.40804520884986, -10.3155158721948,
-11.327014875002, -12.3358109517211, -13.2394134295916, -13.9111554841343,
-14.304537600682, -14.5547322814983, -14.8796619217164, -15.4631436035518,
-16.4274340925622, -17.746845851285, -19.2394841245084, -20.7332967901551,
-22.0894286422147, -23.2707919540204, -24.3196714292944, -25.2721843863329,
-26.2560808253348, -27.4430468037846, -28.9687068837057, -30.8371028962728,
-32.9191236895366, -35.035304478666, -37.0247031066109, -38.8607615381212,
-40.6033135700745, -42.2757985924802, -43.9347147182985, -45.734284638739,
-47.8230575176138, -50.2131479495909, -52.7996085955241, -55.4135980777285,
-57.962173244095, -60.4338737725429, -62.7036155970914, -64.722093717439,
-66.6490938242236, -68.6723847559877, -70.93649618427, -73.4829199486044,
-76.1982303291314, -78.9518922021772, -81.6505070203549, -84.2208249683927,
-86.5850508068946, -88.7756274785869, -90.9313306404693, -93.1660842309518,
-95.6098050275357, -98.3101708329538, -101.169653049083, -104.07705945741,
-106.970214239104, -109.750924471366, -112.329111283685, -114.758201568661,
-117.152289029074, -119.582197861423, -122.096287881144, -124.78120041754,
-127.685325381293, -130.695218841748, -133.656345784662, -136.433116998288,
-139.075149667226, -141.692170350491, -144.301207793699, -146.948554224416,
-149.673388222352, -152.55041823845, -155.598137263283, -158.691017659027,
-161.685986585601, -164.542197231024, -167.328569082727, -170.070148691079,
-172.794098579288, -175.578018860029, -178.445270446267, -181.446562715839,
-184.598352194892, -187.789588146465, -190.893894870588, -193.87582796277,
-196.785183866242, -199.660451700897, -202.532797923263, -205.424194856395,
-208.340769287736, -211.304920755339, -214.344418927964, -217.387551496047,
-220.291822878997, -223.00424797066, -225.533348917433, -227.942695897297,
-230.36234648642, -232.861913227093, -235.424303305764, -238.129397736317,
-241.015605995961, -243.931895840414, -246.715548323266, -249.255374141449,
-251.598714884808, -253.871357158203, -256.160880592109, -258.537852917969,
-261.023366104878, -263.677988241576, -266.490410299427, -269.291167455549,
-271.915326703875, -274.266563363279, -276.415045380095, -278.50033541651,
-280.623191899807, -282.832571741094, -285.157293337129, -287.600552283439,
-290.126384142802, -292.626065376828, -294.915482116937, -296.8922082954,
-298.610875772401, -300.231512287773, -301.916655890747, -303.804240424664,
-305.902084866311, -308.183317348746, -310.591867011654, -312.993617944239,
-315.237108763298, -317.17894930165, -318.872937055682, -320.472759474221,
-322.061959855874, -323.753034472795, -325.621482841452, -327.599116071141,
-329.69696439361, -331.868638811525, -333.88985105192, -335.600106444674,
-337.005756886377, -338.2064865162, -339.327269399958, -340.486325012605,
-341.810048914245, -343.470714892381, -345.418529546771, -347.447478063757,
-349.429456023254, -351.191013078594, -352.595248389517, -353.689252347702,
-354.64064029171, -355.672433912104, -356.996716845187, -358.544798140997,
-360.141319458819, -361.815383255794, -363.538351478514, -365.208599171978,
-366.610204761528, -367.653871307513, -368.466217381122, -369.187443395806,
-370.030427608878, -371.12622937182, -372.429618580391, -373.930335766911,
-375.569520797546, -377.107604849954, -378.394893431059, -379.361571054593,
-380.056867842731, -380.659646406385, -381.372133112047, -382.280834176654,
-383.332680081076, -384.559944695188, -385.951699480774, -387.366089219998,
-388.589846863838, -389.442675141051, -389.923284037789, -390.229839271847,
-390.591599407815, -391.059564749464, -391.714414037031, -392.565651681492,
-393.587091072903, -394.713563706892, -395.788928245077, -396.595447791685,
-397.072440822254, -397.40838461492, -397.688266752608, -398.007102596805,
-398.595147772541, -399.458943444408, -400.430873509522, -401.47090285634,
-402.516064519122), z = c(0, 3.38683848332506, 6.73942240247905,
10.0303107777387, 13.2864582664623, 16.5236739320352, 19.7456728761091,
22.9809172444098, 26.2332919880167, 29.5284881251731, 32.8874403638768,
36.2681341672701, 39.6296423173618, 42.9617816131491, 46.2475822355625,
49.4818495138521, 52.6981144550824, 55.927345075545, 59.1992801685802,
62.5337885027221, 65.9044802578227, 69.280057253288, 72.639827152562,
75.94901199493, 79.2178665013131, 82.4465979734801, 85.6401428884521,
88.8461580431924, 92.0899008317558, 95.3772755010753, 98.720963894315,
102.105446639199, 105.491789465205, 108.850434437514, 112.144957762911,
115.360801681341, 118.528834031761, 121.698658199606, 124.8937299123,
128.15317075757, 131.495276630396, 134.87418159097, 138.229723246027,
141.538297687121, 144.800748794694, 148.002975567416, 151.170055413101,
154.349972128837, 157.57875224427, 160.884040380996, 164.23562985747,
167.596504268331, 170.927743671214, 174.164879470601, 177.280002341053,
180.315898129283, 183.338203171261, 186.402661238693, 189.528305256484,
192.710969086075, 195.942751681331, 199.178629254847, 202.336808282131,
205.330003816225, 208.135027032556, 210.801794092238, 213.429095461752,
216.122544063697, 218.907747854438, 221.758979072197, 224.672886528313,
227.615930590281, 230.480664402728, 233.137882257059, 235.530482940385,
237.704169067339, 239.793497162053, 241.909798296477, 244.095578256242,
246.498208565054, 249.172712204296, 251.947837230072, 254.658520494512,
257.166070734669, 259.384620396627, 261.41083726911, 263.368242978516,
265.344893884986, 267.437131308029, 269.751750101084, 272.264362287533,
274.825922760158, 277.346610292683, 279.686409470373, 281.723842201677,
283.54301091498, 285.25265059731, 286.922982591172, 288.707886707091,
290.743542496069, 292.978664003466, 295.280361774294, 297.591639923275,
299.848397951186, 301.898343816363, 303.615053377941, 305.062887191582,
306.410664098517, 307.866075069628, 309.448778148996, 311.081060098143,
312.777678663393, 314.521915972563, 316.246634176975, 317.771905161294,
318.930750880837, 319.742382143507, 320.360902647948, 320.974304291963,
321.652587689969, 322.508937308483, 323.667685709348, 325.023886927154,
326.406244143962, 327.611472851957, 328.453961080338, 328.914953751674,
329.123906894026, 329.280697601798, 329.507741183512, 329.841680232352,
330.292541887461, 330.815730059541, 331.353373333127, 331.841650310437,
332.080380324658, 331.914616795887, 331.422863253651, 330.810758751205,
330.315938596071, 330.074378820267, 330.212044519981, 330.660732809706,
331.185695067504, 331.62198460866, 331.775861988984, 331.530980443724,
330.92591113599, 330.139158251637, 329.367327831871, 328.695851851461,
328.222814679571, 327.966117957511, 327.795946679113, 327.56047923728,
327.067697396647, 326.192332286799, 324.957748719221, 323.526867953043,
322.092802939544, 320.747317869643, 319.58910759849, 318.612199854356,
317.70160985856, 316.790084250198, 315.697255476398, 314.254972759577,
312.468407853344, 310.476486215513, 308.480156573694, 306.57712069635,
304.935637289146, 303.679102183294, 302.631082759243, 301.597662866323,
300.488641384852, 299.140621343421, 297.4326817513, 295.468761530813,
293.432577696842, 291.445208243892, 289.544028565748, 287.807810538009,
286.229707250672, 284.692841269928, 283.033166647137, 281.098539837969,
278.851365372418, 276.346358016483, 273.73831688747, 271.207949391938,
268.80015144967, 266.477502494836, 264.268354262879, 262.162491300021,
260.053414538758, 257.871567856639, 255.577669825661, 253.083459031906,
250.42370576637, 247.781791966223, 245.334168932516, 243.18180596199,
241.342700610053, 239.666089041187, 237.991951135455, 236.173002050159,
234.189475337485, 232.13614943617, 229.951055788396, 227.698491967576,
225.581085670759, 223.700523516303, 222.095420827998, 220.714615548854,
219.401600539693, 217.975744697712, 216.270127071001, 214.228910278217,
211.951165973092, 209.60362039396, 207.328768989441, 205.172167524536,
203.256068078648, 201.59320324945, 199.998450619509, 198.354704348084,
196.501862137714, 194.436255293541, 192.181352153514, 189.76510509371,
187.390959562139, 185.110271691688, 183.041321591036, 181.205952804635,
179.444260918674, 177.698358260282, 175.783395150807, 173.600126152573,
171.258442094374, 168.783766945263, 166.222758862264, 163.694295078124,
161.295857683714, 159.069926796809, 157.029508160262, 155.112090500317,
153.181154659904, 151.187404301975, 149.102695344265)), .Names = c("x",
"y", "z"), row.names = c(NA, -250L), class = "data.frame")

angle<- 26.565 #degrees
angle<-angle*pi/180
proj2D.x<- (crv.data$x -crv.data$z)*cos(angle)
proj2D.y<-(crv.data$y +crv.data$x+crv.data$z) *sin(0.46365)
proj2d.xy<-cbind(proj2D.x,proj2D.y)
colnames(proj2d.xy)<-c("x","y")

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Hans W Borchers
Sent: Friday, July 24, 2009 5:41 AM
To: r-help at stat.math.ethz.ch
Subject: Re: [R] computing the radius of an arc

Nair, Murlidharan T <mnair <at> iusb.edu> writes:

>
> Hi!!
>
> I am interesting in computing the radius of an arc that best approximates
> a curve. Is there an R function that I can use to draw an arc?
> Nothing useful came up when I searched help.search.  Does anyone have any
> suggestion to do this?
> Thanks ../Murli
>

If you are looking for some formulas to calculate the center and radius
of such a circle/arc, search for 'curvature' in Wikipedia or MathWorld.
Formulas are a bit involved, and you will need to be able to compute
first and second derivatives of the curve.

In case the curve is given as a set of discrete points, you could apply
some polynomial, spline, etc., interpolation.

If you _then_ apply 'draw.arc', watch out to set the aspect ratio to 1,
otherwise your circle may appear to be incorrect.

    library(plotrix)
    curve(sin(x), 0, pi, col="blue", asp=1)
    draw.arc(pi/2, 0, 1, deg1=45, deg2=135, col="red")

Physical meaning of the curvature (and thus the approximation) is that
an observer moving on the curve will feel the same centrifugal forces
as if moving on the circle, at that moment.

Regards
Hans Werner

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list