Builder.cz - Informacni server o programovani

Odběr fotomagazínu

Fotografický magazín "iZIN IDIF" každý týden ve Vašem e-mailu.
Co nového ve světě fotografie!

 

Zadejte Vaši e-mailovou adresu:

Kamarád fotí rád?

Přihlas ho k odběru fotomagazínu!

 

Zadejte e-mailovou adresu kamaráda:

Soutěž

Sponzorem soutěže je:

IDIF

 

Kdo je autorem výstavy obrazových fotografií „Očima Hanse Christiana Andersena“?

V dnešní soutěži hrajeme o:



Rotace vektoru

Seznam témat     Nová odpověď

Přihlásit se     Registrace     Zapomenuté heslo

Re: Rotace vektoru

Autor: Jerry ♀

9:21:00 06.11.2015

jistě že mám :-) něco ještě ze střední školy
originál :-)

' rotace a posun ve svetovych souradnicich
' perspektiva v ose Z
'
'
'

cls

dim dynamic mX1#(64)
dim dynamic mY1#(64)
dim dynamic mZ1#(64)
dim dynamic mX2#(64)
dim dynamic mY2#(64)
dim dynamic mZ2#(64)

dim dynamic cX1#(64)
dim dynamic cY1#(64)
dim dynamic cZ1#(64)
dim dynamic cX2#(64)
dim dynamic cY2#(64)
dim dynamic cZ2#(64)

dim dynamic ValidLine%(64)


PI#=3.1415927
m#=100

cX#=4000 '4000
cY#=8000 '4000
cZ#=5000 '18000

cPhiX#=0 'pi#/6 'pi#/18
cPhiY#=0'pi#/6 'pi#/12
cPhiZ#=0'pi#/6

screen 12


do

LinesCounter%=0
cls

open "kostel.map" for binary as #1

do

LinesCounter% = LinesCounter% + 1
text$=""

do

get$ #1,1,char$
text$=text$+char$
if inkey$=chr$(27) then end

loop until char$=chr$(10)

select case left$(text$,1)
case "?"

case "z"

case "p"

mX1#(LinesCounter%)=val(mid$(text$,3,instr(3,text$,",")-3))
p=instr(3,text$,",")+1
mY1#(LinesCounter%)=val(mid$(text$,p,instr(p,text$,",")-p ) )
p=instr(p,text$,",")+1
mZ1#(LinesCounter%)=val(mid$(text$,p,instr(p,text$,"-")-p ) )
p=instr(p,text$,"-")+1
mX2#(LinesCounter%)=val(mid$(text$,p,instr(p,text$,",")-p ) )
p=instr(p,text$,",")+1
mY2#(LinesCounter%)=val(mid$(text$,p,instr(p,text$,",")-p ) )
p=instr(p,text$,",")+1
mZ2#(LinesCounter%)=val(mid$(text$,p,instr(p,text$,";")-p ) )

end select

if inkey$=chr$(27) then end

loop until left$(text$,1)="z"

close #1

rem ****************************************************

FOR I%=1 TO LinesCounter% STEP 1

cX1#(I%) = mX1#(I%) - cX#
cY1#(I%) = mY1#(I%) - cY#
cZ1#(I%) = mZ1#(I%) - cZ#
cX2#(I%) = mX2#(I%) - cX#
cY2#(I%) = mY2#(I%) - cY#
cZ2#(I%) = mZ2#(I%) - cZ#

NEXT I%

FOR I%=1 to LinesCounter%

rem rovina XY, rotace okolo Z
x1t1#=cX1#(I%)*cos(cPhiZ#)+cY1#(I%)*sin(cPhiZ#)
y1t1#=cY1#(I%)*cos(cPhiZ#)-cX1#(I%)*sin(cPhiZ#)
z1t1#=cZ1#(I%)
x2t1#=cX2#(I%)*cos(cPhiZ#)+cY2#(I%)*sin(cPhiZ#)
y2t1#=cY2#(I%)*cos(cPhiZ#)-cX2#(I%)*sin(cPhiZ#)
z2t1#=cZ2#(I%)

rem rovina XZ, rotace okolo Y
x1t2#=x1t1#*cos(cPhiY#)+z1t1#*sin(cPhiY#)
y1t2#=y1t1#
z1t2#=z1t1#*cos(cPhiY#)-x1t1#*sin(cPhiY#)
x2t2#=x2t1#*cos(cPhiY#)+z2t1#*sin(cPhiY#)
y2t2#=y2t1#
z2t2#=z2t1#*cos(cPhiY#)-x2t1#*sin(cPhiY#)

