Back to index

wims  3.65+svn20090927
geogebra.inc
Go to the documentation of this file.
00001 
00002 pari_precision=$precision
00003 
00004 pari_header=\
00005 \
00006 {\
00007  line(p1,p2)=\
00008  if(#p2==2,\
00009   a=p2[2]-p1[2];b=p1[1]-p2[1];c=p2[1]*p1[2]-p1[1]*p2[2];\
00010   return([0,0,0,a,b,c]));\
00011  if(#p2==3,\
00012   return([0,0,0,-p2[2],p2[1],p2[2]*p1[1]-p2[1]*p1[2]]),\
00013   return([0,0,0,p2[4],p2[5],-(p2[4]*p1[1] + p2[5]*p1[2])]));\
00014 }\
00015 {\
00016 ray(p1,p2)=line(p1,p2)\
00017 }\
00018 {\
00019  midperpendicular(p1,p2)=\
00020   x1=p1[1];y1=p1[2];x2=p2[1];y2=p2[2];\
00021   a=x1-x2;b=y1-y2;c=(x2^2+y2^2-x1^2-y1^2)/2;\
00022   xm=(x1+x2)/2;ym=(y1+y2)/2;xd=x2-x1;yd=y2-y1;\
00023   return([0,0,0,a,b,c]);\
00024 }\
00025 \
00026 {\
00027  perpendicular(p1,p2)=\
00028   x1=p1[1];y1=p1[2];\
00029   if(#p2==6,a=-p2[5];b=p2[4],a=p2[1];b=p2[2]);\
00030   c=-(a*p1[1]+b*p1[2]);\
00031   return([0,0,0,a,b,c]);\
00032 }\
00033 \
00034 {\
00035  bissector(p1,p2,p3)=\
00036   v1=p1-p2; v2=p3-p2;\
00037   v1=v1/sqrt(norml2(v1)) ; v2=v2/sqrt(norml2(v1)) ;\
00038   return(midperpendicular(p2+v1,p2+v2));\
00039 }\
00040 {\
00041  circle(p1,p2)=\
00042   circ=(x-p1[1])^2 +(y-p1[2])^2 ;\
00043   if (#p2==2, diff=p2-p1;\
00044   c=circ-(diff[1]^2+diff[2]^2),\
00045   c=circ-(p2)^2);\
00046 return([polcoeff(c,2,x),polcoeff(c,2,y),polcoeff(polcoeff(c,1,x),1,y),polcoeff(polcoeff(c,1,x),0,y),polcoeff(polcoeff(c,0,x),1,y),polcoeff(polcoeff(c,0,x),0,y)])\
00047 }\
00048 \
00049 {\
00050  segment(p1,p2)=\
00051   if( #p2==2, return(sqrt(norml2(p2-p1))),return(p2));\
00052 }\
00053 
00054 
00055 
00056 {\
00057  middle(x1,y1,x2,y2)=\
00058   x=(x1+x2)/2;y=(y1+y2)/2;\
00059   return([x,y]);\
00060 }\
00061 
00062 
00063 
00064 \\ compute the line through 2 points ax+by+c=0 segment,x1,y1,x2,y2\
00065 {\
00066  segment(p1,p2)=\
00067   x1=p1[1];y1=p1[2];x2=p2[1];y2=p2[2];\
00068   a=y2-y1;b=x1-x2;c=x2*y1-x1*y2;cnorm=max(abs(a),max(abs(b),abs(c)));\
00069   a=a/cnorm;b=b/cnorm;c=c/cnorm;\
00070   return([a,b,c,x1,y1,x2,y2]);\
00071 }\
00072 ray(p1,p2)=\
00073   x1=p1[1];y1=p1[2];x2=p2[1];y2=p2[2];\
00074   a=y2-y1;b=x1-x2;c=x2*y1-x1*y2;cnorm=max(abs(a),max(abs(b),abs(c)));\
00075   a=a/cnorm;b=b/cnorm;c=c/cnorm;\
00076   return([a,b,c,x1,y1]);\
00077 }\
00078 \
00079 \\ compute the mid-perpendicular line of 2 points\
00080 {\
00081  midper(p1,p2)=\
00082   x1=p1[1];y1=p1[2];x2=p2[1];y2=p2[2];\
00083   a=x1-x2;b=y1-y2;c=(x2^2+y2^2-x1^2-y1^2)/2;cnorm=max(abs(a),max(abs(b),abs(c)));\
00084   a=a/cnorm;b=b/cnorm;c=c/cnorm;\
00085   xm=(x1+x2)/2;ym=(y1+y2)/2;xd=x2-x1;yd=y2-y1;\
00086   return([a,b,c,xm+yd,ym-xd,xm-yd,ym+xd]);\
00087 }\
00088 \
00089 \\ compute the middle of 2 points\
00090 {\
00091  middle(x1,y1,x2,y2)=\
00092   x=(x1+x2)/2;y=(y1+y2)/2;\
00093   return([x,y]);\
00094 }\
00095 {\
00096  barycenter(p1,p2,t)=\
00097   x1=p1[1];y1=p1[2];x2=p2[1];y2=p2[2] ; t1=t[1]; t2=t[2];\
00098   if(t1+t2 == 0, return([]), x=(t1*x1+t2*x2)/(t1+t2);y=(t1*y1+t2*y2)/(t1+t2);\
00099   return([x,y]));\
00100 }\
00101 \
00102 \\ compute the intersection point of two lines\
00103 {\
00104  line_intersect(l1,l2)=\
00105   a1=l1[1];b1=l1[2];c1=l1[3];a2=l2[1];b2=l2[2];c2=l2[3];\
00106   det=a1*b2-a2*b1;\
00107   if(abs(det)<compare_precision, return("error parallel"));\
00108   x=-(c1*b2-b1*c2)/det;y=-(a1*c2-a2*c1)/det;\
00109   return([x,y]);\
00110 }\
00111 \
00112 \\ compute the foot point of perpendicular of a line through a point.\
00113 {\
00114  foot_perp(l1,p1)=\
00115   a1=l1[1];b1=l1[2];c1=l1[3];x1=p[1];x2=p[2];c2=-b1*x1+a1*y1;\
00116   det=(b1)^2+(a1)^2;\
00117   x=(-c1*a1-c2*b1)/det;y=(a1*c2-b1*c1)/det;\
00118   return([x,y]);\
00119 }\
00120 \
00121 \\ internal computation, intersection point of a lines and a circle\
00122 {\
00123  lc_int_(data)=\
00124   a=data[1];b=data[2];c=data[3];xc=data[4];yc=data[5];r=data[6];\
00125   if(abs(a)>abs(b),\
00126    b=-b/a;c=-c/a;\
00127    A=b^2+1;B=b*(c-xc)-yc;C=(c-xc)^2+yc^2-r^2;discr=B^2-A*C;\
00128    if(discr<-(compare_precision^2), return("error no_intersection"));\
00129    if(discr<0, discr=0);\
00130    discr=sqrt(discr);y1=(-B+discr)/A;y2=(-B-discr)/A;\
00131    x1=b*y1+c;x2=b*y2+c;\
00132   ,\
00133    a=-a/b;c=-c/b;\
00134    A=a^2+1;B=a*(c-yc)-xc;C=(c-yc)^2+xc^2-r^2;discr=B^2-A*C;\
00135    if(discr<-(compare_precision^2), return("error no_intersection"));\
00136    if(discr<0, discr=0);\
00137    discr=sqrt(discr);x1=(-B+discr)/A;x2=(-B-discr)/A;\
00138    y1=a*x1+c;y2=a*x2+c;\
00139   );\
00140   if(abs(x1)<range_limit && abs(y1)<range_limit && pointcheck([x1,y1])==0,\
00141    out=[x1,y1], out=[]);\
00142   if(abs(x2)<range_limit && abs(y2)<range_limit && \
00143    pointcheck([x2,y2])==0 && max(abs(x1-x2),abs(y1-y2))>closeness,\
00144    out=concat(out,[x2,y2]));\
00145   if(out==[], return("error no_available"), return(out));\
00146 }\
00147 \
00148 \\ compute the intersection point of a lines and a circle\
00149 {\
00150  lc_intersect(l1,c2)=\
00151   return(lc_int_(l1,c2));\
00152 }\
00153 \
00154 \\ compute the intersection point of two circles\
00155 {\
00156  circle_intersect(c1,c2)=\
00157   x1=c1[1];y1=c1[2];r1=c1[3];x2=c2[1];y2=c2[2];r2=c2[3];\
00158   a=2*(x1-x2);b=2*(y1-y2);c=x2^2+y2^2-x1^2-y1^2+r1^2-r2^2;\
00159   cnorm=max(abs(a),max(abs(b),abs(c)));\
00160   return(lc_int_([a/cnorm,b/cnorm,c/cnorm,x1,y1,r1]));\
00161 }\
00162 \
00163 \\ compute a circle of center p1 and through p2.\
00164 {\
00165  circle(p1,p2)=\
00166   diff=p2-p1;\
00167   radius=sqrt(diff[1]^2+diff[2]^2);\
00168   cir=concat(p1,radius);
00169   return(cir);\
00170 }\