How to calculate coordinate X meters away from a point but towards another in C#












0















Let's say I have 2 coordinates that are ~222.33 meters away from each other :



A: 49.25818, -123.20626
B: 49.25813, -123.2032


Those 2 points makes a segment.



How can I calculate the coordinate of point Z that is X meters away from either A or B but towards the other point?



I already know the distance between my 2 points using System.Device.Location library.



GeoCoordinate A = new GeoCoordinate(49.25818, -123.20626);
GeoCoordinate B = new GeoCoordinate(49.25813, -123.2032);
var distanceInMeters = A.GetDistanceTo(B);
// distanceInMeters = 222.33039783713738


I'm looking for something like this:



GeoCoordinate GetPointTowards(GeoCoordinate fromPoint, GeoCoordinate towardPoint, double distanceInMeter) {
[???]
}


I think I may need the bearing or something to be able to get the new point location.



Most examples I've found are for iOS, Android or GMaps with specific libraries..










share|improve this question

























  • maybe this nuget library can help? numerics.mathdotnet.com

    – JohnB
    Nov 21 '18 at 1:28













  • Could you provide another two coordinates with the correct meters please.. Need to test my logic before posting a Method that you can pass into.

    – Levon Ravel
    Nov 21 '18 at 1:48













  • @LevonRavel : {49.25835, -123.21894}, {49.25837, -123.21989}. They are 69.038124262531255 meters away.

    – Remi
    Nov 21 '18 at 1:52











  • okay I can post the equation

    – Levon Ravel
    Nov 21 '18 at 1:53






  • 1





    stackoverflow.com/questions/3225803/… Found this answer hope it helps. It is in kilometers but I think the conversion to meters should be easy enough.

    – Levon Ravel
    Nov 21 '18 at 2:26


















0















Let's say I have 2 coordinates that are ~222.33 meters away from each other :



A: 49.25818, -123.20626
B: 49.25813, -123.2032


Those 2 points makes a segment.



How can I calculate the coordinate of point Z that is X meters away from either A or B but towards the other point?



I already know the distance between my 2 points using System.Device.Location library.



GeoCoordinate A = new GeoCoordinate(49.25818, -123.20626);
GeoCoordinate B = new GeoCoordinate(49.25813, -123.2032);
var distanceInMeters = A.GetDistanceTo(B);
// distanceInMeters = 222.33039783713738


I'm looking for something like this:



GeoCoordinate GetPointTowards(GeoCoordinate fromPoint, GeoCoordinate towardPoint, double distanceInMeter) {
[???]
}


I think I may need the bearing or something to be able to get the new point location.



Most examples I've found are for iOS, Android or GMaps with specific libraries..










share|improve this question

























  • maybe this nuget library can help? numerics.mathdotnet.com

    – JohnB
    Nov 21 '18 at 1:28













  • Could you provide another two coordinates with the correct meters please.. Need to test my logic before posting a Method that you can pass into.

    – Levon Ravel
    Nov 21 '18 at 1:48













  • @LevonRavel : {49.25835, -123.21894}, {49.25837, -123.21989}. They are 69.038124262531255 meters away.

    – Remi
    Nov 21 '18 at 1:52











  • okay I can post the equation

    – Levon Ravel
    Nov 21 '18 at 1:53






  • 1





    stackoverflow.com/questions/3225803/… Found this answer hope it helps. It is in kilometers but I think the conversion to meters should be easy enough.

    – Levon Ravel
    Nov 21 '18 at 2:26
















0












0








0








Let's say I have 2 coordinates that are ~222.33 meters away from each other :



A: 49.25818, -123.20626
B: 49.25813, -123.2032


Those 2 points makes a segment.



How can I calculate the coordinate of point Z that is X meters away from either A or B but towards the other point?



I already know the distance between my 2 points using System.Device.Location library.



GeoCoordinate A = new GeoCoordinate(49.25818, -123.20626);
GeoCoordinate B = new GeoCoordinate(49.25813, -123.2032);
var distanceInMeters = A.GetDistanceTo(B);
// distanceInMeters = 222.33039783713738


