| | 850 | } def |
|---|
| | 851 | |
|---|
| | 852 | %%%%% ### fin insertion ### |
|---|
| | 853 | |
|---|
| | 854 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| | 855 | %%%% cercles %%%% |
|---|
| | 856 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| | 857 | |
|---|
| | 858 | %%%%% ### defcercle ### |
|---|
| | 859 | %% syntaxe : A r /d defcercle |
|---|
| | 860 | /defcercle { |
|---|
| | 861 | 1 dict begin |
|---|
| | 862 | /t@mp@r@ire exch def |
|---|
| | 863 | [ 4 1 roll ] cvx t@mp@r@ire exch |
|---|
| | 864 | end def |
|---|
| | 865 | } def |
|---|
| | 866 | |
|---|
| | 867 | %%%%% ### interdroitecercle ### |
|---|
| | 868 | %% intersection de la droite y = ax+b avec le cercle (x-x0)^2 + (y-y0)^2 = r^2 |
|---|
| | 869 | %% { -- b - y 2 2 3 |
|---|
| | 870 | %% { | x = - -----, y = (b + a x0 + a y0 + (2 a b y0 - 2 a b x0 + |
|---|
| | 871 | %% { -- a |
|---|
| | 872 | %% |
|---|
| | 873 | %% 3 2 2 2 2 4 2 2 2 4 2 2 |
|---|
| | 874 | %% 2 a x0 y0 - a b + a r + a r - a y0 - a x0 )^(1/2)) / (a + 1) |
|---|
| | 875 | %% |
|---|
| | 876 | %% |
|---|
| | 877 | %% -- |
|---|
| | 878 | %% |, |
|---|
| | 879 | %% -- |
|---|
| | 880 | %% -- b - y 2 2 3 |
|---|
| | 881 | %% | x = - -----, y = (b + a x0 + a y0 - (2 a b y0 - 2 a b x0 + |
|---|
| | 882 | %% -- a |
|---|
| | 883 | %% |
|---|
| | 884 | %% 3 2 2 2 2 4 2 2 2 4 2 2 |
|---|
| | 885 | %% 2 a x0 y0 - a b + a r + a r - a y0 - a x0 )^(1/2)) / (a + 1) |
|---|
| | 886 | %% |
|---|
| | 887 | %% -- } |
|---|
| | 888 | %% | } |
|---|
| | 889 | %% -- } |
|---|
| | 890 | |
|---|
| | 891 | %% intersection de la droite x = a avec le cercle (x-x0)^2 + (y-y0)^2 = r^2 |
|---|
| | 892 | %% 2 2 2 1/2 |
|---|
| | 893 | %% {[x = a, y = y0 + (2 a x0 - a + r - x0 ) ], |
|---|
| | 894 | %% |
|---|
| | 895 | %% 2 2 2 1/2 |
|---|
| | 896 | %% [x = a, y = y0 - (2 a x0 - a + r - x0 ) ]} |
|---|
| | 897 | |
|---|
| | 898 | %% intersection de la droite y = b avec le cercle (x-x0)^2 + (y-y0)^2 = r^2 |
|---|
| | 899 | %% 2 2 2 1/2 |
|---|
| | 900 | %% {[y = b, x = x0 + (2 b y0 - b + r - y0 ) ], |
|---|
| | 901 | %% |
|---|
| | 902 | %% 2 2 2 1/2 |
|---|
| | 903 | %% [y = b, x = x0 - (2 b y0 - b + r - y0 ) ]} |
|---|
| | 904 | |
|---|
| | 905 | %% syntaxe : D I r interdroitecercle |
|---|
| | 906 | /interdroitecercle { |
|---|
| | 907 | 16 dict begin |
|---|
| | 908 | /r exch def |
|---|
| | 909 | /y0 exch def |
|---|
| | 910 | /x0 exch def |
|---|
| | 911 | /yB exch def |
|---|
| | 912 | /xB exch def |
|---|
| | 913 | /yA exch def |
|---|
| | 914 | /xA exch def |
|---|
| | 915 | |
|---|
| | 916 | xA yA xB yB verticale? |
|---|
| | 917 | |
|---|
| | 918 | %% la droite est verticale |
|---|
| | 919 | { |
|---|
| | 920 | /xpt1 xA def |
|---|
| | 921 | /xpt2 xA def |
|---|
| | 922 | /quantite |
|---|
| | 923 | 2 xA mul x0 mul xA dup mul sub r dup mul add x0 dup mul sub sqrt |
|---|
| | 924 | def |
|---|
| | 925 | /ypt1 |
|---|
| | 926 | y0 quantite add |
|---|
| | 927 | def |
|---|
| | 928 | /ypt2 |
|---|
| | 929 | y0 quantite sub |
|---|
| | 930 | def |
|---|
| | 931 | } |
|---|
| | 932 | |
|---|
| | 933 | %% la droite n'est pas verticale |
|---|
| | 934 | { |
|---|
| | 935 | /a xA yA xB yB coeffdir def |
|---|
| | 936 | /b xA yA xB yB ordorig def |
|---|
| | 937 | |
|---|
| | 938 | 0 a eq |
|---|
| | 939 | %% la droite est horizontale |
|---|
| | 940 | { |
|---|
| | 941 | /quantite |
|---|
| | 942 | 2 b mul y0 mul |
|---|
| | 943 | b dup mul sub |
|---|
| | 944 | r dup mul add |
|---|
| | 945 | y0 dup mul sub |
|---|
| | 946 | sqrt |
|---|
| | 947 | def |
|---|
| | 948 | /xpt1 |
|---|
| | 949 | x0 quantite add |
|---|
| | 950 | def |
|---|
| | 951 | /xpt2 |
|---|
| | 952 | x0 quantite sub |
|---|
| | 953 | def |
|---|
| | 954 | /ypt1 b def |
|---|
| | 955 | /ypt2 b def |
|---|
| | 956 | } |
|---|
| | 957 | |
|---|
| | 958 | %% la droite n'est pas horizontale |
|---|
| | 959 | { |
|---|
| | 960 | /quantite1 |
|---|
| | 961 | b |
|---|
| | 962 | a x0 mul add |
|---|
| | 963 | a dup mul y0 mul add |
|---|
| | 964 | def |
|---|
| | 965 | /quantite2 |
|---|
| | 966 | 2 a dup mul mul b mul y0 mul |
|---|
| | 967 | 2 a 3 exp mul b mul x0 mul sub |
|---|
| | 968 | 2 a 3 exp mul x0 mul y0 mul add |
|---|
| | 969 | a dup mul b dup mul mul sub |
|---|
| | 970 | a dup mul r dup mul mul add |
|---|
| | 971 | a 4 exp r dup mul mul add |
|---|
| | 972 | a dup mul y0 dup mul mul sub |
|---|
| | 973 | a 4 exp x0 dup mul mul sub |
|---|
| | 974 | sqrt |
|---|
| | 975 | def |
|---|
| | 976 | /quantite3 |
|---|
| | 977 | a dup mul 1 add |
|---|
| | 978 | def |
|---|
| | 979 | /ypt1 |
|---|
| | 980 | quantite1 quantite2 add quantite3 div |
|---|
| | 981 | def |
|---|
| | 982 | /xpt1 |
|---|
| | 983 | ypt1 b sub a div |
|---|
| | 984 | def |
|---|
| | 985 | /ypt2 |
|---|
| | 986 | quantite1 quantite2 sub quantite3 div |
|---|
| | 987 | def |
|---|
| | 988 | /xpt2 |
|---|
| | 989 | ypt2 b sub a div |
|---|
| | 990 | def |
|---|
| | 991 | } |
|---|
| | 992 | ifelse |
|---|
| | 993 | } |
|---|
| | 994 | ifelse |
|---|
| | 995 | |
|---|
| | 996 | xpt1 ypt1 |
|---|
| | 997 | xpt2 ypt2 |
|---|
| | 998 | ordonnepoints |
|---|
| | 999 | end |
|---|
| | 1000 | } def |
|---|
| | 1001 | |
|---|
| | 1002 | %%%%% ### intercercle ### |
|---|
| | 1003 | %% syntaxe : cerc1 cerc2 intercercle --> A B les points d'intersection |
|---|
| | 1004 | %% des 2 cercles, tries par 'ordonnepoints' |
|---|
| | 1005 | /intercercle { |
|---|
| | 1006 | 12 dict begin |
|---|
| | 1007 | /r2 exch def |
|---|
| | 1008 | /y2 exch def |
|---|
| | 1009 | /x2 exch def |
|---|
| | 1010 | /r1 exch def |
|---|
| | 1011 | /y1 exch def |
|---|
| | 1012 | /x1 exch def |
|---|
| | 1013 | |
|---|
| | 1014 | %% on translate pour se ramener a (x1, y1) = (0, 0) |
|---|
| | 1015 | x2 y2 x1 y1 subv |
|---|
| | 1016 | /y2 exch def |
|---|
| | 1017 | /x2 exch def |
|---|
| | 1018 | |
|---|
| | 1019 | %% on prepare l'equation du 2nd degre |
|---|
| | 1020 | |
|---|
| | 1021 | %% 2 2 2 |
|---|
| | 1022 | %% {y = RootOf((4 x2 + 4 y2 ) _Z |
|---|
| | 1023 | %% |
|---|
| | 1024 | %% 3 2 2 2 4 |
|---|
| | 1025 | %% + (-4 y2 - 4 r1~ y2 + 4 y2 r2~ - 4 x2 y2) _Z + x2 |
|---|
| | 1026 | %% |
|---|
| | 1027 | %% 4 2 2 2 2 2 2 2 2 |
|---|
| | 1028 | %% + r2~ - 2 y2 r2~ + 2 x2 y2 - 2 x2 r2~ - 2 r1~ x2 |
|---|
| | 1029 | %% |
|---|
| | 1030 | %% 4 4 2 2 2 2 |
|---|
| | 1031 | %% + r1~ + y2 + 2 r1~ y2 - 2 r1~ r2~ ), x = 1/2 (-2 y2 |
|---|
| | 1032 | %% |
|---|
| | 1033 | %% 2 2 2 |
|---|
| | 1034 | %% RootOf((4 x2 + 4 y2 ) _Z |
|---|
| | 1035 | %% |
|---|
| | 1036 | %% 3 2 2 2 4 |
|---|
| | 1037 | %% + (-4 y2 - 4 r1~ y2 + 4 y2 r2~ - 4 x2 y2) _Z + x2 |
|---|
| | 1038 | %% |
|---|
| | 1039 | %% 4 2 2 2 2 2 2 2 2 |
|---|
| | 1040 | %% + r2~ - 2 y2 r2~ + 2 x2 y2 - 2 x2 r2~ - 2 r1~ x2 |
|---|
| | 1041 | %% |
|---|
| | 1042 | %% 4 4 2 2 2 2 2 2 2 |
|---|
| | 1043 | %% + r1~ + y2 + 2 r1~ y2 - 2 r1~ r2~ ) + r1~ + x2 + y2 |
|---|
| | 1044 | %% |
|---|
| | 1045 | %% 2 |
|---|
| | 1046 | %% - r2~ )/x2} |
|---|
| | 1047 | |
|---|
| | 1048 | %% coeff pour le degre 2 |
|---|
| | 1049 | /a |
|---|
| | 1050 | %% 2 2 2 |
|---|
| | 1051 | %% {y = RootOf((4 x2 + 4 y2 ) _Z |
|---|
| | 1052 | 4 x2 dup mul mul |
|---|
| | 1053 | 4 y2 dup mul mul add |
|---|
| | 1054 | def |
|---|
| | 1055 | |
|---|
| | 1056 | %% coeff pour le degre 1 |
|---|
| | 1057 | %% |
|---|
| | 1058 | /b |
|---|
| | 1059 | %% 3 2 2 2 |
|---|
| | 1060 | %% + (-4 y2 - 4 r1~ y2 + 4 y2 r2~ - 4 x2 y2) _Z |
|---|
| | 1061 | -4 y2 3 exp mul |
|---|
| | 1062 | 4 r1 dup mul mul y2 mul sub |
|---|
| | 1063 | 4 r2 dup mul mul y2 mul add |
|---|
| | 1064 | 4 x2 dup mul mul y2 mul sub |
|---|
| | 1065 | def |
|---|
| | 1066 | |
|---|
| | 1067 | %% coeff pour le degre 0 |
|---|
| | 1068 | %% |
|---|
| | 1069 | /c { |
|---|
| | 1070 | %% 4 |
|---|
| | 1071 | %% + x2 |
|---|
| | 1072 | x2 4 exp |
|---|
| | 1073 | %% |
|---|
| | 1074 | %% 4 2 2 2 2 2 2 2 2 |
|---|
| | 1075 | %% + r2~ - 2 y2 r2~ + 2 x2 y2 - 2 x2 r2~ - 2 r1~ x2 |
|---|
| | 1076 | r2 4 exp add |
|---|
| | 1077 | 2 y2 dup mul mul r2 dup mul mul sub |
|---|
| | 1078 | 2 x2 dup mul mul y2 dup mul mul add |
|---|
| | 1079 | 2 x2 dup mul mul r2 dup mul mul sub |
|---|
| | 1080 | 2 x2 dup mul mul r1 dup mul mul sub |
|---|
| | 1081 | %% |
|---|
| | 1082 | %% 4 4 2 2 2 2 |
|---|
| | 1083 | %% + r1~ + y2 + 2 r1~ y2 - 2 r1~ r2~ ) |
|---|
| | 1084 | r1 4 exp add |
|---|
| | 1085 | y2 4 exp add |
|---|
| | 1086 | 2 r1 dup mul mul y2 dup mul mul add |
|---|
| | 1087 | 2 r1 dup mul mul r2 dup mul mul sub |
|---|
| | 1088 | } def |
|---|
| | 1089 | |
|---|
| | 1090 | a b c solve2nddegre |
|---|
| | 1091 | /Y1 exch def |
|---|
| | 1092 | /Y0 exch def |
|---|
| | 1093 | |
|---|
| | 1094 | /X0 |
|---|
| | 1095 | %% x = 1/2 (-2 y2 Y |
|---|
| | 1096 | -2 y2 mul Y0 mul |
|---|
| | 1097 | %% |
|---|
| | 1098 | %% 2 2 2 |
|---|
| | 1099 | %% + r1~ + x2 + y2 |
|---|
| | 1100 | r1 dup mul add |
|---|
| | 1101 | x2 dup mul add |
|---|
| | 1102 | y2 dup mul add |
|---|
| | 1103 | %% |
|---|
| | 1104 | %% 2 |
|---|
| | 1105 | %% - r2~ )/x2} |
|---|
| | 1106 | r2 dup mul sub |
|---|
| | 1107 | |
|---|
| | 1108 | 2 x2 mul div |
|---|
| | 1109 | def |
|---|
| | 1110 | |
|---|
| | 1111 | /X1 |
|---|
| | 1112 | %% x = 1/2 (-2 y2 Y |
|---|
| | 1113 | -2 y2 mul Y1 mul |
|---|
| | 1114 | %% |
|---|
| | 1115 | %% 2 2 2 |
|---|
| | 1116 | %% + r1~ + x2 + y2 |
|---|
| | 1117 | r1 dup mul add |
|---|
| | 1118 | x2 dup mul add |
|---|
| | 1119 | y2 dup mul add |
|---|
| | 1120 | %% |
|---|
| | 1121 | %% 2 |
|---|
| | 1122 | %% - r2~ )/x2} |
|---|
| | 1123 | r2 dup mul sub |
|---|
| | 1124 | |
|---|
| | 1125 | 2 x2 mul div |
|---|
| | 1126 | def |
|---|
| | 1127 | |
|---|
| | 1128 | %% on depose le resultat, en n'oubliant pas de retranslater en sens |
|---|
| | 1129 | %% inverse |
|---|
| | 1130 | |
|---|
| | 1131 | X0 Y0 x1 y1 addv |
|---|
| | 1132 | X1 Y1 x1 y1 addv |
|---|
| | 1133 | ordonnepoints |
|---|
| | 1134 | end |
|---|
| | 1135 | } def |
|---|
| | 1136 | |
|---|
| | 1137 | %%%%% ### ABcercle ### |
|---|
| | 1138 | %% syntaxe : A B C ABcercle --> le cercle passant par A, B, C |
|---|
| | 1139 | /ABcercle { |
|---|
| | 1140 | 3 dict begin |
|---|
| | 1141 | /@3 defpoint |
|---|
| | 1142 | /@2 defpoint |
|---|
| | 1143 | /@1 defpoint |
|---|
| | 1144 | @1 @2 mediatrice |
|---|
| | 1145 | @1 @3 mediatrice |
|---|
| | 1146 | interdroite |
|---|
| | 1147 | dupp |
|---|
| | 1148 | @3 distance |
|---|
| | 1149 | end |
|---|
| | 1150 | } def |
|---|
| | 1151 | |
|---|
| | 1152 | %%%%% ### diamcercle ### |
|---|
| | 1153 | %% syntaxe : A B diamcercle --> le cercle de diametre [AB] |
|---|
| | 1154 | /diamcercle { |
|---|
| | 1155 | 4 copy |
|---|
| | 1156 | distance 2 div |
|---|
| | 1157 | 5 1 roll |
|---|
| | 1158 | milieu |
|---|
| | 1159 | 3 -1 roll |
|---|
| | 10674 | /projname where pop /projname undef |
|---|
| | 10675 | } if |
|---|
| | 10676 | } def |
|---|
| | 10677 | |
|---|
| | 10678 | /proj-pst-cercle { |
|---|
| | 10679 | action (none) eqstring not { |
|---|
| | 10680 | planprojpst bprojscene |
|---|
| | 10681 | solidlinewidth setlinewidth |
|---|
| | 10682 | linestyle |
|---|
| | 10683 | linecolor |
|---|
| | 10684 | range aload pop proj-args |
|---|
| | 10685 | proj-definition cvx exec Cercle |
|---|
| | 10686 | eprojscene |
|---|
| | 10687 | } if |
|---|
| | 10688 | /projname where { |
|---|
| | 10689 | pop |
|---|
| | 10690 | proj-args proj-definition cvx exec projname cvlit defcercle |
|---|
| | 10691 | /projname where pop /projname undef |
|---|
| | 10692 | } if |
|---|
| | 10693 | } def |
|---|
| | 10694 | |
|---|
| | 10695 | /proj-pst-line { |
|---|
| | 10696 | action (none) eqstring not { |
|---|
| | 10697 | planprojpst bprojscene |
|---|
| | 10698 | solidlinewidth setlinewidth |
|---|
| | 10699 | linestyle |
|---|
| | 10700 | linecolor |
|---|
| | 10701 | [proj-args proj-definition cvx exec ] ligne |
|---|
| | 10702 | eprojscene |
|---|
| | 10703 | } if |
|---|
| | 10704 | /projname where { |
|---|
| | 10705 | pop |
|---|
| | 10706 | [proj-args proj-definition cvx exec] projname cvlit exch def |
|---|
| | 10707 | /projname where pop /projname undef |
|---|
| | 10708 | } if |
|---|
| | 10709 | } def |
|---|
| | 10710 | |
|---|
| | 10711 | /proj-pst-angledroit { |
|---|
| | 10712 | action (none) eqstring not { |
|---|
| | 10713 | planprojpst bprojscene |
|---|
| | 10714 | solidlinewidth setlinewidth |
|---|
| | 10715 | linestyle |
|---|
| | 10716 | linecolor |
|---|
| | 10717 | proj-args proj-definition cvx exec angledroit |
|---|
| | 10718 | eprojscene |
|---|