06-24-2023, 04:45 PM
Is there any way to have code forum posts preserve all ASCII characters in the 32 to 255 range? For example, often times in my code I'll comment depictions of formulas as ASCII art in my code. I usually embed extended ASCII characters in them for readability. The code box below shows the result of this, versus the picture I included showing what it actually looks like.
Code: (Select All)
SUB Rotate (vec AS Type_Vector2, angleDeg AS SINGLE, origin AS Type_Vector2)
' Rotate a point around an origin using linear transformations.
'
' Rotating from (x,y) to (x',y') |
' | (x',y') : L = R cosé | All of this shows how to get to this
' | ù : A = x' | -----------
' | /.\ : B = L cosè = R cosè cosé = x cosé | |
' | / .è\ : (note - * opposite angles are equal) | |
' | / . \ : C = R siné | +----+
' | / . \ : D = C sinè = R sinè siné = y siné | |
' | / . \ : Y = R sinè | |
' | / . \C : X = r cosè |
' | / . \ __ | -----------------
' | / . \ L stops : x' = B - |AB| = X cosé - Y siné |
' | / . \ here
' | / . \ | All of this just to show how to get from x to x' using (X cosé - Y siné)
' | / . \ | Use the same linear transformation methods to get y' using (X siné + Y cosé)
' | R/ . \ |
' | / .¿ D \ Change the origin point of all rotations to (0,0) by subtracting the current
' | / .------------âù_--ù (x,y) origin point from the current vector length. Add it back when rotation is
' | / . __--. . completed.
' | / . * __-- . .
' | / . __-- . .
' | / L __-- . .
' | / __-- . . .Y
' | / __-- * . . .
' | / __-- . . .
' | / é __-- . . .
' |/__-- è â. . .
' ù-----------------------ù-------------ù---ù------------
' A B
' |------------------- X -------------------|
DIM x AS SINGLE
DIM y AS SINGLE
DIM __cos AS SINGLE
DIM __sin AS SINGLE
DIM xPrime AS SINGLE
DIM yPrime AS SINGLE
x = vec.x - origin.x ' move rotation vector origin to 0
y = vec.y - origin.y
__cos = COS(_D2R(angleDeg)) ' get cosine and sine of angle
__sin = SIN(_D2R(angleDeg))
xPrime = (x * __cos) - (y * __sin) ' calculate rotated location of vector
yPrime = (x * __sin) + (y * __cos)
xPrime = xPrime + origin.x ' move back to original origin
yPrime = yPrime + origin.y
vec.x = xPrime ' pass back rotated vector
vec.y = yPrime
END SUB