rem rovina YZ, rotace okolo X
x1t3#=x1t2#
y1t3#=y1t2#*cos(cPhiX#)+z1t2#*sin(cPhiX#)
z1t3#=z1t2#*cos(cPhiX#)-y1t2#*sin(cPhiX#)
x2t3#=x2t2#
y2t3#=y2t2#*cos(cPhiX#)+z2t2#*sin(cPhiX#)
z2t3#=z2t2#*cos(cPhiX#)-y2t2#*sin(cPhiX#)

cX1#(I%) = x1t3#
cY1#(I%) = y1t3#
cZ1#(I%) = z1t3#
cX2#(I%) = x2t3#
cY2#(I%) = y2t3#
cZ2#(I%) = z2t3#

NEXT I%

FOR I%=1 TO LinesCounter%

Mark%=&B00 ' rovina Sigma.6
IF ( ((+1)*cY1#(I%)) + ((+1)*cZ1#(I%)) ) > 0 THEN Mark% = Mark% OR &B01
IF ( ((+1)*cY2#(I%)) + ((+1)*cZ2#(I%)) ) > 0 THEN Mark% = Mark% OR &B10
SELECT CASE Mark%
CASE &B00 'AB out
ValidLine%(I%) = 1
CASE &B11 'AB in
ValidLine%(I%) = 2
CASE &B01 'B out
ValidLine%(I%) = 3
u1#=cX2#(I%) - cX1#(I%)
u2#=cY2#(I%) - cY1#(I%)
u3#=cZ2#(I%) - cZ1#(I%)
t=((-1)*((0)*cX2#(I%) + (+1)*cY2#(I%) + (+1)*cZ2#(I%) - 0))/_
((0)*u1# + (+1)*u2# + (+1)*u3#)
cX2#(I%) = cX2#(I%) + u1#*t
cY2#(I%) = cY2#(I%) + u2#*t
cZ2#(I%) = cZ2#(I%) + u3#*t
CASE &B10 'A out
ValidLine%(I%) = 4
u1#=cX2#(I%) - cX1#(I%)
u2#=cY2#(I%) - cY1#(I%)
u3#=cZ2#(I%) - cZ1#(I%)
t=((-1)*((0)*cX1#(I%) + (+1)*cY1#(I%) + (+1)*cZ1#(I%) - 0))/_
((0)*u1# + (+1)*u2# + (+1)*u3#)
cX1#(I%) = cX1#(I%) + u1#*t
cY1#(I%) = cY1#(I%) + u2#*t
cZ1#(I%) = cZ1#(I%) + u3#*t
END SELECT

IF ValidLine%(I%)>1 THEN
Mark%=&B00 ' rovina Sigma.5
IF ( ((+1)*cY1#(I%)) + ((-1)*cZ1#(I%)) ) < 0 THEN Mark% = Mark% OR &B01
IF ( ((+1)*cY2#(I%)) + ((-1)*cZ2#(I%)) ) < 0 THEN Mark% = Mark% OR &B10
SELECT CASE Mark%
CASE &B00 'AB out
ValidLine%(I%) = 1
CASE &B11 'AB in
ValidLine%(I%) = 2
CASE &B01 'B out
ValidLine%(I%) = 3
u1#=cX2#(I%) - cX1#(I%)
u2#=cY2#(I%) - cY1#(I%)
u3#=cZ2#(I%) - cZ1#(I%)
t=((-1)*((0)*cX2#(I%) + (+1)*cY2#(I%) + (-1)*cZ2#(I%) - 0))/_
((0)*u1# + (+1)*u2# + (-1)*u3#)
cX2#(I%) = cX2#(I%) + u1#*t
cY2#(I%) = cY2#(I%) + u2#*t
cZ2#(I%) = cZ2#(I%) + u3#*t
CASE &B10 'A out
ValidLine%(I%) = 4
u1#=cX2#(I%) - cX1#(I%)
u2#=cY2#(I%) - cY1#(I%)
u3#=cZ2#(I%) - cZ1#(I%)
t=((-1)*((0)*cX1#(I%) + (+1)*cY1#(I%) + (-1)*cZ1#(I%) - 0))/_
((0)*u1# + (+1)*u2# + (-1)*u3#)
cX1#(I%) = cX1#(I%) + u1#*t
cY1#(I%) = cY1#(I%) + u2#*t
cZ1#(I%) = cZ1#(I%) + u3#*t
END SELECT
END IF
IF ValidLine%(I%)>1 THEN
Mark%=&B00 ' rovina Sigma.4
IF ( ((-1)*cX1#(I%)) + ((-1)*cZ1#(I%)) ) < 0 THEN Mark% = Mark% OR &B01
IF ( ((-1)*cX2#(I%)) + ((-1)*cZ2#(I%)) ) < 0 THEN Mark% = Mark% OR &B10
SELECT CASE Mark%
CASE &B00 'AB out
ValidLine%(I%) = 1
CASE &B11 'AB in
ValidLine%(I%) = 2
CASE &B01 'B out
ValidLine%(I%) = 3
u1#=cX2#(I%) - cX1#(I%)
u2#=cY2#(I%) - cY1#(I%)
u3#=cZ2#(I%) - cZ1#(I%)
t=((-1)*((-1)*cX2#(I%) + (0)*cY2#(I%) + (-1)*cZ2#(I%) - 0))/_
((-1)*u1# + (0)*u2# + (-1)*u3#)
cX2#(I%) = cX2#(I%) + u1#*t
cY2#(I%) = cY2#(I%) + u2#*t
cZ2#(I%) = cZ2#(I%) + u3#*t
CASE &B10 'A out
ValidLine%(I%) = 4
u1#=cX2#(I%) - cX1#(I%)
u2#=cY2#(I%) - cY1#(I%)
u3#=cZ2#(I%) - cZ1#(I%)
t=((-1)*((-1)*cX1#(I%) + (0)*cY1#(I%) + (-1)*cZ1#(I%) - 0))/_
((-1)*u1# + (0)*u2# + (-1)*u3#)
cX1#(I%) = cX1#(I%) + u1#*t
cY1#(I%) = cY1#(I%) + u2#*t
cZ1#(I%) = cZ1#(I%) + u3#*t
END SELECT
END IF

IF ValidLine%(I%)>1 THEN
Mark%=&B00 ' rovina Sigma.3
IF ( ((-1)*cX1#(I%)) + ((+1)*cZ1#(I%)) ) > 0 THEN Mark% = Mark% OR &B01
IF ( ((-1)*cX2#(I%)) + ((+1)*cZ2#(I%)) ) > 0 THEN Mark% = Mark% OR &B10
SELECT CASE Mark%
CASE &B00 'AB out
ValidLine%(I%) = 1
CASE &B11 'AB in
ValidLine%(I%) = 2
CASE &B01 'B out
ValidLine%(I%) = 3
u1#=cX2#(I%) - cX1#(I%)
u2#=cY2#(I%) - cY1#(I%)
u3#=cZ2#(I%) - cZ1#(I%)
t=((-1)*((-1)*cX2#(I%) + (0)*cY2#(I%) + (+1)*cZ2#(I%) - 0))/_
((-1)*u1# + (0)*u2# + (+1)*u3#)
cX2#(I%) = cX2#(I%) + u1#*t
cY2#(I%) = cY2#(I%) + u2#*t
cZ2#(I%) = cZ2#(I%) + u3#*t
CASE &B10 'A out
ValidLine%(I%) = 4
u1#=cX2#(I%) - cX1#(I%)
u2#=cY2#(I%) - cY1#(I%)
u3#=cZ2#(I%) - cZ1#(I%)
t=((-1)*((-1)*cX1#(I%) + (0)*cY1#(I%) + (+1)*cZ1#(I%) - 0))/_
((-1)*u1# + (0)*u2# + (+1)*u3#)
cX1#(I%) = cX1#(I%) + u1#*t
cY1#(I%) = cY1#(I%) + u2#*t
cZ1#(I%) = cZ1#(I%) + u3#*t
END SELECT
END IF

IF ValidLine%(I%)>1 THEN
Mark%=&B00 ' rovina Sigma.2
IF ( ((-1)*cZ1#(I%)) + 100000 ) > 0 THEN Mark% = Mark% OR &B01
IF ( ((-1)*cZ2#(I%)) + 100000 ) > 0 THEN Mark% = Mark% OR &B10
SELECT CASE Mark%
CASE &B00 'AB out
ValidLine%(I%) = 1
CASE &B11 'AB in
ValidLine%(I%) = 2
CASE &B01 'B out
ValidLine%(I%) = 3
u1#=cX2#(I%) - cX1#(I%)
u2#=cY2#(I%) - cY1#(I%)
u3#=cZ2#(I%) - cZ1#(I%)
t=((-1)*((0)*cX2#(I%) + (0)*cY2#(I%) + (-1)*cZ2#(I%) + 100000))/_
((0)*u1# + (0)*u2# + (-1)*u3#)
cX2#(I%) = cX2#(I%) + u1#*t
cY2#(I%) = cY2#(I%) + u2#*t
cZ2#(I%) = cZ2#(I%) + u3#*t
CASE &B10 'A out
ValidLine%(I%) = 4
u1#=cX2#(I%) - cX1#(I%)
u2#=cY2#(I%) - cY1#(I%)
u3#=cZ2#(I%) - cZ1#(I%)
t=((-1)*((0)*cX1#(I%) + (0)*cY1#(I%) + (-1)*cZ1#(I%) + 100000))/_
((0)*u1# + (0)*u2# + (-1)*u3#)
cX1#(I%) = cX1#(I%) + u1#*t
cY1#(I%) = cY1#(I%) + u2#*t
cZ1#(I%) = cZ1#(I%) + u3#*t
END SELECT
END IF

IF ValidLine%(I%)>1 THEN
Mark%=&B00 ' rovina Sigma.1
IF ( ((-1)*cZ1#(I%)) + 460 ) < 0 THEN Mark% = Mark% OR &B01
IF ( ((-1)*cZ2#(I%)) + 460 ) < 0 THEN Mark% = Mark% OR &B10
SELECT CASE Mark%
CASE &B00 'AB out
ValidLine%(I%) = 1
CASE &B11 'AB in
ValidLine%(I%) = 2
CASE &B01 'B out
ValidLine%(I%) = 3
u1#=cX2#(I%) - cX1#(I%)
u2#=cY2#(I%) - cY1#(I%)
u3#=cZ2#(I%) - cZ1#(I%)
t=((-1)*((0)*cX2#(I%) + (0)*cY2#(I%) + (-1)*cZ2#(I%) + 460))/_
((0)*u1# + (0)*u2# + (-1)*u3#)
cX2#(I%) = cX2#(I%) + u1#*t
cY2#(I%) = cY2#(I%) + u2#*t
cZ2#(I%) = cZ2#(I%) + u3#*t
CASE &B10 'A out
ValidLine%(I%) = 4
u1#=cX2#(I%) - cX1#(I%)
u2#=cY2#(I%) - cY1#(I%)
u3#=cZ2#(I%) - cZ1#(I%)
t=((-1)*((0)*cX1#(I%) + (0)*cY1#(I%) + (-1)*cZ1#(I%) + 460))/_
((0)*u1# + (0)*u2# + (-1)*u3#)
cX1#(I%) = cX1#(I%) + u1#*t
cY1#(I%) = cY1#(I%) + u2#*t
cZ1#(I%) = cZ1#(I%) + u3#*t
END SELECT
END IF

NEXT I%

VIEW(100,100)-(475,475),,2
WINDOW(-25000,-25000)-(25000,25000)

line (0,0)-(15000,0),4
line (0,0)-(0,15000),4
line (0,0)-(-15000,0),4
line (0,0)-(0,-15000),4

FOR I%=1 TO LinesCounter%

If ValidLine%(I%)>1 then


line (cX1#(I%)*m#*(1/(cZ1#(I%)/230)),_
cY1#(I%)*m#*(1/(cZ1#(I%)/230)))-_
(cX2#(I%)*m#*(1/(cZ2#(I%)/230)),_
cY2#(I%)*m#*(1/(cZ2#(I%)/230))),14
end if

NEXT I%

kbRightArrow$=CHR$(0)+CHR$(77)
kbLeftArrow$ =CHR$(0)+CHR$(75)
kbUpArrow$=CHR$(0)+CHR$(72)
kbDownArrow$ =CHR$(0)+CHR$(80)
kbHome$=CHR$(0)+CHR$(71)
kbEnd$=CHR$(0)+CHR$(79)

DO
char$=inkey$
LOOP UNTIL char$<>"
locate 3,1
? char$

SELECT CASE char$
CASE "r",kbRightArrow$ 'posun v ose kamery +X
x#=0 + 200
y#=0
z#=0

rem rovina YZ, rotace okolo X
x1t1#=+x#
y1t1#=+y#*cos(cPhiX#)-z#*sin(cPhiX#)
z1t1#=+y#*sin(cPhiX#)+z#*cos(cPhiX#)

rem rovina XZ, rotace okolo Y
x1t2#=+x1t1#*cos(cPhiY#)-z1t1#*sin(cPhiY#)
y1t2#=+y1t1#
z1t2#=+x1t1#*sin(cPhiY#)+z1t1#*cos(cPhiY#)

rem rovina XY, rotace okolo Z
x1t3#=+x1t2#*cos(cPhiZ#)-y1t2#*sin(cPhiZ#)
y1t3#=+x1t2#*sin(cPhiZ#)+y1t2#*cos(cPhiZ#)
z1t3#=+z1t2#

cX# = FIX(cX# + x1t3#)
cY# = FIX(cY# + y1t3#)
cZ# = FIX(cZ# + z1t3#)

CASE "f", kbLeftArrow$ 'posun v ose kamery -X

x#=0 - 200
y#=0
z#=0

rem rovina YZ, rotace okolo X
x1t1#=+x#
y1t1#=+y#*cos(cPhiX#)-z#*sin(cPhiX#)
z1t1#=+y#*sin(cPhiX#)+z#*cos(cPhiX#)

rem rovina XZ, rotace okolo Y
x1t2#=+x1t1#*cos(cPhiY#)-z1t1#*sin(cPhiY#)
y1t2#=+y1t1#
z1t2#=+x1t1#*sin(cPhiY#)+z1t1#*cos(cPhiY#)

rem rovina XY, rotace okolo Z
x1t3#=+x1t2#*cos(cPhiZ#)-y1t2#*sin(cPhiZ#)
y1t3#=+x1t2#*sin(cPhiZ#)+y1t2#*cos(cPhiZ#)
z1t3#=+z1t2#

cX# = FIX(cX# + x1t3#)
cY# = FIX(cY# + y1t3#)
cZ# = FIX(cZ# + z1t3#)

CASE "t",kbHome$ 'posun v ose kamery +Y

x#=0
y#=0 + 200
z#=0

rem rovina YZ, rotace okolo X
x1t1#=+x#
y1t1#=+y#*cos(cPhiX#)-z#*sin(cPhiX#)
z1t1#=+y#*sin(cPhiX#)+z#*cos(cPhiX#)

rem rovina XZ, rotace okolo Y
x1t2#=+x1t1#*cos(cPhiY#)-z1t1#*sin(cPhiY#)
y1t2#=+y1t1#
z1t2#=+x1t1#*sin(cPhiY#)+z1t1#*cos(cPhiY#)

rem rovina XY, rotace okolo Z
x1t3#=+x1t2#*cos(cPhiZ#)-y1t2#*sin(cPhiZ#)
y1t3#=+x1t2#*sin(cPhiZ#)+y1t2#*cos(cPhiZ#)
z1t3#=+z1t2#

cX# = FIX(cX# + x1t3#)
cY# = FIX(cY# + y1t3#)
cZ# = FIX(cZ# + z1t3#)

CASE "g",kbEnd$ 'posun v ose kamery -Y

x#=0
y#=0 - 200
z#=0

rem rovina YZ, rotace okolo X
x1t1#=+x#
y1t1#=+y#*cos(cPhiX#)-z#*sin(cPhiX#)
z1t1#=+y#*sin(cPhiX#)+z#*cos(cPhiX#)

rem rovina XZ, rotace okolo Y
x1t2#=+x1t1#*cos(cPhiY#)-z1t1#*sin(cPhiY#)
y1t2#=+y1t1#
z1t2#=+x1t1#*sin(cPhiY#)+z1t1#*cos(cPhiY#)

rem rovina XY, rotace okolo Z
x1t3#=+x1t2#*cos(cPhiZ#)-y1t2#*sin(cPhiZ#)
y1t3#=+x1t2#*sin(cPhiZ#)+y1t2#*cos(cPhiZ#)
z1t3#=+z1t2#

cX# = FIX(cX# + x1t3#)
cY# = FIX(cY# + y1t3#)
cZ# = FIX(cZ# + z1t3#)

CASE "y",kbUpArrow$ 'posun v ose kamery +Z

x#=0
y#=0
z#=0 + 200

rem rovina YZ, rotace okolo X
x1t1#=+x#
y1t1#=+y#*cos(cPhiX#)-z#*sin(cPhiX#)
z1t1#=+y#*sin(cPhiX#)+z#*cos(cPhiX#)

rem rovina XZ, rotace okolo Y
x1t2#=+x1t1#*cos(cPhiY#)-z1t1#*sin(cPhiY#)
y1t2#=+y1t1#
z1t2#=+x1t1#*sin(cPhiY#)+z1t1#*cos(cPhiY#)

rem rovina XY, rotace okolo Z
x1t3#=+x1t2#*cos(cPhiZ#)-y1t2#*sin(cPhiZ#)
y1t3#=+x1t2#*sin(cPhiZ#)+y1t2#*cos(cPhiZ#)
z1t3#=+z1t2#

cX# = FIX(cX# + x1t3#)
cY# = FIX(cY# + y1t3#)
cZ# = FIX(cZ# + z1t3#)

CASE "h",kbDownArrow$ 'posun v ose kamery -Z

x#=0
y#=0
z#=0 - 200

rem rovina YZ, rotace okolo X
x1t1#=+x#
y1t1#=+y#*cos(cPhiX#)-z#*sin(cPhiX#)
z1t1#=+y#*sin(cPhiX#)+z#*cos(cPhiX#)

rem rovina XZ, rotace okolo Y
x1t2#=+x1t1#*cos(cPhiY#)-z1t1#*sin(cPhiY#)
y1t2#=+y1t1#
z1t2#=+x1t1#*sin(cPhiY#)+z1t1#*cos(cPhiY#)

rem rovina XY, rotace okolo Z
x1t3#=+x1t2#*cos(cPhiZ#)-y1t2#*sin(cPhiZ#)
y1t3#=+x1t2#*sin(cPhiZ#)+y1t2#*cos(cPhiZ#)
z1t3#=+z1t2#

cX# = FIX(cX# + x1t3#)
cY# = FIX(cY# + y1t3#)
cZ# = FIX(cZ# + z1t3#)

CASE "u"
m#=m#+5
CASE "j"
m#=m#-5

CASE "q" 'rotace (+) okolo X v rovine YZ

cPhiX#=cPhiX#+0.174
IF cPhiX#>2*PI# THEN
cPhiX#=cPhiX#-(2*PI#)
END IF

CASE "a"

cPhiX#=cPhiX#-0.174
IF cPhiX#<0 THEN
cPhiX#=(2*PI#)-abs(cPhiX#)
END IF

CASE "w" 'rotace (+) okolo Y v rovine XZ

cPhiY#=cPhiY#+0.174
IF cPhiY#>2*PI# THEN
cPhiY#=cPhiY#-(2*PI#)
END IF

CASE "s" 'rotace (-) okolo Y v rovine XZ

cPhiY#=cPhiY#-0.174
IF cPhiY#<0 THEN
cPhiY#=(2*PI#)-ABS(cPhiY#)
END IF

CASE "e" 'rotace (+) okolo Z v rovine XY

cPhiZ#=cPhiZ#+0.174
IF cPhiZ#>2*PI# THEN
cPhiZ#=cPhiZ#-(2*PI#)
END IF

CASE "d" 'rotace (-) okolo Z v rovine XY

cPhiZ#=cPhiZ#-0.174
IF cPhiZ#<0 THEN
cPhiZ#=(2*PI#)-ABS(cPhiZ#)
END IF

CASE "z"
cPhiX#=0
CASE "x"
cPhiY#=0
CASE "c"
cPhiZ#=0

CASE "p"

cX#=0
cY#=0
cZ#=0
cPhiX#=0
cPhiY#=0
cPhiZ#=0

END SELECT


locate 1,1
? "cX:";cX#;"cY:";cY#;"cZ:";cZ#;" "
locate 2,1
? string$(80," ")
locate 2,1
? "cfX:";FIX((360/(2*PI#))*cPhiX#);_
"cfY:";FIX((360/(2*PI#))*cPhiY#);_
"cfZ:";FIX((360/(2*PI#))*cPhiY#);

loop until char$=chr$(27)


end





Citovat příspěvek

 

Re: Rotace vektoru

Autor: dfdsfgecffx ♂

17:13:50 04.11.2015

ta hrozna megamatice vznikla nasobenim matic 3x3 pro rotaci kolem x,y,z.
nemas tam renonc?

Citovat příspěvek

 

Re: Rotace vektoru

Autor: JerryM ♀

13:55:03 03.11.2015

Ten tvůj algoritmus je nějakej divnej
nejdřív rotuješ např. kolem X pak Y a pak Z
takže to co dostaneš z rotace kolem X vložíš do další rovnice atd...
to nikde nevidim....
k rotaci ti stačí klasický dvě rovnice na rotaci ve 2D kolem středu [0,0] jak je znáš z tabulek

Citovat příspěvek

 

Rotace vektoru

Autor: tlustoprd ♂

11:07:03 02.11.2015

Ahoj, potrebuji rotovat vektor kolem os x, y, z o uhel alfa, beta, gama. Vsechny pohyby mohou probihat soucasne. Uvaha byla takova, ze mezi sebou vynasobim matice rotace pro jednotlive osy a vyslednou "megamatici" pote nasobim vektorem, ktery chci rotovat.

"Megamatici" jsem spocital zde: http://www.wolframalpha.com/input/?i=matrix+multiplication&a=*C.matrix+multiplication-_*Calculator.dflt-&f2=%7B%7B1%2C0%2C0%7D%2C%7B0%2C+cos(A)%2C+-sin(A)%7D%2C%7B0%2Csin(A)%2Ccos(A)%7D%7D&f=MatricesOperations.theMatrix1%5Cu005f%7B%7B1%2C0%2C0%7D%2C%7B0%2C+cos(A)%2C+-sin(A)%7D%2C%7B0%2Csin(A)%2Ccos(A)%7D%7D&f3=%7B%7Bcos(B)%2C0%2Csin(B)%7D%2C%7B0%2C1%2C0%7D%2C%7B-sin(B)%2C0%2Ccos(B)%7D%7D&f=MatricesOperations.theMatrix2%5Cu005f%7B%7Bcos(B)%2C0%2Csin(B)%7D%2C%7B0%2C1%2C0%7D%2C%7B-sin(B)%2C0%2Ccos(B)%7D%7D&f4=%7B%7Bcos(C)%2C-sin(C)%2C0%7D%2C%7Bsin(C)%2Ccos(C)%2C0%7D%2C%7B0%2C0%2C1%7D%7D&f=MatricesOperations.theMatrix3_%7B%7Bcos(C)%2C-sin(C)%2C0%7D%2C%7Bsin(C)%2Ccos(C)%2C0%7D%2C%7B0%2C0%2C1%7D%7D

V soucasne dobe na to pouzivam nasledujici kod, ktery, az na rotaci kolem osy x, funguje:

.
.
.
double result[3];
double vectorToRotate[3] = {Record->X, Record->Y, Record->Z};
fillRotationMatrix(rotationMatrix, pitchDelta, rollDelta, yawDelta);
multiplyMatrix(rotationMatrix, vectorToRotate, result);
.
.
.
void CConvertor::fillRotationMatrix(double rotationMatrix[3][3], double alpha/*pitch*/, double beta/*roll*/, double gama/*yaw*/)
{
//first row
rotationMatrix[0][0] = cos(beta)*cos(gama);
rotationMatrix[0][1] = -cos(beta)*sin(gama);
rotationMatrix[0][2] = sin(beta);

//second row
rotationMatrix[1][0] = cos(gama)*sin(alpha)*sin(beta) + cos(alpha)*sin(gama);
rotationMatrix[1][1] = cos(alpha)*cos(gama) - sin(alpha)*sin(beta)*sin(gama);
rotationMatrix[1][2] = -cos(beta)*sin(alpha);

//third row
rotationMatrix[2][0] = sin(alpha)*sin(gama) - cos(alpha)*cos(gama)*sin(beta);
rotationMatrix[2][1] = cos(gama)*sin(alpha) + cos(alpha)*sin(beta)*sin(gama);
rotationMatrix[2][2] = cos(alpha)*cos(beta);
}

void CConvertor::multiplyMatrix(double inputMatrix[3][3], double inputVector[3], double outputVector[3])
{
const int ROWS = 3;
const int COLS = 3;
int i;
for (i = 0; i < ROWS; i++)
outputVector[i] = vectors_dot_prod(inputMatrix[i], inputVector, COLS);
}

double CConvertor::vectors_dot_prod(const double *x, const double *y, const int n)
{
double res = 0;
for (int i = 0; i < n; i++)
res += x[i] * y[i];
return res;
}

Nevedeli byste nekdo, kde muze byt problem? :-(

Citovat příspěvek

 

 

 

Přihlášení k mému účtu

Uživatelské jméno:

Heslo: