如何使用 whatever 来定义线段上的一个点?

如何使用 whatever 来定义线段上的一个点?

点 M 使得直线 (CM) 垂直于直线 (NP)。我不明白这段代码的错误所在。

\documentclass[border=5mm]{standalone}
\usepackage{luatex85}
\usepackage{luamplib}
\usepackage{unicode-math}
\setmainfont{TeX Gyre Pagella}
\setmathfont{TeX Gyre Pagella Math}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
path carre, p;
carre = unitsquare scaled 138;

pair a, b, c, d, N, P, M;
a = point 0 of carre;
b = point 1 of carre;
c = point 2 of carre;
d = point 3 of carre;

p = b -- d;
N = whatever[a,d];
P = whatever[a,b];
M = whatever[b,d];
(M - c) dotprod (P - N) = 0;

draw M -- c;

draw p  withcolor blue;
draw carre withcolor red;

label.lft("$A$", point 0 of carre);
label.lrt("$B$", point 1 of carre);
label.urt("$C$", point 2 of carre);
label.ulft("$D$", point 3 of carre);
endfig;
\end{mplibcode}
\end{document}

答案1

正如评论中所述,并且因此这有一个答案:可以在任何可以通过求解线性方程来唯一地为其分配值的地方whatever使用。您收到错误,因为无法根据给定的信息唯一地确定。例如,这里有两个可能的位置:metapostMM

在此处输入图片描述

必须同时指定NP才能唯一确定M(请注意,仅指定一个仍然不够)。在这种情况下,metapost能够找到其位置(参见末尾的代码)。关于您的评论:

M 是对角线 [BD] 上的一个点。点 N 和 P 使得 APMN 是一个矩形。线 (CM) 和 (PN) 垂直。我尝试这个 N = whatever[a,d]; P = whatever[a,b]; M = whatever[b,d]; (M - N) dotprod (a -d)=0; (M - P) dotprod (a -b)=0;

如果我没看错您的评论,那么对于每个选择,线 CM 和 PN 都是正交/垂直的M(请注意,下面的阴影三角形是相似的)。因此,标准没有唯一指定M,也metapost无法为其分配位置。 在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}

path carre, p;
carre = unitsquare scaled 138;

pair a, b, c, d, N, P, M, Q;
a = point 0 of carre;
b = point 1 of carre;
c = point 2 of carre;
d = point 3 of carre;

beginfig(1);
% fix N
N=.07[a,d]; 
% fix P
P=.3[a,b];


p = b -- d;
% M is a point on the line through b and d
M = whatever[b,d];
% such that the line through M and c is orthogonal 
% to the line through P and N.  Since this point is unique
% (and the constraints are linear) metapost can find it.
(M - c) dotprod (P - N) = 0;

% to extend the line through M and c to intersect with the
% line through N and P: find the point Q that is both on 
% the line through M and c and on the line through N and P.
% This point is unique so metapost can find it.
Q=whatever[M,c]=whatever[N,P];
draw N--P dashed evenly;
draw M -- c;
dotlabel.rt("$M$",M);
draw M--Q dashed evenly;
draw P--Q dashed evenly;
draw unitsquare scaled 5 rotated angle(c-M) shifted Q;


draw p  withcolor blue;
draw carre withcolor red;

label.lft("$A$", point 0 of carre);
label.lrt("$B$", point 1 of carre);
label.urt("$C$", point 2 of carre);
label.ulft("$D$", point 3 of carre);
dotlabel.bot("$P$",P);
dotlabel.urt("$N$",N);
endfig;

% regarding comment
beginfig(2);
M := .6[b,d];
N := (0,ypart M);
P := (xpart M,0);

Q:=whatever[c,M]=whatever[N,P];
fill M--Q--N--cycle withcolor .8;
fill a--N--P--cycle withcolor .9;
fill M--(xpart b, ypart M)--c--cycle withcolor .95;
draw M--N;
draw M--P;
draw N--P dashed evenly;

draw c--M--Q;
draw unitsquare scaled 5;

draw p  withcolor blue;
draw carre withcolor red;

label.lft("$A$", point 0 of carre);
label.lrt("$B$", point 1 of carre);
label.urt("$C$", point 2 of carre);
label.ulft("$D$", point 3 of carre);
label.lft("N",N);
label.bot("P",P);
label.top("M",M);
label.bot("Q",Q);
endfig;
\end{mplibcode}
\end{document}

相关内容