Author 
Message 
Tony Soneman #1 / 20

Coordinates
If I have 2 sets of coordinates 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 


Stoil Marino #2 / 20

Coordinates
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 coordinates 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 


Duane Bozart #3 / 20

Coordinates
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 coordinates 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 


Rick Rothstei #4 / 20

Coordinates
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:
Quote: > > > If I have 2 sets of coordinates 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 


Dan Te #5 / 20

Coordinates
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 (x2x1)^2 and (x2x1)*(x2x1) in VB6? Dan :)

Wed, 16 Mar 2005 10:35:25 GMT 


Rick Rothstei #6 / 20

Coordinates
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 (x2x1)^2 and (x2x1)*(x2x1) 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 


Tony Soneman #7 / 20

Coordinates
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 (x2x1)^2 and (x2x1)*(x2x1) in > VB6? > Dan :)

Wed, 16 Mar 2005 11:25:54 GMT 


Tony Soneman #8 / 20

Coordinates
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 (x2x1)^2 and (x2x1)*(x2x1) in > VB6? > Dan :)

Wed, 16 Mar 2005 11:25:54 GMT 


Tony Soneman #9 / 20

Coordinates
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 (x2x1)^2 and (x2x1)*(x2x1) in > VB6? > Dan :)

Wed, 16 Mar 2005 11:57:44 GMT 


Duane Bozart #10 / 20

Coordinates
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 (x2x1)^2 and (x2x1)*(x2x1) 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 


Dan Te #11 / 20

Coordinates
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 (x2x1)^2 and >(x2x1)*(x2x1) 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 


Rick Rothstei #12 / 20

Coordinates
Quote:
> >> >Date: 9/27/02 5:18 PM Pacific Daylight Time > >> >Messageid:
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 (x2x1)^2 and > >(x2x1)*(x2x1) 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 


Duane Bozart #13 / 20

Coordinates
Quote:
> > >> >Date: 9/27/02 5:18 PM Pacific Daylight Time > > >> >Messageid:
> > >> >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 (x2x1)^2 and > > >(x2x1)*(x2x1) 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 allthe 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 


Rick Rothstei #14 / 20

Coordinates
Quote:
> > > >> >Date: 9/27/02 5:18 PM Pacific Daylight Time > > > >> >Messageid:
> > > >> >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 (x2x1)^2 and > > > >(x2x1)*(x2x1) 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 allthe 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 noninteger 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 


J Fren #15 / 20

Coordinates
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 noninteger 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 


Page 1 of 2

[ 20 post ] 

Go to page:
[1]
[2] 
