Vector relative to another vector












2












$begingroup$


I have a direction vector (x/y/z) that I need to express relative to the normal vector of a surface, such that the direction vector is "local" to the normal vector.



I've read that I need to create a basis using the normal vector (up/right/forward) and use the dot product to find each new vector element.



1.) Is this the most efficient way to calculate the localized direction vector?



2.) How do I then transform the direction vector back into its original basis (after it is altered in local space)?










share|cite|improve this question









$endgroup$












  • $begingroup$
    The approach you describes seems like generally the right one, but it would be easier to give a good answer if you gave some more specifics about your application (and perhaps establish some notation).
    $endgroup$
    – arghbleargh
    Aug 19 '16 at 20:34
















2












$begingroup$


I have a direction vector (x/y/z) that I need to express relative to the normal vector of a surface, such that the direction vector is "local" to the normal vector.



I've read that I need to create a basis using the normal vector (up/right/forward) and use the dot product to find each new vector element.



1.) Is this the most efficient way to calculate the localized direction vector?



2.) How do I then transform the direction vector back into its original basis (after it is altered in local space)?










share|cite|improve this question









$endgroup$












  • $begingroup$
    The approach you describes seems like generally the right one, but it would be easier to give a good answer if you gave some more specifics about your application (and perhaps establish some notation).
    $endgroup$
    – arghbleargh
    Aug 19 '16 at 20:34














2












2








2





$begingroup$


I have a direction vector (x/y/z) that I need to express relative to the normal vector of a surface, such that the direction vector is "local" to the normal vector.



I've read that I need to create a basis using the normal vector (up/right/forward) and use the dot product to find each new vector element.



1.) Is this the most efficient way to calculate the localized direction vector?



2.) How do I then transform the direction vector back into its original basis (after it is altered in local space)?










share|cite|improve this question









$endgroup$




I have a direction vector (x/y/z) that I need to express relative to the normal vector of a surface, such that the direction vector is "local" to the normal vector.



I've read that I need to create a basis using the normal vector (up/right/forward) and use the dot product to find each new vector element.



1.) Is this the most efficient way to calculate the localized direction vector?



2.) How do I then transform the direction vector back into its original basis (after it is altered in local space)?







linear-algebra geometry






share|cite|improve this question













share|cite|improve this question











share|cite|improve this question




share|cite|improve this question










asked Aug 19 '16 at 16:55









anonymooseanonymoose

112




112












  • $begingroup$
    The approach you describes seems like generally the right one, but it would be easier to give a good answer if you gave some more specifics about your application (and perhaps establish some notation).
    $endgroup$
    – arghbleargh
    Aug 19 '16 at 20:34


















  • $begingroup$
    The approach you describes seems like generally the right one, but it would be easier to give a good answer if you gave some more specifics about your application (and perhaps establish some notation).
    $endgroup$
    – arghbleargh
    Aug 19 '16 at 20:34
















$begingroup$
The approach you describes seems like generally the right one, but it would be easier to give a good answer if you gave some more specifics about your application (and perhaps establish some notation).
$endgroup$
– arghbleargh
Aug 19 '16 at 20:34




$begingroup$
The approach you describes seems like generally the right one, but it would be easier to give a good answer if you gave some more specifics about your application (and perhaps establish some notation).
$endgroup$
– arghbleargh
Aug 19 '16 at 20:34










1 Answer
1






active

oldest

votes


















0












$begingroup$


Is this the most efficient way to calculate the localized direction vector?




It depends on how you define "efficient". In general, this is the simplest way, and definitely sufficiently fast in a computer program, even in a game. Whether it is the fastest, depends on the hardware, memory structures available, and so on. This is definitely the way I'd generally do it, for sure.



If you are asking about the nitty gritty details, I'd say you could make the surface normal vector unit vector (by always scaling it to unit length, i.e. 1), and also store the two other basis vector with each surface. That is, rather than calculate them again and again. I'd definitely do this myself.





Let's say you have $hat{n}$ as the normal vector, perpendicular to the surface, with $hat{u}$ and $hat{v}$ parallel to the surface; with all three unit vectors (length $1$), and all three vectors perpendicular to each other. Furthermore, the point on the surface is $vec{p}$, and you wish to find the vector $vec{r}$ from point $vec{p}$ to $vec{q}$, but relative to the point $vec{p}$ on the surface. This is simple:
$$vec{r} = ( x, y, z ) = left ( hat{u} cdot left ( vec{q} - vec{p} right ), ;
hat{v} cdot left ( vec{q} - vec{p} right ), ;
hat{n} cdot left ( vec{q} - vec{p} right ) right )$$



