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
|
Choose the first point to define your reference line
(setq pt1(getpoint "\n Start Point: "))
(setq pt1x (car pt1))
(setq pt1y (cadr pt1))
Choose the second point to define your reference line
(setq pt2(getpoint "\n End Point: "))
(setq pt2x (car pt2))
(setq pt2y (cadr pt2))
Choose the point you want to have perpendiculary measured (and drawn) to the reference line
(setq temppt(getpoint "\n Point to calculate: "))
(setq tempptx (car temppt))
(setq temppty (cadr temppt))
Voila où je commence á rencontrer des problèmes:
i sont les coordonnées du point calculé sur la ligne
EPS = 0.000001; // smallest positive value: less than that to be considered zero
EPSEPS = EPS * EPS; // and its square
function SqLineMagnitude(const pt1x, pt1y, pt2x, pt2y: extended): extended;
res := (pt2x - pt1x) * (pt2x - pt1x) + (pt2y - pt1y) * (pt2y - pt1y);
AutoLISP: (defun SqLineMagnitude (+(* (- pt2x pt1x)(- pt2x pt1x))(*(- pt2y pt1y) (- pt2y pt1y)))
begin
SqLineMag := SqLineMagnitude(pt1x, pt1y, pt2x, pt2y);
if SqLineMag < EPSEPS then exit;// Calculation not possible, choose one another point
u := ( (tempptx - pt1x)*(pt2x - pt1x) + (temppty - pt1y)*(pt2y - pt1y) ) / SqLineMag;
AutoLISP: (defun u (+(* (- tempptx pt1x)(- pt2x pt1x))(*(- temppty pt1y) (- pt2y pt1y)))
if (u < EPS) or (u > 1) then
ix := SqLineMagnitude(tempptx, temppty, pt1x, pt1y);
iy := SqLineMagnitude(tempptx, temppty, pt2x, pt2y);
else // if (u > EPS) or (u < 1) then
ix := pt1x + u * (pt2x - pt1x);
iy := pt1y + u * (pt2y - pt1y);
result := SqlineMagnitude(px, py, ix, iy);
// finally convert to actual distance not its square
result := sqrt(result);
Quand tout cela fonctionnera, je dessinerais une flêche qui montre la direction á suivre du point pour rencontrer ma ligne de référence ainsi que la distance en millimetres.
Je demanderais en suite á l'utilisateur, si il veux continuer avec un autre point ou arrêter (á l'aide de CANCEL/Echap) |
Partager