
Rotate a set of 2D coordinates about the origin

sjr51
2D waves are organized with x cordinates in first column y coordinates in second column.
To move to a different position ABx ABy and the if-else-endif statements need to be changed.
Function Rotator(wavenames) //Select top graph. Execute with rotator(wavelist("*",";","WIN:")) String wavenames Variable theta, xprime, yprime, xcd, ycd variable i=0 Variable j=0 // i will count through the waves, j will be row index Variable ABx, CDx, ABy, CDy For (i = 0; i < ItemsInList(wavenames); i += 1) String name = StringFromList(i,wavenames) Wave/z w1= $name variable last = dimsize(w1,0) ABx=1 //calculate theta. ABx and ABy are set at 1,0. This will give a 1 unit long line along the x-axis. CDx=w1[last-1][0] //coordinate of last point ABy=0 CDy=w1[last-1][1] theta=acos(((ABx*CDx)+(ABy*CDy))/(sqrt((ABx^2)+(ABy^2))*sqrt((CDx^2)+(CDy^2)))) //answer is in radians // print name, " is ",theta," radians", "or" , theta*(180/pi), "degrees. last-1 =", CDx,",", CDy //remove // for debugging if (CDy<0) theta=theta // execute if condition is TRUE else theta=(2*PI)-theta // execute if condition is FALSE endif //if-elseif-endif statement checks if last point is above the x-axis and corrects the rotation. For (j = 0; j < last; j+=1) xcd = w1[j][0] ycd = w1[j][1] xprime = (xcd*(cos(theta)))-(ycd*(sin(theta))) yprime = (xcd*(sin(theta)))+(ycd*(cos(theta))) w1[j][0] = xprime w1[j][1] = yprime endfor // print "Now y is", ",", yprime //remove // for debugging. Should be ~0. endfor End

Forum

Support

Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
July 28, 2014 at 08:04 am - Permalink
A.G.
WaveMetrics, Inc.
July 28, 2014 at 08:44 am - Permalink