I'm looking for something like this:



GeoCoordinate GetPointTowards(GeoCoordinate fromPoint, GeoCoordinate towardPoint, double distanceInMeter) {
[???]
}


I think I may need the bearing or something to be able to get the new point location.



Most examples I've found are for iOS, Android or GMaps with specific libraries..










share|improve this question
















Let's say I have 2 coordinates that are ~222.33 meters away from each other :



A: 49.25818, -123.20626
B: 49.25813, -123.2032


Those 2 points makes a segment.



How can I calculate the coordinate of point Z that is X meters away from either A or B but towards the other point?



I already know the distance between my 2 points using System.Device.Location library.



GeoCoordinate A = new GeoCoordinate(49.25818, -123.20626);
GeoCoordinate B = new GeoCoordinate(49.25813, -123.2032);
var distanceInMeters = A.GetDistanceTo(B);
// distanceInMeters = 222.33039783713738


I'm looking for something like this:



GeoCoordinate GetPointTowards(GeoCoordinate fromPoint, GeoCoordinate towardPoint, double distanceInMeter) {
[???]
}


I think I may need the bearing or something to be able to get the new point location.



Most examples I've found are for iOS, Android or GMaps with specific libraries..







c# geospatial distance






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 2:15







Remi

















asked Nov 21 '18 at 1:23









RemiRemi

15212




15212













  • maybe this nuget library can help? numerics.mathdotnet.com

    – JohnB
    Nov 21 '18 at 1:28













  • Could you provide another two coordinates with the correct meters please.. Need to test my logic before posting a Method that you can pass into.

    – Levon Ravel
    Nov 21 '18 at 1:48













  • @LevonRavel : {49.25835, -123.21894}, {49.25837, -123.21989}. They are 69.038124262531255 meters away.

    – Remi
    Nov 21 '18 at 1:52











  • okay I can post the equation

    – Levon Ravel
    Nov 21 '18 at 1:53






  • 1





    stackoverflow.com/questions/3225803/… Found this answer hope it helps. It is in kilometers but I think the conversion to meters should be easy enough.

    – Levon Ravel
    Nov 21 '18 at 2:26





















  • maybe this nuget library can help? numerics.mathdotnet.com

    – JohnB
    Nov 21 '18 at 1:28













  • Could you provide another two coordinates with the correct meters please.. Need to test my logic before posting a Method that you can pass into.

    – Levon Ravel
    Nov 21 '18 at 1:48













  • @LevonRavel : {49.25835, -123.21894}, {49.25837, -123.21989}. They are 69.038124262531255 meters away.

    – Remi
    Nov 21 '18 at 1:52











  • okay I can post the equation

    – Levon Ravel
    Nov 21 '18 at 1:53






  • 1





    stackoverflow.com/questions/3225803/… Found this answer hope it helps. It is in kilometers but I think the conversion to meters should be easy enough.

    – Levon Ravel
    Nov 21 '18 at 2:26



















maybe this nuget library can help? numerics.mathdotnet.com

– JohnB
Nov 21 '18 at 1:28







maybe this nuget library can help? numerics.mathdotnet.com

– JohnB
Nov 21 '18 at 1:28















Could you provide another two coordinates with the correct meters please.. Need to test my logic before posting a Method that you can pass into.

– Levon Ravel
Nov 21 '18 at 1:48







Could you provide another two coordinates with the correct meters please.. Need to test my logic before posting a Method that you can pass into.

– Levon Ravel
Nov 21 '18 at 1:48















@LevonRavel : {49.25835, -123.21894}, {49.25837, -123.21989}. They are 69.038124262531255 meters away.

– Remi
Nov 21 '18 at 1:52





@LevonRavel : {49.25835, -123.21894}, {49.25837, -123.21989}. They are 69.038124262531255 meters away.

– Remi
Nov 21 '18 at 1:52













okay I can post the equation

– Levon Ravel
Nov 21 '18 at 1:53





okay I can post the equation

– Levon Ravel
Nov 21 '18 at 1:53




1




1





stackoverflow.com/questions/3225803/… Found this answer hope it helps. It is in kilometers but I think the conversion to meters should be easy enough.

