Results 1 to 4 of 4

Thread: [RESOLVED] The length of a line

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Resolved [RESOLVED] The length of a line

    I am sure there's a simple way to do this, but I want to calculate exactly how long a line is based on the x/y co-ordinates of both points. For instance, if a line was from 1,1 to 1,10 it would obviously be 10, but I need to know how to calculate it if it was 1,1 to 3,10 or 1,1 to 7,9.

    I'll be working with larger numbers than this, probably in their thousands...it'll calculate the distance between two points on a VB form...but that shouldn't make much difference :-)

    Has anyone got a function for returning the result distance between two x,y co-ordinates?
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: The length of a line

    You would use Pythagorean theorem, eg:
    Code:
    Length = Sqrt((x2-x1)^2 + (y2-y1)^2)

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: The length of a line

    Many thanks...I had a feeling it was pythagorean but had no idea how to put the idea into practice...I'm not much of a mathematic :-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [RESOLVED] The length of a line

    By the way, there are ways to make quick and dirty approximations of that length that can be considerably faster in C/C++, but when I tried the same approximations in VB.NET, I got no performance boost, so not only is the Pythagorean Theorem the way to get the precise value, it is also, at least in VB.NET, the fastest way to get a good value, so you might as well just use it.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width