cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
%3CLINGO-SUB%20id%3D%22lingo-sub-236281%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EComment%20calculer%20le%20produit%20crois%C3%A9%20vectoriel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-236281%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ED'apr%C3%A8s%20la%20documentation%2C%20il%20semble%20que%20l'op%C3%A9rateur%20*%20effectuera%20un%20produit%20vectoriel%20et%20%3B*%20effectuera%20un%20produit%20scalaire.%20Je%20souhaite%20utiliser%20un%20produit%20vectoriel%20pour%20d%C3%A9terminer%20le%20vecteur%20normal%20%C3%A0%20une%20paire%20de%20vecteurs%20connus%20comme%20ceci%26nbsp%3B%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Ep1%20%3D%20%5B1%2C%202%2C%204%5D%3B%0Ap2%20%3D%20%5B2%2C%201%2C%204%5D%3B%0Ap3%20%3D%20%5B2%2C%202%2C%204%5D%3B%0A%0Av1%20%3D%20p3%20-%20p1%3B%0Av2%20%3D%20p2%20-%20p1%3B%0A%0AxProd%20%3D%20v1*v2%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E3%20points%20d%C3%A9finissent%20un%20plan%2C%20deux%20vecteurs%20pris%20%C3%A0%20partir%20de%20ces%20points%20font%20de%20m%C3%AAme%2C%20le%20produit%20vectoriel%20doit%20donner%20le%20vecteur%20normal%20de%20ce%20plan.%20Le%20probl%C3%A8me%20semble%20%C3%AAtre%20que%20les%20dimensions%20des%20deux%20matrices%20multipli%C3%A9es%20(v1%20et%20v2)%20ne%20concordent%20pas%26nbsp%3B%3A%20nRows(v1)%20devrait%20%C3%AAtre%20%C3%A9gal%20%C3%A0%20nCols(v2).%20Je%20peux%20l'impl%C3%A9menter%20manuellement%20avec%20une%20formule%20simplifi%C3%A9e%20pour%20les%20produits%20crois%C3%A9s%20vectoriels%2C%20mais%20est-ce%20que%20quelqu'un%20sait%20comment%20le%20formater%20diff%C3%A9remment%20pour%20travailler%20avec%20la%20multiplication%20matricielle%20%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-611821%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%20%3A%20Comment%20calculer%20le%20produit%20crois%C3%A9%20vectoriel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-611821%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ELes%20performances%20inf%C3%A9rieures%20ne%20sont%20pas%20surprenantes...%20merci%20d'avoir%20ins%C3%A9r%C3%A9%20le%20r%C3%A9glage%20du%20signe.%20J'ai%20omis%20le%20%22signe%20en%20damier%22%20par%20inadvertance.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOMI%2C%20c'est%20l'un%20de%20ces%20cas%20o%C3%B9%20%22ce%20n'est%20pas%20parce%20que%20vous%20pouvez%20le%20faire%20que%20vous%20devriez%22%20s'appliquer...%20%7Bcool%2C%20amusant%2C%20court%7D%20ne%20l'emporte%20pas%20sur%20%7Bcompr%C3%A9hensible%2C%20maintenable%2C%20rapide%7D.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-611720%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%20%3A%20Comment%20calculer%20le%20produit%20crois%C3%A9%20vectoriel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-611720%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F3552%22%20target%3D%22_blank%22%3E%40brady_brady%3C%2FA%3E%20Cool!%20Il%20a%20besoin%20d'un%20ajustement%20si%20vous%20comptez%20l'utiliser%26nbsp%3B%3A%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%20i%20%3D%201%3B%0A%20j%20%3D%20-1%3B%0A%20J(%203%2C%201%2C%20(j%20*%3D%20-1)%20*%20Det(%20(v1%20%7C%7C%20v2)%5BRemove(%20%5B1%2C%202%2C%203%5D%2C%20i%2B%2B%20)%2C%200%5D%20)%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%3C%2FCODE%3E%3CA%20href%3D%22https%3A%2F%2Fmathinsight.org%2Fcross_product_formula%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fmathinsight.org%2Fcross_product_formula%3C%2FA%3E%20montre%20comment%20l'%C3%A9l%C3%A9ment%20du%20milieu%20doit%20%C3%AAtre%20n%C3%A9gatif.Ci-dessus%2C%20j%20alternera%20de%20signe%20(1%2C%20-1%2C%201)%20et%20i%20augmentera%20(1%2C%202%2C%203).%20La%20fonction%20J(...)%20a%20une%20boucle%20implicite%20qui%20%C3%A9value%20le%203%C3%A8me%20argument%20pour%20chaque%20%C3%A9l%C3%A9ment.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELa%20formule%20simple%20et%20corrig%C3%A9e%20de%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F11962%22%20target%3D%22_blank%22%3E%20%40klk%3C%2FA%3E%20est%20environ%203%20fois%20plus%20rapide%20et%20environ%20N%20fois%20plus%20facile%20%C3%A0%20comprendre.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECode%20de%20test.%3C%2FP%3E%0A%3CDIV%20class%3D%22lia-spoiler-container%22%3E%3CA%20class%3D%22lia-spoiler-link%22%20href%3D%22%23%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EVoir%20plus...%3C%2FA%3E%3CNOSCRIPT%3E%3CDIV%20class%3D%22lia-spoiler-content%22%3E%3CBR%20%2F%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Ev1%20%3D%20%5B0%2C%200%2C%201%5D%3B%0Av2%20%3D%20%5B0%2C%201%2C%200%5D%3B%0A%0Astart%20%3D%20HP%20Time()%3B%0AFor(%20t%20%3D%201%2C%20t%20%26lt%3B%201e6%2C%20t%20%2B%3D%201%2C%0A%20i%20%3D%201%3B%0A%20j%20%3D%20-1%3B%0A%20J(%203%2C%201%2C%20(j%20*%3D%20-1)%20*%20Det(%20(v1%20%7C%7C%20v2)%5BRemove(%20%5B1%2C%202%2C%203%5D%2C%20i%2B%2B%20)%2C%200%5D%20)%20)%3B%0A)%3B%0Astop%20%3D%20HP%20Time()%3B%0AShow(%20(stop%20-%20start)%20%2F%201e6%20)%3B%2F%2F9.3s%0A%0A%0Astart%20%3D%20HP%20Time()%3B%0AFor(%20t%20%3D%201%2C%20t%20%26lt%3B%201e6%2C%20t%20%2B%3D%201%2C%0A%20Matrix(%20%7Bv1%5B2%5D%20*%20v2%5B3%5D%20-%20v1%5B3%5D%20*%20v2%5B2%5D%2C%20v1%5B3%5D%20*%20v2%5B1%5D%20-%20v1%5B1%5D%20*%20v2%5B3%5D%2C%20v1%5B1%5D%20*%20v2%5B2%5D%20-%20v1%5B2%5D%20*%20v2%5B1%5D%7D%20)%0A)%3B%0Astop%20%3D%20HP%20Time()%3B%0AShow(%20(stop%20-%20start)%20%2F%201e6%20)%3B%2F%2F3.2s%0A%0A%0AFor(%20q%20%3D%201%2C%20q%20%26lt%3B%2010000%2C%20q%20%2B%3D%201%2C%0A%20v1%20%3D%20J(%203%2C%201%2C%20Random%20Uniform(%20-1%2C%201%20)%20)%3B%0A%20v2%20%3D%20J(%203%2C%201%2C%20Random%20Uniform(%20-1%2C%201%20)%20)%3B%0A%20If(%0A%20%20All(%0A%20%20%20Round(%20Matrix(%20%7Bv1%5B2%5D%20*%20v2%5B3%5D%20-%20v1%5B3%5D%20*%20v2%5B2%5D%2C%20v1%5B3%5D%20*%20v2%5B1%5D%20-%20v1%5B1%5D%20*%20v2%5B3%5D%2C%20v1%5B1%5D%20*%20v2%5B2%5D%20-%20v1%5B2%5D%20*%20v2%5B1%5D%7D%20)%2C%2010%20)%20%2F%2F%0A%20%20%20%3D%3D%20%2F%2F%0A%20%20%20(i%20%3D%201%3B%20j%20%3D%20-1%20%3B%20Round(%20J(%203%2C%201%2C%20(j%20*%3D%20-1)%20*%20Det(%20(v1%20%7C%7C%20v2)%5BRemove(%20%5B1%2C%202%2C%203%5D%2C%20i%2B%2B%20)%2C%200%5D%20)%20)%2C%2010%20)%20%3B%20)%20%2F%2F%0A%20%20)%20%3D%3D%200%2F%2F%0A%20%2C%20%2F%2F%0A%20%20Throw(%20Char(%20q%20)%20)%0A%20)%3B%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3ECurieusement%2C%20les%20arrondis%20%C3%A0%2011%20places%20ne%20parviennent%20parfois%20pas%20%C3%A0%20correspondre%20aux%20r%C3%A9sultats.%20Probablement%20des%20vecteurs%20presque%20colin%C3%A9aires.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FDIV%3E%3CNOSCRIPT%3E%3CDIV%20class%3D%22lia-spoiler-noscript-content%22%3Ev1%20%3D%20%5B0%2C%200%2C%201%5D%26nbsp%3B%3B%20v2%20%3D%20%5B0%2C%201%2C%200%5D%26nbsp%3B%3B%20d%C3%A9but%20%3D%20HP%20Time()%3B%20Pour(%20t%20%3D%201%2C%20t%20%26lt%3B%201e6%2C%20t%20%2B%3D%201%2C%20i%20%3D%201%3B%20j%20%3D%20-1%3B%20J(%203%2C%201%2C%20(j%20*%3D%20-1)%20*%20Det(%20(v1%20%7C%7C%20v2)%5BSupprimer(%20%5B%201%2C%202%2C%203%5D%2C%20i%2B%2B%20)%2C%200%5D%20)%20)%3B%20)%3B%20arr%C3%AAter%20%3D%20HP%20Temps%20()%3B%20Show(%20(stop%20-%20start)%20%2F%201e6%20)%3B%2F%2F9.3s%20start%20%3D%20HP%20Time()%3B%20Pour(%20t%20%3D%201%2C%20t%20%26lt%3B%201e6%2C%20t%20%2B%3D%201%2C%20Matrice(%20%7Bv1%5B2%5D%20*%20v2%5B3%5D%20-%20v1%5B3%5D%20*%20v2%5B2%5D%2C%20v1%5B3%5D%20*%20v2%5B1%5D%20-%20v1%5B%201%5D%20*%20v2%5B3%5D%2C%20v1%5B1%5D%20*%20v2%5B2%5D%20-%20v1%5B2%5D%20*%20v2%5B1%5D%7D%20)%20)%3B%20arr%C3%AAter%20%3D%20HP%20Temps%20()%3B%20Show(%20(stop%20-%20start)%20%2F%201e6%20)%3B%2F%2F3.2s%20For(%20q%20%3D%201%2C%20q%20%26lt%3B%2010000%2C%20q%20%2B%3D%201%2C%20v1%20%3D%20J(%203%2C%201%2C%20Random%20Uniform(%20-1%2C%201%20)%20)%3B%20v2%20%3D%20J(%203%2C%201%2C%20Random%20Uniform(%20-1%2C%201%20)%20)%3B%20If(%20All(%20Round(%20Matrix(%20%7Bv1%5B2%5D%20*%20v2%5B3%5D%20-%20v1%5B3%5D%20*%20v2%5B2%5D%2C%20v1%5B3%5D%20*%20v2%5B1%5D%20-%20v1%5B1%5D%20*%20v2%5B3%5D%2C%20v1%5B1%5D%20*%20v2%5B2%5D%20-%20v1%5B2%5D%20*%20v2%5B1%5D%7D%20)%2C%2010%20)%20%2F%2F%20%3D%3D%20%2F%2F%20(i%20%3D%201%3B%20j%20%3D%20-1%20%3B%20Rond(%20J(%203%2C%201%2C%20(j%20*%3D%20-1)%20*%20Det(%20(v1%20%7C%7C%20v2)%5BSupprimer(%20%5B1%2C%202%2C%203%5D%2C%20i%2B%2B%20)%2C%200%5D%20)%20)%2C%2010%20)%20%3B%20)%20%2F%2F%20)%20%3D%3D%200%2F%2F%20%2C%20%2F%2F%20Throw(%20Char(%20q%20)%20)%20)%3B%20)%3B%20Curieusement%2C%20les%20arrondis%20%C3%A0%2011%20places%20ne%20parviennent%20parfois%20pas%20%C3%A0%20correspondre%20aux%20r%C3%A9sultats.%20Probablement%20des%20vecteurs%20presque%20colin%C3%A9aires.%3C%2FDIV%3E%3C%2FNOSCRIPT%3E%3C%2FNOSCRIPT%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-611656%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%20%3A%20Comment%20calculer%20le%20produit%20crois%C3%A9%20vectoriel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-611656%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EEh%20bien%2C%20le%20zombie%20ressuscit%C3%A9%20m'a%20attrap%C3%A9.%20Voici%20une%20fa%C3%A7on%20de%20le%20faire%20via%20les%20d%C3%A9terminants%20comme%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F982%22%20target%3D%22_blank%22%3E%20%40Craige_Hales%3C%2FA%3E%20mentionn%C3%A9.%20C'est%20court%2C%20mais%20je%20ne%20sais%20pas...%20ce%20n'est%20pas%20tr%C3%A8s%20simple.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EcrossP%20%3D%20Function(%20%7Bx%2C%20y%2C%20i%20%3D%201%7D%2C%0A%20Return(%20J(%203%2C%201%2C%20Det(%20(x%20%7C%7C%20y)%5BRemove(%20%5B1%2C%202%2C%203%5D%2C%20i%2B%2B%20)%2C%200%5D%20)%20)%20)%0A)%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Ec'est-%C3%A0-dire%20en%20utilisant%20les%20donn%C3%A9es%20fournies%20%C3%A0%20l'origine%26nbsp%3B%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22brady_brady_0-1678770863902.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22brady_brady_0-1678770863902.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22brady_brady_0-1678770863902.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F50994iC68731CC95838C56%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22brady_brady_0-1678770863902.png%22%20alt%3D%22brady_brady_0-1678770863902.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-610312%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%20%3A%20Comment%20calculer%20le%20produit%20crois%C3%A9%20vectoriel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-610312%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ED%C3%A9sol%C3%A9%20d'avoir%20relanc%C3%A9%20ce%20fil%20de%20discussion%20zombie%2C%20mais%20il%20y%20a%20une%20erreur%20de%20signe%20dans%20le%20deuxi%C3%A8me%20%C3%A9l%C3%A9ment%20ici.je%20crois%20que%20%C3%A7a%20devrait%20%C3%AAtre%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EMatrix(%0A%20%20%7Bv1%5B2%5D%20*%20v2%5B3%5D%20-%20v1%5B3%5D%20*%20v2%5B2%5D%2C%20v1%5B3%5D%20*%20v2%5B1%5D%20-%20v1%5B1%5D%20*%20v2%5B3%5D%2C%20v1%5B1%5D%20*%20v2%5B2%5D%20-%20v1%5B2%5D%20*%20v2%5B1%5D%7D%3CBR%20%2F%3E)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EJe%20veux%20juste%20laisser%20ceci%20ici%20pour%20tous%20ceux%20qui%20viendront%20pour%20un%20copier-coller%20rapide.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-236315%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%20%3A%20Comment%20calculer%20le%20produit%20crois%C3%A9%20vectoriel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-236315%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EMerci%20Cwillden%2C%20c'est%20essentiellement%20ce%20que%20j'ai%20mis%20en%20%C5%93uvre.%20Cela%20fonctionne%20pour%20moi%20puisque%20je%20ne%20m'int%C3%A9resse%20qu'aux%20vecteurs%203D%2C%20mais%20je%20suis%20surpris%20que%20ce%20ne%20soit%20pas%20une%20fonction%20int%C3%A9gr%C3%A9e.%20Je%20vais%20laisser%20cela%20ouvert%20un%20moment%20pour%20voir%20si%20quelqu'un%20d'autre%20conna%C3%AEt%20une%20telle%20m%C3%A9thode.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-236298%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%20%3A%20Comment%20calculer%20le%20produit%20crois%C3%A9%20vectoriel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-236298%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EJ'esp%C3%A8re%20que%20quelqu'un%20trouvera%20une%20fa%C3%A7on%20intelligente%20de%20proc%C3%A9der.%20La%20fonction%20det()%20est%20%C3%A9troitement%20li%C3%A9e%2C%20mais%20je%20ne%20comprends%20pas%20comment%20utiliser%20det(3x3%20Matrix)%20pour%20r%C3%A9cup%C3%A9rer%20plus%20qu'une%20valeur%20scalaire.%20Je%20pense%20que%20vous%20pourriez%20utiliser%20det(2x2%20sub-matrix)%20trois%20fois%2C%20mais%20je%20pense%20que%20la%20solution%20simple%3CA%20href%3D%22https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FCross_product%23Mnemonic%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3E%20xyzzy%3C%2FA%3E%20L%E2%80%99approche%20est%20plus%20simple%20et%20tout%20aussi%20rapide.%3C%2FP%3E%3CP%3EJe%20l'utilise%20pour%20les%20normales%20de%20surface%20dans%20les%20sc%C3%A8nes%203D%2C%20il%20y%20a%20du%20JSL%20dans%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2FUncharted%2FCustom-Visualization%2Fba-p%2F191559%22%20target%3D%22_blank%22%3E%20https%3A%2F%2Fcommunity.jmp.com%2Ft5%2FUncharted%2FCustom-Visualization%2Fba-p%2F191559%3C%2FA%3E%20.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-236294%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%20%3A%20Comment%20calculer%20le%20produit%20crois%C3%A9%20vectoriel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-236294%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ESi%20vous%20ne%20traitez%20que%20des%20vecteurs%203x1%20(ou%201x3)%2C%20alors%20je%20pense%20que%20l'efficacit%C3%A9%20ou%20l'%C3%A9l%C3%A9gance%20du%20calcul%20n'est%20pas%20trop%20importante.Est-ce%20que%20cela%20serait%20suffisant%20%3F%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Ecross_prod%20%3D%20function(%7Bv1%2C%20v2%7D%2C%0A%20matrix(%7Bv1%5B2%5D*v2%5B3%5D%20-%20v1%5B3%5D*v2%5B2%5D%2C%20v1%5B1%5D*v2%5B3%5D%20-%20v1%5B3%5D*v2%5B1%5D%2C%20v1%5B1%5D*v2%5B2%5D%20-%20v1%5B2%5D*v2%5B1%5D%7D)%3B%0A)%3B%0A%0Across_prod(v1%2C%20v2)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
CaseyL
Level II

How to calculate Vector Cross Product

From the documentation it looks like the * operator will perform a cross product and ;* will perform a dot product. I want to use a cross product to determine the vector normal to a pair of known vectors like this:

 

p1 = [1, 2, 4];
p2 = [2, 1, 4];
p3 = [2, 2, 4];

v1 = p3 - p1;
v2 = p2 - p1;

xProd = v1*v2;

 3 points define a plane, two vectors taken from those points do the same, the cross-product should give the normal vector of that plane. The problem seems to be that the dimensions of the two matrices being multiplied (v1 and v2) do not agree -- nRows(v1) should equal nCols(v2). I can implement this manually with a simplified formula for vector cross products but does anyone know how to format this differently to work with matrix multiplication?

7 REPLIES 7
cwillden
Super User (Alumni)

Re: How to calculate Vector Cross Product

If you're only ever dealing 3x1 (or 1x3) vectors, then I would think computational efficiency or elegance is not too important.  Would this be sufficient?

cross_prod = function({v1, v2},
	matrix({v1[2]*v2[3] - v1[3]*v2[2], v1[1]*v2[3] - v1[3]*v2[1], v1[1]*v2[2] - v1[2]*v2[1]});
);

cross_prod(v1, v2);
-- Cameron Willden
Craige_Hales
Super User

Re: How to calculate Vector Cross Product

I hope someone comes up with a clever way to do this. The det() function is closely related, but I don't understand how to use det(3x3 matrix) to get back more than a scalar value. I think you could use det(2x2 sub-matrix) three times, but I think the straight-forward xyzzy approach is simpler and just as fast.

I use it for the surface normals in 3D scenes, there is some JSL in https://community.jmp.com/t5/Uncharted/Custom-Visualization/ba-p/191559 .

Craige
CaseyL
Level II

Re: How to calculate Vector Cross Product

Thanks cwillden, this is essentially what  I have implemented. It does work for me since I am only concerned with 3D vectors, but I am supprised this isn't a built in function. I'm going to leave this open for a bit to see if anyone else knows of such a way. 

klk
klk
Level III

Re: How to calculate Vector Cross Product

Sorry for reviving this zombie thread, but there is a sign error in the second element here.  I believe it should be

Matrix(
		{v1[2] * v2[3] - v1[3] * v2[2], v1[3] * v2[1] - v1[1] * v2[3], v1[1] * v2[2] - v1[2] * v2[1]}
)

Just want to leave this here for anyone else who comes along for a quick copy-paste.

Re: How to calculate Vector Cross Product

Well, the revived zombie caught me. Here is a way to do it via determinants as @Craige_Hales mentioned. It is short, but I don't know... it isn't very simple.

 

crossP = Function( {x, y, i = 1},
	Return( J( 3, 1, Det( (x || y)[Remove( [1, 2, 3], i++ ), 0] ) ) )
);

 

i.e., using the originally-supplied data:

brady_brady_0-1678770863902.png

 

Craige_Hales
Super User

Re: How to calculate Vector Cross Product

@brady_brady  Cool! It needs a tweak if you are going to use it:

	i = 1;
	j = -1;
	J( 3, 1, (j *= -1) * Det( (v1 || v2)[Remove( [1, 2, 3], i++ ), 0] ) );

 https://mathinsight.org/cross_product_formula shows how the middle element needs to be negative.  Above, j will alternate sign (1, -1, 1), and i increases (1, 2, 3). The J(...) function has an implicit loop that evaluates the 3rd argument for each element.

 

The straight forward corrected formula from @klk  is about 3 times faster and about N times easier to understand.

 

Test code.

View more...

v1 = [0, 0, 1];
v2 = [0, 1, 0];

start = HP Time();
For( t = 1, t < 1e6, t += 1,
	i = 1;
	j = -1;
	J( 3, 1, (j *= -1) * Det( (v1 || v2)[Remove( [1, 2, 3], i++ ), 0] ) );
);
stop = HP Time();
Show( (stop - start) / 1e6 );//9.3s


start = HP Time();
For( t = 1, t < 1e6, t += 1,
	Matrix( {v1[2] * v2[3] - v1[3] * v2[2], v1[3] * v2[1] - v1[1] * v2[3], v1[1] * v2[2] - v1[2] * v2[1]} )
);
stop = HP Time();
Show( (stop - start) / 1e6 );//3.2s


For( q = 1, q < 10000, q += 1,
	v1 = J( 3, 1, Random Uniform( -1, 1 ) );
	v2 = J( 3, 1, Random Uniform( -1, 1 ) );
	If(
		All(
			Round( Matrix( {v1[2] * v2[3] - v1[3] * v2[2], v1[3] * v2[1] - v1[1] * v2[3], v1[1] * v2[2] - v1[2] * v2[1]} ), 10 ) //
			== //
			(i = 1; j = -1 ; Round( J( 3, 1, (j *= -1) * Det( (v1 || v2)[Remove( [1, 2, 3], i++ ), 0] ) ), 10 ) ; ) //
		) == 0//
	, //
		Throw( Char( q ) )
	);
);
Curiously, rounding to 11 places occasionally fails to match results. Probably nearly collinear vectors.

Craige

Re: How to calculate Vector Cross Product

The inferior performance doesn't surprise... thanks for inserting the sign adjustment. I omitted the "sign checkerboard" inadvertently.

 

IMO this is one of those instances where "just because you can, doesn't mean you should" applies... {cool, fun, short} doesn't outweigh {understandable, maintainable, speedy}.