### Author Topic: How to do it in AutoLISP then in ObjectARX  (Read 3074 times)

0 Members and 1 Guest are viewing this topic.

#### LE

• Guest
##### How to do it in AutoLISP then in ObjectARX
« on: July 25, 2006, 10:13:26 PM »
Just want to post some functions written originally  in AutoLisp and then translated into ObjectARX

Function: NDIV divides a vector in "n" numbers of parts.

In AutoLISP
Code: [Select]
`(defun NDIV  (pt1 pt2 n)  (mapcar '+ pt1 (mapcar '/ (mapcar '- pt2 pt1) (list n n n))))`
In ObjectARX
Code: [Select]
`static void PtNdiv(ads_point p1, ads_point p2, double ndiv, ads_point ptres){ ptres[0] = p1[0] + (p2[0] - p1[0]) / ndiv; ptres[1] = p1[1] + (p2[1] - p1[1]) / ndiv; ptres[2] = p1[2] + (p2[2] - p1[2]) / ndiv;}`
Function: CENCIR giving three points find the circle center.

In AutoLISP
Code: [Select]
`(defun CENCIR  (p0 pm p1 / p)  (inters (setq p (ndiv p0 pm 2))   (polar p (+ (angle p0 pm) (/ pi 2)) 1)   (setq p (ndiv p1 pm 2))   (polar p (- (angle p1 pm) (/ pi 2)) 1)   nil))`
In ObjectARX
Code: [Select]
`#define PI 3.141592653589793238462643383279502884197169399375105820974944592308int CenCir(ads_point p0, ads_point pm, ads_point p1, ads_point ptres) { ads_point from1,to1,from2,to2,ptint; int teston; teston=0; PtNdiv(p0,pm,2,from1); acutPolar(from1, (acutAngle(p0,pm) + (PI / 2)), 1, to1); PtNdiv(p1,pm,2,from2); acutPolar(from2, (acutAngle(p1,pm) - (PI / 2)), 1, to2); if (acdbInters(from1,to1,from2,to2,teston,ptres)==RTNORM) { ads_point_set(ptres,ptint); return TRUE; } else { return FALSE; }}`
Function: P1CLC passing a point, center, arclength & direction draw an arc.

In AutoLISP
Code: [Select]
`(defun P1CLC  (p1 cen lc dir / r r1 delta delt1)  (setq r     (distance cen p1) r1    (sqrt (- (expt r 2) (expt (/ lc 2) 2))) delta (* 2 (atan (/ lc (* 2 r1)))) delt1 (/ (* delta 180) pi))  (if (minusp dir)    (setq delt1 (* delt1 -1)))  (vl-cmdf "._ARC" "_C" cen p1 "_A" delt1))`
In ObjectARX
Code: [Select]
`void CmdCall (struct resbuf *cmdlist) { if (cmdlist==NULL) { acdbFail("\nCouldn't create list buffer\n"); acutRelRb(cmdlist); }else { int status; struct resbuf rb, rb1; acedGetVar("CMDECHO", &rb); rb1.restype = RTSHORT; rb1.resval.rint = 0; acedSetVar("CMDECHO", &rb1); status=acedCmd(cmdlist); acutRelRb(cmdlist); if ((status==RTNORM)&&(rb.restype == RTSHORT)) { acedSetVar("CMDECHO", &rb); } if ((status==RTCAN)&&(rb.restype==RTSHORT)) { acedSetVar("CMDECHO", &rb); } }}void p1clc(ads_point p1, ads_point cen, ads_real lc, short dir) { ads_real r,r1,delta,delt1; r=acutDistance(cen,p1); r1= sqrt((pow(r,2) - pow(lc/2,2))); delta=(2 * atan((lc / (2*r1)))); delt1=((delta*180) / PI); if (dir < 0) { //(dir==-1) { delt1=(delt1 * -1); } struct resbuf *cmdlist=NULL; cmdlist=acutBuildList( RTSTR, "_.ARC", RTSTR, "_C", RT3DPOINT, cen, RT3DPOINT, p1, RTSTR, "_A", RTREAL, delt1, 0); CmdCall(cmdlist);}`

#### Alexander Rivilis

• Bull Frog
• Posts: 212
• Programmer from Kyiv (Ukraine)
##### Re: How to do it in AutoLISP then in ObjectARX
« Reply #1 on: July 26, 2006, 04:03:23 AM »
My version:
Code: [Select]
`int CenCir(ads_point p0, ads_point pm, ads_point p1, ads_point ptres) {  AcGeVector3d v1(asPnt3d(p0)-asPnt3d(pm)),               v2(asPnt3d(p1)-asPnt3d(pm));  if (v1.isParallelTo(v2)) return FALSE;  AcGeCircArc3d crc(asPnt3d(p0),asPnt3d(pm),asPnt3d(p1));  ads_point_set(ptres,asDblArray(crc.center()));  return TRUE;}`

#### Kerry

• Mesozoic relic
• Seagull
• Posts: 11654
• class keyThumper<T>:ILazy<T>
##### Re: How to do it in AutoLISP then in ObjectARX
« Reply #2 on: July 26, 2006, 04:36:58 AM »
My version:
Code: [Select]
`int CenCir( .. ... return FALSE;..   return TRUE;}`

I keep forgetting that C++ TRUE and FALSE are ints, not boolean ..
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

#### LE

• Guest
##### Re: How to do it in AutoLISP then in ObjectARX
« Reply #3 on: July 26, 2006, 12:27:12 PM »
My version:
Code: [Select]
`int CenCir( .. ... return FALSE;..   return TRUE;}`

I keep forgetting that C++ TRUE and FALSE are ints, not boolean ..

Yes they are part of the #define's like:

Code: [Select]
`#define TRUE 1#define FALSE 0`
In example more definitions can be:

Code: [Select]
`#define BAD 0#define TRUE 1#define FALSE 0#define CLOCKWISE 1#define COUNTERCLOCKWISE-1#define PI 3.141592653589793238462643383279502884197169399375105820974944592308#define 2PI 6.28318530717958647692528676655901#define MIN(x,y) (x < y ? x : y)#define MAX(x,y) (x > y ? x : y)//#define ENGLISH 1#define EPS 1e-05#define PI90 1.5707963267948966192313216916398#define PI270 4.7123889803846898576939650749193#define PI360 6.283185307179586476925286766559#define Absolute(a)  ((a) >= 0.0 ? (a) : -(a))#define EQN(x,y) (Absolute((x) - (y)) <= EPS)#define EQNPLUS(x, y)(EQN(x,y) || x > y)#define EQNMINUS(x,y)(EQN(x,y) || x < y)// For checking near equal floating-point values #define EPSILON 0.001 //0.0000000001 //0.0001   // tolerance.#define DOUBLE_EQ(x,v) (((v - EPSILON) < x) && (x <( v + EPSILON)))`