Another useful algorithm that covers these types of situations is the 2D rotational transformation. You do not have to worry about the hypotenuse. Simply provide the x/y coordinates of your points(s) & the angle you want to rotate them. The textbook formula is something like this:
NewPnt.x = OldPnt.x * cos(Ang) - OldPnt.y * sin(Ang)
NewPnt.y = OldPnt.y * cos(Ang) + OldPnt.x * sin(Ang)
You may need to swap the signs based on the coordinate & rotation conventions you are using.
If you need to rotate around an arbitrary point simply add the x/y offset after the rotation.
Here's some code to play with. The A & D keys rotate the points, Esc to exit. Enjoy.
// Project: Rotate2D_test1
// Created: 2015-07-28
// Demonstrates 2D rotation transformation
// by Uncle Martin aka Marty Quire, Tampa, FL
// Set window properties
SetWindowTitle( "Rotate2D_test1" )
SetWindowSize( 1024, 768, 0 )
// Set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
// Define screen center origin
#constant ORG_X = 512
#constant ORG_Y = 384
// Define an x/y point type
type PntTyp
x as float
y as float
endtype
// Define a global shape table of points
global Shape as PntTyp[15]
// Define a point for rotated output
RotPnt as PntTyp
// Save some points in a shape table
SavPnt(0, 50, 10)
SavPnt(1, 60, 35)
SavPnt(2, 70, 60)
SavPnt(3, 80, 35)
SavPnt(4, 90, 10)
SavPnt(5, 100, 35)
SavPnt(6, 110, 60)
SavPnt(7, 120, 35)
SavPnt(8, 130, 10)
MaxPnt = 8
// Define rotation angle
ang# = 0.0
repeat
// Read keys
KeyA = GetRawKeyState(65)
KeyD = GetRawKeyState(68)
KeyEsc = GetRawKeyState(27)
// Increment & decrement rotation angle
if KeyA then ang# = ang# - .2
if KeyD then ang# = ang# + .2
// Diplay rotation angle
printc("Angle=")
print(ang#)
// Draw crosshair at screen center origin
DrawLine(ORG_X-3, ORG_Y, ORG_X+3, ORG_Y, 255, 0, 0)
DrawLine(ORG_X, ORG_Y-3, ORG_X, ORG_Y+3, 255, 0, 0)
// For all points in shape table
for i = 0 to MaxPnt
// Call function to rotate this point to current angle
RotPnt = RotPnt2D(Shape[i], ang#)
// Draw the rotated point
DrawLine(RotPnt.x+ORG_X, -RotPnt.y+ORG_Y, RotPnt.x+ORG_X, -RotPnt.y+ORG_Y, 255, 255, 255)
next i
// Update display
Sync()
until KeyEsc
end
// Function to rotate a 2D point around the origin
function RotPnt2D(OrgPnt as PntTyp, A as float)
NewPnt as PntTyp
NewPnt.x = OrgPnt.x * cos(A) - OrgPnt.y * sin(A)
NewPnt.y = OrgPnt.y * cos(A) + OrgPnt.x * sin(A)
endfunction NewPnt
// Function to save an x/y point into a global shape table
function SavPnt(Index as integer, x as integer, y as integer)
Shape[Index].x = x
Shape[Index].y = y
endfunction
Code every line like it might be your last...
Someday it will be.