– Levon Ravel
Nov 21 '18 at 2:26







stackoverflow.com/questions/3225803/… Found this answer hope it helps. It is in kilometers but I think the conversion to meters should be easy enough.

– Levon Ravel
Nov 21 '18 at 2:26














1 Answer
1






active

oldest

votes


















1














Here's an outline of how I would do it. With this approach, there is no need to explicitly deal with the difference in units between coordinates and distances because taking the ratio of target to total distance eliminates the unit.



totalDistance = distance in meters between point A and point B.
targetDistance = distance in meters to travel from point A to point B

ratio = targetDistance / totalDistance

diffX = B.X - A.X
diffY = B.Y - A.Y

targetX = A.X + (ratio * diffX)
targetY = A.Y + (ratio * diffY)


But this wouldn't handle the edge cases like being at 179 degrees longitude and adding 3 degrees which would put you at -178 longitude.






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    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
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404008%2fhow-to-calculate-coordinate-x-meters-away-from-a-point-but-towards-another-in-c%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









    1














    Here's an outline of how I would do it. With this approach, there is no need to explicitly deal with the difference in units between coordinates and distances because taking the ratio of target to total distance eliminates the unit.



    totalDistance = distance in meters between point A and point B.
    targetDistance = distance in meters to travel from point A to point B

    ratio = targetDistance / totalDistance

    diffX = B.X - A.X
    diffY = B.Y - A.Y

    targetX = A.X + (ratio * diffX)
    targetY = A.Y + (ratio * diffY)


    But this wouldn't handle the edge cases like being at 179 degrees longitude and adding 3 degrees which would put you at -178 longitude.






    share|improve this answer






























      1














      Here's an outline of how I would do it. With this approach, there is no need to explicitly deal with the difference in units between coordinates and distances because taking the ratio of target to total distance eliminates the unit.



      totalDistance = distance in meters between point A and point B.
      targetDistance = distance in meters to travel from point A to point B

      ratio = targetDistance / totalDistance

      diffX = B.X - A.X
      diffY = B.Y - A.Y

      targetX = A.X + (ratio * diffX)
      targetY = A.Y + (ratio * diffY)


      But this wouldn't handle the edge cases like being at 179 degrees longitude and adding 3 degrees which would put you at -178 longitude.






      share|improve this answer




























        1












        1








        1







        Here's an outline of how I would do it. With this approach, there is no need to explicitly deal with the difference in units between coordinates and distances because taking the ratio of target to total distance eliminates the unit.



        totalDistance = distance in meters between point A and point B.
        targetDistance = distance in meters to travel from point A to point B

        ratio = targetDistance / totalDistance

        diffX = B.X - A.X
        diffY = B.Y - A.Y

        targetX = A.X + (ratio * diffX)
        targetY = A.Y + (ratio * diffY)


        But this wouldn't handle the edge cases like being at 179 degrees longitude and adding 3 degrees which would put you at -178 longitude.






        share|improve this answer















        Here's an outline of how I would do it. With this approach, there is no need to explicitly deal with the difference in units between coordinates and distances because taking the ratio of target to total distance eliminates the unit.



        totalDistance = distance in meters between point A and point B.
        targetDistance = distance in meters to travel from point A to point B

        ratio = targetDistance / totalDistance

        diffX = B.X - A.X
        diffY = B.Y - A.Y

        targetX = A.X + (ratio * diffX)
        targetY = A.Y + (ratio * diffY)


        But this wouldn't handle the edge cases like being at 179 degrees longitude and adding 3 degrees which would put you at -178 longitude.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 21 '18 at 2:55

























        answered Nov 21 '18 at 2:42









        LynnLynn

        212




        212






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • 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.


            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%2fstackoverflow.com%2fquestions%2f53404008%2fhow-to-calculate-coordinate-x-meters-away-from-a-point-but-towards-another-in-c%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

            If I really need a card on my start hand, how many mulligans make sense? [duplicate]

            Alcedinidae

            Can an atomic nucleus contain both particles and antiparticles? [duplicate]