Co-ordinates 
Author Message
 Co-ordinates

If I have 2 sets of co-ordinates on a form, how can I tell the distance from
one to the other in, say, pixels?

Thanks

Tony Sonemann



Wed, 16 Mar 2005 02:59:38 GMT  
 Co-ordinates
Hi Tony,

Let say you have point A = (X1,Y1) and Point B = (X2,Y2).

The distance between the points, AB, will then be:

AB = SQR((X2 - X1) ^ 2 + (Y2 - Y1) ^ 2)

The distance is measured in the same units as are the coordinates. Just make sure that both pair of coordinates are in the same units.

Regards,

Stoil

Quote:

> If I have 2 sets of co-ordinates on a form, how can I tell the distance from
> one to the other in, say, pixels?

> Thanks

> Tony Sonemann



Wed, 16 Mar 2005 03:19:12 GMT  
 Co-ordinates
I'll note that if you only need to know whether a point is closer than
another, you can dispense with the SQR() operation and speed the
calculations up (maybe significantly).  
Quote:

> Hi Tony,

> Let say you have point A = (X1,Y1) and Point B = (X2,Y2).

> The distance between the points, AB, will then be:

> AB = SQR((X2 - X1) ^ 2 + (Y2 - Y1) ^ 2)

> The distance is measured in the same units as are the coordinates. Just make sure that both pair of coordinates are in the same units.

> Regards,

> Stoil


> > If I have 2 sets of co-ordinates on a form, how can I tell the distance from
> > one to the other in, say, pixels?

> > Thanks

> > Tony Sonemann



Wed, 16 Mar 2005 05:30:28 GMT  
 Co-ordinates
Well, if you really want to speed it up, I'd suggest doing away with
that power operation and convert it to a straight multiplication

AB = (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1)

still assuming that we are removing the Sqr operation for comparative
speed.

Rick


Quote:
> I'll note that if you only need to know whether a point is closer than
> another, you can dispense with the SQR() operation and speed the
> calculations up (maybe significantly).


> > Hi Tony,

> > Let say you have point A = (X1,Y1) and Point B = (X2,Y2).

> > The distance between the points, AB, will then be:

> > AB = SQR((X2 - X1) ^ 2 + (Y2 - Y1) ^ 2)

> > The distance is measured in the same units as are the coordinates.

Just make sure that both pair of coordinates are in the same units.
Quote:

> > Regards,

> > Stoil




Quote:
> > > If I have 2 sets of co-ordinates on a form, how can I tell the
distance from
> > > one to the other in, say, pixels?

> > > Thanks

> > > Tony Sonemann



Wed, 16 Mar 2005 08:18:12 GMT  
 Co-ordinates

Quote:

>Date: 9/27/02 5:18 PM Pacific Daylight Time

>Well, if you really want to speed it up, I'd suggest doing away with
>that power operation and convert it to a straight multiplication

>AB = (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1)

>still assuming that we are removing the Sqr operation for comparative
>speed.

>Rick

Is there really a speed difference between (x2-x1)^2   and  (x2-x1)*(x2-x1) in
VB6?

Dan  :-)



Wed, 16 Mar 2005 10:35:25 GMT  
 Co-ordinates

Quote:

> >Date: 9/27/02 5:18 PM Pacific Daylight Time

> >Well, if you really want to speed it up, I'd suggest doing away with
> >that power operation and convert it to a straight multiplication

> >AB = (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1)

> >still assuming that we are removing the Sqr operation for comparative
> >speed.

> >Rick

> Is there really a speed difference between (x2-x1)^2   and
(x2-x1)*(x2-x1) in
> VB6?

Yes, definitely. The multiplication is some 2.5 times faster than
raising to a power in the IDE and 4.5 times faster when compiled (I used
a Long for my test). Actually, multiplication has always been faster
than raising to a power in all version of BASIC and VB.

Rick



Wed, 16 Mar 2005 11:24:11 GMT  
 Co-ordinates
Just wanted to say thanks for all the assistance - this really helps!

Tony


Quote:

> >Date: 9/27/02 5:18 PM Pacific Daylight Time

> >Well, if you really want to speed it up, I'd suggest doing away with
> >that power operation and convert it to a straight multiplication

> >AB = (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1)

> >still assuming that we are removing the Sqr operation for comparative
> >speed.

> >Rick

> Is there really a speed difference between (x2-x1)^2   and
(x2-x1)*(x2-x1) in
> VB6?

> Dan  :-)



Wed, 16 Mar 2005 11:25:54 GMT  
 Co-ordinates
Just wanted to say thanks for all the assistance - this really helps!

Tony


Quote:

> >Date: 9/27/02 5:18 PM Pacific Daylight Time

> >Well, if you really want to speed it up, I'd suggest doing away with
> >that power operation and convert it to a straight multiplication

