Reputation: 317
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:
-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
This makes an image that looks like this.
Here is my (PHP) code to rotate the points:
$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 );
}
Output:
-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
The resulting image no longer looks good.
What am I doing wrong in my math? I'd like it to still have 90 degree corners where it should, etc.
Thank you! Seth
EDIT: The rest of this exercise is that I'm translating the points to latitude/longitude coordinates for displaying in Google Earth. Translation code:
$x2 = ( $x2 * $scale ) + $latref;
$y2 = ( $y2 * $scale ) + $lonref;
Is my "real" problem (as @joel-in-go points out), the physical distance between degrees of latitude and longitude not equal?
Upvotes: 0
Views: 640
Reputation: 7580
Nothing wrong with your maths - the scales on the X and Y coordinate axes in your graph are not the same :)
Upvotes: 4