File: geogebra.inc

package info (click to toggle)
wims 2%3A4.29a%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 185,704 kB
  • sloc: xml: 366,687; javascript: 120,570; ansic: 62,341; java: 62,170; sh: 7,744; perl: 3,937; yacc: 3,217; cpp: 1,915; lex: 1,805; makefile: 1,084; lisp: 914; pascal: 601; python: 520; php: 318; asm: 7
file content (163 lines) | stat: -rw-r--r-- 4,430 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163

pari_precision=$precision

pari_header=$pari_header\
\
{\
 line(p1,p2)=\
 if(#p2==2,\
  a=p2[2]-p1[2];b=p1[1]-p2[1];c=p2[1]*p1[2]-p1[1]*p2[2];\
  return([0,0,0,a,b,c]));\
 if(#p2==3,\
  return([0,0,0,-p2[2],p2[1],p2[2]*p1[1]-p2[1]*p1[2]]),\
  return([0,0,0,p2[4],p2[5],-(p2[4]*p1[1] + p2[5]*p1[2])]));\
}\
{\
ray(p1,p2)=line(p1,p2)\
}\
{\
 midperpendicular(p1,p2)=\
  x1=p1[1];y1=p1[2];x2=p2[1];y2=p2[2];\
  a=x1-x2;b=y1-y2;c=(x2^2+y2^2-x1^2-y1^2)/2;\
  xm=(x1+x2)/2;ym=(y1+y2)/2;xd=x2-x1;yd=y2-y1;\
  return([0,0,0,a,b,c]);\
}\
\
{\
 perpendicular(p1,p2)=\
  x1=p1[1];y1=p1[2];\
  if(#p2==6,a=-p2[5];b=p2[4],a=p2[1];b=p2[2]);\
  c=-(a*p1[1]+b*p1[2]);\
  return([0,0,0,a,b,c]);\
}\
\
{\
 bissector(p1,p2,p3)=\
  v1=p1-p2; v2=p3-p2;\
  v1=v1/sqrt(norml2(v1)) ; v2=v2/sqrt(norml2(v1)) ;\
  return(midperpendicular(p2+v1,p2+v2));\
}\
\
{\
 circle(p1,p2)=\
  circ=(x-p1[1])^2 +(y-p1[2])^2 ;\
  if (#p2==2, diff=p2-p1;\
  c=circ-(diff[1]^2+diff[2]^2),\
  c=circ-(p2)^2);\
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)])\
}\
\
{\
 segment(p1,p2)=\
  if( #p2==2, return(sqrt(norml2(p2-p1))),return(p2));\
}\
\
\\compute the middle of 2 points\
{\
 middle(x1,y1,x2,y2)=\
  x=(x1+x2)/2;y=(y1+y2)/2;\
  return([x,y]);\
}\


\\ compute the line through 2 points ax+by+c=0 segment,x1,y1,x2,y2\
{\
 segment(p1,p2)=\
  x1=p1[1];y1=p1[2];x2=p2[1];y2=p2[2];\
  a=y2-y1;b=x1-x2;c=x2*y1-x1*y2;cnorm=max(abs(a),max(abs(b),abs(c)));\
  a=a/cnorm;b=b/cnorm;c=c/cnorm;\
  return([a,b,c,x1,y1,x2,y2]);\
}\
ray(p1,p2)=\
  x1=p1[1];y1=p1[2];x2=p2[1];y2=p2[2];\
  a=y2-y1;b=x1-x2;c=x2*y1-x1*y2;cnorm=max(abs(a),max(abs(b),abs(c)));\
  a=a/cnorm;b=b/cnorm;c=c/cnorm;\
  return([a,b,c,x1,y1]);\
}\
\
\\ compute the mid-perpendicular line of 2 points\
{\
 midper(p1,p2)=\
  x1=p1[1];y1=p1[2];x2=p2[1];y2=p2[2];\
  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)));\
  a=a/cnorm;b=b/cnorm;c=c/cnorm;\
  xm=(x1+x2)/2;ym=(y1+y2)/2;xd=x2-x1;yd=y2-y1;\
  return([a,b,c,xm+yd,ym-xd,xm-yd,ym+xd]);\
}\
\
{\
 barycenter(p1,p2,t)=\
  x1=p1[1];y1=p1[2];x2=p2[1];y2=p2[2] ; t1=t[1]; t2=t[2];\
  if(t1+t2 == 0, return([]), x=(t1*x1+t2*x2)/(t1+t2);y=(t1*y1+t2*y2)/(t1+t2);\
  return([x,y]));\
}\
\
\\ compute the intersection point of two lines\
{\
 line_intersect(l1,l2)=\
  a1=l1[1];b1=l1[2];c1=l1[3];a2=l2[1];b2=l2[2];c2=l2[3];\
  det=a1*b2-a2*b1;\
  if(abs(det)<compare_precision, return("error parallel"));\
  x=-(c1*b2-b1*c2)/det;y=-(a1*c2-a2*c1)/det;\
  return([x,y]);\
}\
\
\\ compute the foot point of perpendicular of a line through a point.\
{\
 foot_perp(l1,p1)=\
  a1=l1[1];b1=l1[2];c1=l1[3];x1=p[1];x2=p[2];c2=-b1*x1+a1*y1;\
  det=(b1)^2+(a1)^2;\
  x=(-c1*a1-c2*b1)/det;y=(a1*c2-b1*c1)/det;\
  return([x,y]);\
}\
\
\\ internal computation, intersection point of a line and a circle\
{\
 lc_int_(data)=\
  a=data[1];b=data[2];c=data[3];xc=data[4];yc=data[5];r=data[6];\
  if(abs(a)>abs(b),\
   b=-b/a;c=-c/a;\
   A=b^2+1;B=b*(c-xc)-yc;C=(c-xc)^2+yc^2-r^2;discr=B^2-A*C;\
   if(discr<-(compare_precision^2), return("error no_intersection"));\
   if(discr<0, discr=0);\
   discr=sqrt(discr);y1=(-B+discr)/A;y2=(-B-discr)/A;\
   x1=b*y1+c;x2=b*y2+c;\
  ,\
   a=-a/b;c=-c/b;\
   A=a^2+1;B=a*(c-yc)-xc;C=(c-yc)^2+xc^2-r^2;discr=B^2-A*C;\
   if(discr<-(compare_precision^2), return("error no_intersection"));\
   if(discr<0, discr=0);\
   discr=sqrt(discr);x1=(-B+discr)/A;x2=(-B-discr)/A;\
   y1=a*x1+c;y2=a*x2+c;\
  );\
  if(abs(x1)<range_limit && abs(y1)<range_limit && pointcheck([x1,y1])==0,\
   out=[x1,y1], out=[]);\
  if(abs(x2)<range_limit && abs(y2)<range_limit && \
   pointcheck([x2,y2])==0 && max(abs(x1-x2),abs(y1-y2))>closeness,\
   out=concat(out,[x2,y2]));\
  if(out==[], return("error no_available"), return(out));\
}\
\
\\ compute the intersection point of a line and a circle\
{\
 lc_intersect(l1,c2)=\
  return(lc_int_(l1,c2));\
}\
\
\\ compute the intersection point of two circles\
{\
 circle_intersect(c1,c2)=\
  x1=c1[1];y1=c1[2];r1=c1[3];x2=c2[1];y2=c2[2];r2=c2[3];\
  a=2*(x1-x2);b=2*(y1-y2);c=x2^2+y2^2-x1^2-y1^2+r1^2-r2^2;\
  cnorm=max(abs(a),max(abs(b),abs(c)));\
  return(lc_int_([a/cnorm,b/cnorm,c/cnorm,x1,y1,r1]));\
}\
\
\\ compute a circle of center p1 and through p2.\
{\
 circle(p1,p2)=\
  diff=p2-p1;\
  radius=sqrt(diff[1]^2+diff[2]^2);\
  cir=concat(p1,radius);
  return(cir);\
}\