> >AB = (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1)

> >still assuming that we are removing the Sqr operation for comparative
> >speed.

> >Rick

> Is there really a speed difference between (x2-x1)^2   and
(x2-x1)*(x2-x1) in
> VB6?

> Dan  :-)



Wed, 16 Mar 2005 11:25:54 GMT  
 Co-ordinates
BTW, Dan , yes there is - I just ran a test and there is an 18 second
difference over 10 million iterations.

Tony


Quote:

> >Date: 9/27/02 5:18 PM Pacific Daylight Time

> >Well, if you really want to speed it up, I'd suggest doing away with
> >that power operation and convert it to a straight multiplication

> >AB = (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1)

> >still assuming that we are removing the Sqr operation for comparative
> >speed.

> >Rick

> Is there really a speed difference between (x2-x1)^2   and
(x2-x1)*(x2-x1) in
> VB6?

> Dan  :-)



Wed, 16 Mar 2005 11:57:44 GMT  
 Co-ordinates

Quote:


> >Date: 9/27/02 5:18 PM Pacific Daylight Time

> >Well, if you really want to speed it up, I'd suggest doing away with
> >that power operation and convert it to a straight multiplication

> >AB = (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1)

> >still assuming that we are removing the Sqr operation for comparative
> >speed.

> >Rick

> Is there really a speed difference between (x2-x1)^2   and  (x2-x1)*(x2-x1) in
> VB6?

I wasn't sure about VB6, but there is certainly in VB5 (and I note
another response confirms it's still there in VB6 as well)...amazing
they couldn't do such a simple optimization for integer powers isn't?  

I should have pointed it out as well as the SQR, but I do that so
automatically now I didn't think to mention it explicitly.



Wed, 16 Mar 2005 13:30:35 GMT  
 Co-ordinates

Quote:



>> >Date: 9/27/02 5:18 PM Pacific Daylight Time

>> >Well, if you really want to speed it up, I'd suggest doing away with
>> >that power operation and convert it to a straight multiplication

>> >AB = (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1)

>> >still assuming that we are removing the Sqr operation for comparative
>> >speed.

>> >Rick

>> Is there really a speed difference between (x2-x1)^2   and
>(x2-x1)*(x2-x1) in
>> VB6?

>Yes, definitely. The multiplication is some 2.5 times faster than
>raising to a power in the IDE and 4.5 times faster when compiled (I used
>a Long for my test). Actually, multiplication has always been faster
>than raising to a power in all version of BASIC and VB.

>Rick

Wow!  That's pretty amazing actually.  It sure makes things clear as to what
Microsofts goals are and how it goes about achieving those goals  ( ie.. as
long as we're making money,  forget about quality as it is irrelevant ).

Dan  :-)



Thu, 17 Mar 2005 00:09:58 GMT  
 Co-ordinates

Quote:




> >> >Date: 9/27/02 5:18 PM Pacific Daylight Time
> >> >Message-id:


Quote:

> >> >Well, if you really want to speed it up, I'd suggest doing away
with
> >> >that power operation and convert it to a straight multiplication

> >> >AB = (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1)

> >> >still assuming that we are removing the Sqr operation for
comparative
> >> >speed.

> >> >Rick

> >> Is there really a speed difference between (x2-x1)^2   and
> >(x2-x1)*(x2-x1) in
> >> VB6?

> >Yes, definitely. The multiplication is some 2.5 times faster than
> >raising to a power in the IDE and 4.5 times faster when compiled (I
used
> >a Long for my test). Actually, multiplication has always been faster
> >than raising to a power in all version of BASIC and VB.

> >Rick

> Wow!  That's pretty amazing actually.  It sure makes things clear as
to what
> Microsofts goals are and how it goes about achieving those goals  (
ie.. as
> long as we're making money,  forget about quality as it is

irrelevant ).

That might be a little unfair. You have to remember that the power
operation has to be able to handle more than simply squaring a number.
It does this

     1.23 ^ 4.56

just as easily as this

     1.23 ^ 2

and there is no simple multiplication that can be done for that first
calculation.

Rick



Thu, 17 Mar 2005 00:40:28 GMT  
 Co-ordinates

Quote:







> > >> >Date: 9/27/02 5:18 PM Pacific Daylight Time
> > >> >Message-id:

> > >> >Well, if you really want to speed it up, I'd suggest doing away
> with
> > >> >that power operation and convert it to a straight multiplication

> > >> >AB = (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1)

> > >> >still assuming that we are removing the Sqr operation for
> comparative
> > >> >speed.

> > >> >Rick

> > >> Is there really a speed difference between (x2-x1)^2   and
> > >(x2-x1)*(x2-x1) in
> > >> VB6?

> > >Yes, definitely. The multiplication is some 2.5 times faster than
> > >raising to a power in the IDE and 4.5 times faster when compiled (I
> used
> > >a Long for my test). Actually, multiplication has always been faster
> > >than raising to a power in all version of BASIC and VB.