Here, $x$ and $y$ are along the surface, with $z$ increasing above the surface if your normal points outwards; if your normals point inwards, then $z$ decreases as you go further above the surface. $z = 0$ is on the surface in any case.






How do I then transform the direction vector back into its original basis (after it is altered in local space)?




Converting $vec{r}$ back to the global coordinate system is just as easy,
$$vec{q} = vec{p} + x hat{u} + y hat{v} + z hat{n}$$





As to computational efficiency, each conversion requires nine multiplications and nine additions or subtractions, if I calculated right. I would consider that quite efficient; I don't really know how you could reduce that in any way that would matter in practice.






share|cite|improve this answer









$endgroup$













    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "69"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    noCode: true, onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f1897310%2fvector-relative-to-another-vector%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0












    $begingroup$


    Is this the most efficient way to calculate the localized direction vector?




    It depends on how you define "efficient". In general, this is the simplest way, and definitely sufficiently fast in a computer program, even in a game. Whether it is the fastest, depends on the hardware, memory structures available, and so on. This is definitely the way I'd generally do it, for sure.



    If you are asking about the nitty gritty details, I'd say you could make the surface normal vector unit vector (by always scaling it to unit length, i.e. 1), and also store the two other basis vector with each surface. That is, rather than calculate them again and again. I'd definitely do this myself.





    Let's say you have $hat{n}$ as the normal vector, perpendicular to the surface, with $hat{u}$ and $hat{v}$ parallel to the surface; with all three unit vectors (length $1$), and all three vectors perpendicular to each other. Furthermore, the point on the surface is $vec{p}$, and you wish to find the vector $vec{r}$ from point $vec{p}$ to $vec{q}$, but relative to the point $vec{p}$ on the surface. This is simple:
    $$vec{r} = ( x, y, z ) = left ( hat{u} cdot left ( vec{q} - vec{p} right ), ;
    hat{v} cdot left ( vec{q} - vec{p} right ), ;
    hat{n} cdot left ( vec{q} - vec{p} right ) right )$$



    Here, $x$ and $y$ are along the surface, with $z$ increasing above the surface if your normal points outwards; if your normals point inwards, then $z$ decreases as you go further above the surface. $z = 0$ is on the surface in any case.






    How do I then transform the direction vector back into its original basis (after it is altered in local space)?




    Converting $vec{r}$ back to the global coordinate system is just as easy,
    $$vec{q} = vec{p} + x hat{u} + y hat{v} + z hat{n}$$





    As to computational efficiency, each conversion requires nine multiplications and nine additions or subtractions, if I calculated right. I would consider that quite efficient; I don't really know how you could reduce that in any way that would matter in practice.






    share|cite|improve this answer









    $endgroup$


















      0












      $begingroup$


      Is this the most efficient way to calculate the localized direction vector?




      It depends on how you define "efficient". In general, this is the simplest way, and definitely sufficiently fast in a computer program, even in a game. Whether it is the fastest, depends on the hardware, memory structures available, and so on. This is definitely the way I'd generally do it, for sure.



      If you are asking about the nitty gritty details, I'd say you could make the surface normal vector unit vector (by always scaling it to unit length, i.e. 1), and also store the two other basis vector with each surface. That is, rather than calculate them again and again. I'd definitely do this myself.





      Let's say you have $hat{n}$ as the normal vector, perpendicular to the surface, with $hat{u}$ and $hat{v}$ parallel to the surface; with all three unit vectors (length $1$), and all three vectors perpendicular to each other. Furthermore, the point on the surface is $vec{p}$, and you wish to find the vector $vec{r}$ from point $vec{p}$ to $vec{q}$, but relative to the point $vec{p}$ on the surface. This is simple:
      $$vec{r} = ( x, y, z ) = left ( hat{u} cdot left ( vec{q} - vec{p} right ), ;
      hat{v} cdot left ( vec{q} - vec{p} right ), ;
      hat{n} cdot left ( vec{q} - vec{p} right ) right )$$



      Here, $x$ and $y$ are along the surface, with $z$ increasing above the surface if your normal points outwards; if your normals point inwards, then $z$ decreases as you go further above the surface. $z = 0$ is on the surface in any case.






      How do I then transform the direction vector back into its original basis (after it is altered in local space)?




      Converting $vec{r}$ back to the global coordinate system is just as easy,
      $$vec{q} = vec{p} + x hat{u} + y hat{v} + z hat{n}$$





      As to computational efficiency, each conversion requires nine multiplications and nine additions or subtractions, if I calculated right. I would consider that quite efficient; I don't really know how you could reduce that in any way that would matter in practice.






      share|cite|improve this answer









      $endgroup$
















        0












        0








        0





        $begingroup$


        Is this the most efficient way to calculate the localized direction vector?




        It depends on how you define "efficient". In general, this is the simplest way, and definitely sufficiently fast in a computer program, even in a game. Whether it is the fastest, depends on the hardware, memory structures available, and so on. This is definitely the way I'd generally do it, for sure.



        If you are asking about the nitty gritty details, I'd say you could make the surface normal vector unit vector (by always scaling it to unit length, i.e. 1), and also store the two other basis vector with each surface. That is, rather than calculate them again and again. I'd definitely do this myself.





        Let's say you have $hat{n}$ as the normal vector, perpendicular to the surface, with $hat{u}$ and $hat{v}$ parallel to the surface; with all three unit vectors (length $1$), and all three vectors perpendicular to each other. Furthermore, the point on the surface is $vec{p}$, and you wish to find the vector $vec{r}$ from point $vec{p}$ to $vec{q}$, but relative to the point $vec{p}$ on the surface. This is simple:
        $$vec{r} = ( x, y, z ) = left ( hat{u} cdot left ( vec{q} - vec{p} right ), ;
        hat{v} cdot left ( vec{q} - vec{p} right ), ;
        hat{n} cdot left ( vec{q} - vec{p} right ) right )$$



        Here, $x$ and $y$ are along the surface, with $z$ increasing above the surface if your normal points outwards; if your normals point inwards, then $z$ decreases as you go further above the surface. $z = 0$ is on the surface in any case.






        How do I then transform the direction vector back into its original basis (after it is altered in local space)?




        Converting $vec{r}$ back to the global coordinate system is just as easy,
        $$vec{q} = vec{p} + x hat{u} + y hat{v} + z hat{n}$$





        As to computational efficiency, each conversion requires nine multiplications and nine additions or subtractions, if I calculated right. I would consider that quite efficient; I don't really know how you could reduce that in any way that would matter in practice.






        share|cite|improve this answer









        $endgroup$




        Is this the most efficient way to calculate the localized direction vector?




        It depends on how you define "efficient". In general, this is the simplest way, and definitely sufficiently fast in a computer program, even in a game. Whether it is the fastest, depends on the hardware, memory structures available, and so on. This is definitely the way I'd generally do it, for sure.



        If you are asking about the nitty gritty details, I'd say you could make the surface normal vector unit vector (by always scaling it to unit length, i.e. 1), and also store the two other basis vector with each surface. That is, rather than calculate them again and again. I'd definitely do this myself.





        Let's say you have $hat{n}$ as the normal vector, perpendicular to the surface, with $hat{u}$ and $hat{v}$ parallel to the surface; with all three unit vectors (length $1$), and all three vectors perpendicular to each other. Furthermore, the point on the surface is $vec{p}$, and you wish to find the vector $vec{r}$ from point $vec{p}$ to $vec{q}$, but relative to the point $vec{p}$ on the surface. This is simple:
        $$vec{r} = ( x, y, z ) = left ( hat{u} cdot left ( vec{q} - vec{p} right ), ;
        hat{v} cdot left ( vec{q} - vec{p} right ), ;
        hat{n} cdot left ( vec{q} - vec{p} right ) right )$$



        Here, $x$ and $y$ are along the surface, with $z$ increasing above the surface if your normal points outwards; if your normals point inwards, then $z$ decreases as you go further above the surface. $z = 0$ is on the surface in any case.






        How do I then transform the direction vector back into its original basis (after it is altered in local space)?




        Converting $vec{r}$ back to the global coordinate system is just as easy,
        $$vec{q} = vec{p} + x hat{u} + y hat{v} + z hat{n}$$





        As to computational efficiency, each conversion requires nine multiplications and nine additions or subtractions, if I calculated right. I would consider that quite efficient; I don't really know how you could reduce that in any way that would matter in practice.







        share|cite|improve this answer












        share|cite|improve this answer



        share|cite|improve this answer










        answered Aug 19 '16 at 21:28









        Nominal AnimalNominal Animal

        6,9452517




        6,9452517






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Mathematics Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f1897310%2fvector-relative-to-another-vector%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Cabo Verde

            Gyllenstierna