Shop OBEX P1 Docs P2 Docs Learn Events
XYPOL(x, y) : length, angle32bit confused on angle32 bit — Parallax Forums

XYPOL(x, y) : length, angle32bit confused on angle32 bit

Found this on internet:
'angle32bit means: one turn (0..360°, 0..2Pi) is resolved to the full range of a 32bit integer (0..4294967296)

Is this correct?
Then:
PI = $7FFFFFFF.8 aprox $80000000
2*PI = $FFFF_FFFF = 4_294_967_295 aprox 4_294_967_296 = $1_0000_0000

Using Propeller Constants:
Then:
Propeller constant PI =$4049_0FDB = 1_078_530_011
2*PI = $8092_1FB6 = 2_157_060__022

There apears to be a confusion for the above constants.

How would you convert to degrees?

Test Program ('XYPOL(x, y) : length, angle32bit )
PUB go() |x,y,z,w,rotation,degree
repeat
rotation := 2PI
x := 4
y := 4
z,w := XYPOL( x,y)
debug(udec(x),udec(y),udec(z),udec(w),udec(rotation),uhex(rotation))
debug(uhex(PI),uhex(2
PI),udec(Pi),udec(2*PI))
waitms(3000)

Regards & Thanks
Bob (WRD)

Comments

  • evanhevanh Posts: 16,024
    edited 2021-07-04 23:07

    Hmm, I've not really used Spin ... but I don't think it uses radians for anything. Maybe binfloat does.

    As for degrees, it's not too hard; Choosing, say, two decimal places: degree := muldiv64( angle32, 35999, $ffff_ffff )

  • evanhevanh Posts: 16,024

    Pi being screwy ... Maybe it's an encoded float for using in constants only.

    Certainly an interesting idea to make it suit the binary hardware though. I'd never looked at Pi that way before. It stops being a magic number when it's just $8000_0000. :)

  • RaymanRayman Posts: 14,744

    Seems the explanations for rotations is missing from Spin2 docs.
    But, there is this in the P2 silicon docs:

    (X,Y) ROTATION

    The rotation function inputs three terms: 32-bit signed X and Y values, and an unsigned 32-bit angle, where $00000000..$FFFFFFFF = 0..359.9999999 degrees. The Y term, if non-zero, is supplied via an optional SETQ prefix instruction:

  • evanhevanh Posts: 16,024
    edited 2021-07-05 09:36

    All cordic use descriptions are lacking. Hence my going looking for how to do arctan with the cordic.

    The question is really what does QROTATE do? When QROTATE is used with only two inputs it's known to provide both sine and cosine as results. And, looking at Eric's code, tangent is achieved by dividing the resulting sine by the resulting cosine.

    EDIT: Oh, I guess that kind of answers your question. The QROTATE command is divided into better known functions, like sin() and cos(), in Spin2.

    EDIT2: Ha, forgot which topic I'd posted the acrtan snippet in - https://forums.parallax.com/discussion/comment/1525278/#Comment_1525278

Sign In or Register to comment.