Note that there are some explanatory texts on larger screens.

plurals
  1. PO2D Coordinate rotation - image distorted
    text
    copied!<p>I have an arrow, represented as X,Y points, that I want to rotate 25 degrees. My arrow rotates, but it no longer looks good. The angles are no longer 90 degrees where they should be. The points:</p> <pre><code>-85.0,0.0 -25.0,50.0 -25.0,15.0 85.0,15.0 85.0,-15.0 -25.0,-15.0 -25.0,-50.0 -85.0,0.0 </code></pre> <p>This makes an image <a href="http://itools.subhashbose.com/grapher/index.php?x%5B%5D=-85&amp;y%5B%5D=0&amp;x%5B%5D=-25&amp;y%5B%5D=50&amp;x%5B%5D=-25&amp;y%5B%5D=15&amp;x%5B%5D=85&amp;y%5B%5D=15&amp;x%5B%5D=85&amp;y%5B%5D=-15&amp;x%5B%5D=-25&amp;y%5B%5D=-15&amp;x%5B%5D=-25&amp;y%5B%5D=-50&amp;x%5B%5D=-85&amp;y%5B%5D=0&amp;submit=Plot%20Graph&amp;w=800&amp;h=800&amp;n=&amp;dtsz=Auto&amp;title=Arrow,%20no%20rotation&amp;shax=on&amp;xlbl=&amp;axx=on&amp;aspx=Auto&amp;ylbl=&amp;axy=on&amp;aspy=Auto&amp;sh_lbl_hv=on&amp;nfurl=on&amp;nStrip=on" rel="nofollow">that looks like this</a>.</p> <p>Here is my (PHP) code to rotate the points:</p> <pre><code>$pts = array( array( -85, 0 ), array( -25, 50 ), array( -25, 15 ), array( 85, 15 ), array( 85, -15 ), array( -25, -15 ), array( -25, -50 ), array( -85, 0 ), ); $rotate = deg2rad( 25 ); $sin = sin( $rotate ); $cos = cos( $rotate ); foreach( $pts as $xy ) { list( $x, $y ) = $xy; // Rotate $x2 = ( $x * $cos ) - ( $y * $sin ); $y2 = ( $x * $sin ) + ( $y * $cos ); printf( "%0.3f, %0.3f\n", $x2, $y2 ); } </code></pre> <p>Output:</p> <pre><code>-77.036, -35.923 -43.789, 34.750 -28.997, 3.029 70.697, 49.517 83.375, 22.328 -16.318, -24.160 -1.527, -55.881 -77.036, -35.923 </code></pre> <p>The resulting image <a href="http://itools.subhashbose.com/grapher/index.php?x%5B%5D=-77.036161898115&amp;y%5B%5D=-35.922552247959&amp;x%5B%5D=-43.788607762951&amp;y%5B%5D=34.749932808315&amp;x%5B%5D=-28.996968602027&amp;y%5B%5D=3.0291602620323&amp;x%5B%5D=70.696887972005&amp;y%5B%5D=49.517169053509&amp;x%5B%5D=83.375435824226&amp;y%5B%5D=22.32793544241&amp;x%5B%5D=-16.318420749806&amp;y%5B%5D=-24.160073349067&amp;x%5B%5D=-1.5267815888813&amp;y%5B%5D=-55.88084589535&amp;x%5B%5D=-77.036161898115&amp;y%5B%5D=-35.922552247959&amp;submit=Plot%20Graph&amp;w=800&amp;h=800&amp;n=&amp;dtsz=Auto&amp;title=Arrow,%20rotated%2025%20degrees&amp;shax=on&amp;xlbl=&amp;axx=on&amp;aspx=Auto&amp;ylbl=&amp;axy=on&amp;aspy=Auto&amp;sh_lbl_hv=on&amp;nfurl=on&amp;nStrip=on" rel="nofollow">no longer looks good</a>.</p> <p>What am I doing wrong in my math? I'd like it to still have 90 degree corners where it should, etc.</p> <p>Thank you! Seth</p> <p>EDIT: The rest of this exercise is that I'm translating the points to latitude/longitude coordinates for displaying in Google Earth. Translation code:</p> <pre><code>$x2 = ( $x2 * $scale ) + $latref; $y2 = ( $y2 * $scale ) + $lonref; </code></pre> <p>Is my "real" problem (as @joel-in-go points out), the physical distance between degrees of latitude and longitude not equal?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload