December 03, 2020, 12:56:31 pm

## News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........

## Started V2 Class

Started by J B Wood (Zumwalt), September 01, 2006, 09:56:26 pm

0 Members and 1 Guest are viewing this topic.

#### J B Wood (Zumwalt)

##### September 01, 2006, 09:56:26 pm
I am starting this class along with my V3 class to add some more functionality to both 3d and 2d.
Small but needed item, distance2d, first and only method in the class at the moment:

V2.inc
Code Select
`class V2{ declare V2(); declare _V2(); declare distance2D(VECTOR2 P1, VECTOR2 P2),float;}`

V2.src
Code Select
`declare cdecl import, pow(double x, double y),double;#include "V2.inc"V2 :: V2(){}V2 :: _V2(){} V2 :: distance2D(VECTOR2 P1, VECTOR2 P2), float{ float resD2D; resD2D = sqrt(pow(P1.y - P2.y,2) + pow(P1.x - P2.x,2)); return resD2D; }`

#### kryton9

##### September 01, 2006, 10:03:39 pm #1 Last Edit: September 01, 2006, 10:07:47 pm by kryton9
Cool, I read that 3d distance is the same, so with an optional flag it could do either
declare Distance(point p1, point p2, opt int flag);

if (flag 3) resD2D = sqrt(pow(P1.y - P2.y,2) + pow(P1.x - P2.x,2)+ pow(P1.z - P2.z,2));
if (flag 2) resD2D = sqrt(pow(P1.y - P2.y,2) + pow(P1.x - P2.x,2));

for example.

#### J B Wood (Zumwalt)

##### September 01, 2006, 10:06:53 pm #2
Yea the formula is about the same going to add that to my V3 class
sqrt(pow(x2-x1,2)+pow(y2-y1,2)+pow(z2-z1,2))

Key thing to note is the import of the pow math command, makes things simpler.

#### kryton9

##### September 01, 2006, 10:08:19 pm #3
I think ()^2Ãƒâ€šÃ,Â  Ãƒâ€šÃ,Â works also. instead of pow

#### Ionic Wind Support Team

##### September 01, 2006, 10:46:41 pm #4
Yes.  ^ is power just like in basic languages.  Would be faster too.
Ionic Wind Support Team