> > >Rick

> > Wow!  That's pretty amazing actually.  It sure makes things clear as
> to what
> > Microsofts goals are and how it goes about achieving those goals  (
> ie.. as
> > long as we're making money,  forget about quality as it is
> irrelevant ).

> That might be a little unfair. You have to remember that the power
> operation has to be able to handle more than simply squaring a number.
> It does this

>      1.23 ^ 4.56

> just as easily as this

>      1.23 ^ 2

> and there is no simple multiplication that can be done for that first
> calculation.

No, I think it's not unfair at all--the optimization when the power <is>
an integer -- especially for powers of 2 is routine in other compilers.
It's just that MS put so little effort into optimization of the VB
compiler.  The only thing I think one can say in defense is that MS
probably never expected VB to amount to anything near what it turned
into in terms of usage.


Thu, 17 Mar 2005 01:52:15 GMT  
 Co-ordinates

Quote:








> > > >> >Date: 9/27/02 5:18 PM Pacific Daylight Time
> > > >> >Message-id:

> > > >> >Well, if you really want to speed it up, I'd suggest doing
away
> > with
> > > >> >that power operation and convert it to a straight
multiplication

> > > >> >AB = (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1)

> > > >> >still assuming that we are removing the Sqr operation for
> > comparative
> > > >> >speed.

> > > >> >Rick

> > > >> Is there really a speed difference between (x2-x1)^2   and
> > > >(x2-x1)*(x2-x1) in
> > > >> VB6?

> > > >Yes, definitely. The multiplication is some 2.5 times faster than
> > > >raising to a power in the IDE and 4.5 times faster when compiled
(I
> > used
> > > >a Long for my test). Actually, multiplication has always been
faster
> > > >than raising to a power in all version of BASIC and VB.

> > > >Rick

> > > Wow!  That's pretty amazing actually.  It sure makes things clear
as
> > to what
> > > Microsofts goals are and how it goes about achieving those goals
(
> > ie.. as
> > > long as we're making money,  forget about quality as it is
> > irrelevant ).

> > That might be a little unfair. You have to remember that the power
> > operation has to be able to handle more than simply squaring a
number.
> > It does this

> >      1.23 ^ 4.56

> > just as easily as this

> >      1.23 ^ 2

> > and there is no simple multiplication that can be done for that
first
> > calculation.

> No, I think it's not unfair at all--the optimization when the power
<is>
> an integer -- especially for powers of 2 is routine in other
compilers.
> It's just that MS put so little effort into optimization of the VB
> compiler.  The only thing I think one can say in defense is that MS
> probably never expected VB to amount to anything near what it turned
> into in terms of usage.

Well, OK, I can't really argue with that too much. Yes, they could have
put in a test for integer powers and provided a loop that did continuous
multiplications if one was found; but that would have subjected every
other calculation using non-integer powers to run through that test.
Probably a minimal overhead there, but I guess it was kind of a trade
off. And, obviously, under current conditions, deciding on which method
to use is only material when lots of powers are being calculated (in a
loop). For a single calculation, the time differential is unnoticeable.

Rick



Thu, 17 Mar 2005 16:03:25 GMT  
 Co-ordinates
On Sun, 29 Sep 2002 08:03:25 GMT, "Rick Rothstein"

<snip>

Quote:
>Well, OK, I can't really argue with that too much. Yes, they could have
>put in a test for integer powers and provided a loop that did continuous
>multiplications if one was found; but that would have subjected every
>other calculation using non-integer powers to run through that test.
>Probably a minimal overhead there, but I guess it was kind of a trade
>off. And, obviously, under current conditions, deciding on which method
>to use is only material when lots of powers are being calculated (in a
>loop). For a single calculation, the time differential is unnoticeable.

On balance I can live without that sort of optimization
- the trade off is an App that runs an unpredictable path
- (well slightly)

We can always 'optimize' ourselves if it is really necessary



Thu, 17 Mar 2005 16:49:38 GMT  
 
 [ 20 post ]  Go to page: [1] [2]

 Relevant Pages 

1. How do I coordinate the screen's coordinates with a form coordinate

2. Mapping listview coordinates to screen coordinates

3. Cartesian Coordinates vs Picture Box Coordinates

4. Converting container-relative coordinates to screen coordinates

5. Container-relative coordinates to screen coordinates

6. Line Co-ordinates

7. EXCEL 2000 : Selection Co-ordinates

8. Obtaining x,y co-ordinates of a Dropped Object

9. MDI co-ordinates, docking form and more

10. Forcing mouse pointer to move to a co-ordinate

11. Finding mouse co-ordinates

12. how do i use mouse co-ordinates

 

 
Powered by phpBB® Forum Software