tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
85
Task/Quaternion-type/PureBasic/quaternion-type-1.purebasic
Normal file
85
Task/Quaternion-type/PureBasic/quaternion-type-1.purebasic
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
Structure Quaternion
|
||||
a.f
|
||||
b.f
|
||||
c.f
|
||||
d.f
|
||||
EndStructure
|
||||
|
||||
Procedure.f QNorm(*x.Quaternion)
|
||||
ProcedureReturn Sqr(Pow(*x\a, 2) + Pow(*x\b, 2) + Pow(*x\c, 2) + Pow(*x\d, 2))
|
||||
EndProcedure
|
||||
|
||||
;If supplied, the result is returned in the quaternion structure *res,
|
||||
;otherwise a new quaternion is created. A pointer to the result is returned.
|
||||
Procedure QNeg(*x.Quaternion, *res.Quaternion = 0)
|
||||
If *res = 0: *res.Quaternion = AllocateMemory(SizeOf(Quaternion)): EndIf
|
||||
If *res
|
||||
*res\a = -*x\a
|
||||
*res\b = -*x\b
|
||||
*res\c = -*x\c
|
||||
*res\d = -*x\d
|
||||
EndIf
|
||||
ProcedureReturn *res
|
||||
EndProcedure
|
||||
|
||||
Procedure QConj(*x.Quaternion, *res.Quaternion = 0)
|
||||
If *res = 0: *res.Quaternion = AllocateMemory(SizeOf(Quaternion)): EndIf
|
||||
If *res
|
||||
*res\a = *x\a
|
||||
*res\b = -*x\b
|
||||
*res\c = -*x\c
|
||||
*res\d = -*x\d
|
||||
EndIf
|
||||
ProcedureReturn *res
|
||||
EndProcedure
|
||||
|
||||
Procedure QAddReal(r.f, *x.Quaternion, *res.Quaternion = 0)
|
||||
If *res = 0: *res.Quaternion = AllocateMemory(SizeOf(Quaternion)): EndIf
|
||||
If *res
|
||||
*res\a = *x\a + r
|
||||
*res\b = *x\b
|
||||
*res\c = *x\c
|
||||
*res\d = *x\d
|
||||
EndIf
|
||||
ProcedureReturn *res
|
||||
EndProcedure
|
||||
|
||||
Procedure QAddQuaternion(*x.Quaternion, *y.Quaternion, *res.Quaternion = 0)
|
||||
If *res = 0: *res.Quaternion = AllocateMemory(SizeOf(Quaternion)): EndIf
|
||||
If *res
|
||||
*res\a = *x\a + *y\a
|
||||
*res\b = *x\b + *y\b
|
||||
*res\c = *x\c + *y\c
|
||||
*res\d = *x\d + *y\d
|
||||
EndIf
|
||||
ProcedureReturn *res
|
||||
EndProcedure
|
||||
|
||||
Procedure QMulReal_and_Quaternion(r.f, *x.Quaternion, *res.Quaternion = 0)
|
||||
If *res = 0: *res.Quaternion = AllocateMemory(SizeOf(Quaternion)): EndIf
|
||||
If *res
|
||||
*res\a = *x\a * r
|
||||
*res\b = *x\b * r
|
||||
*res\c = *x\c * r
|
||||
*res\d = *x\d * r
|
||||
EndIf
|
||||
ProcedureReturn *res
|
||||
EndProcedure
|
||||
|
||||
Procedure QMulQuaternion(*x.Quaternion, *y.Quaternion, *res.Quaternion = 0)
|
||||
If *res = 0: *res.Quaternion = AllocateMemory(SizeOf(Quaternion)): EndIf
|
||||
If *res
|
||||
*res\a = *x\a * *y\a - *x\b * *y\b - *x\c * *y\c - *x\d * *y\d
|
||||
*res\b = *x\a * *y\b + *x\b * *y\a + *x\c * *y\d - *x\d * *y\c
|
||||
*res\c = *x\a * *y\c - *x\b * *y\d + *x\c * *y\a + *x\d * *y\b
|
||||
*res\d = *x\a * *y\d + *x\b * *y\c - *x\c * *y\b + *x\d * *y\a
|
||||
EndIf
|
||||
ProcedureReturn *res
|
||||
EndProcedure
|
||||
|
||||
Procedure Q_areEqual(*x.Quaternion, *y.Quaternion)
|
||||
If (*x\a <> *y\a) Or (*x\b <> *y\b) Or (*x\c <> *y\c) Or (*x\d <> *y\d)
|
||||
ProcedureReturn 0 ;false
|
||||
EndIf
|
||||
ProcedureReturn 1 ;true
|
||||
EndProcedure
|
||||
29
Task/Quaternion-type/PureBasic/quaternion-type-2.purebasic
Normal file
29
Task/Quaternion-type/PureBasic/quaternion-type-2.purebasic
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
Procedure.s ShowQ(*x.Quaternion, NN = 0)
|
||||
ProcedureReturn "{" + StrF(*x\a, NN) + "," + StrF(*x\b, NN) + "," + StrF(*x\c, NN) + "," + StrF(*x\d, NN) + "}"
|
||||
EndProcedure
|
||||
|
||||
If OpenConsole()
|
||||
Define.Quaternion Q0, Q1, Q2, res, res2
|
||||
Define.f r = 7
|
||||
|
||||
Q0\a = 1: Q0\b = 2: Q0\c = 3: Q0\d = 4
|
||||
Q1\a = 2: Q1\b = 3: Q1\c = 4: Q1\d = 5
|
||||
Q2\a = 3: Q2\b = 4: Q2\c = 5: Q2\d = 6
|
||||
|
||||
PrintN("Q0 = " + ShowQ(Q0, 0))
|
||||
PrintN("Q1 = " + ShowQ(Q1, 0))
|
||||
PrintN("Q2 = " + ShowQ(Q2, 0))
|
||||
|
||||
PrintN("Normal of Q0 = " + StrF(QNorm(Q0)))
|
||||
PrintN("Neg(Q0) = " + ShowQ(QNeg(Q0, res)))
|
||||
PrintN("Conj(Q0) = " + ShowQ(QConj(Q0, res)))
|
||||
PrintN("r + Q0 = " + ShowQ(QAddReal(r, Q0, res)))
|
||||
PrintN("Q0 + Q1 = " + ShowQ(QAddQuaternion(Q0, Q1, res)))
|
||||
PrintN("Q1 + Q2 = " + ShowQ(QAddQuaternion(Q1, Q2, res)))
|
||||
PrintN("Q1 * Q2 = " + ShowQ(QMulQuaternion(Q1, Q2, res)))
|
||||
PrintN("Q2 * Q1 = " + ShowQ(QMulQuaternion(Q2, Q1, res2)))
|
||||
Print( "Q1 * Q2"): If Q_areEqual(res, res2): Print(" = "): Else: Print(" <> "): EndIf: Print( "Q2 * Q1")
|
||||
|
||||
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
|
||||
CloseConsole()
|
||||
EndIf
|
||||
Loading…
Add table
Add a link
Reference in a new issue