如何用 Asymptote 绘制旋转门?

如何用 Asymptote 绘制旋转门?

在此处输入图片描述

以下是我用 Ti 创建的旋转门图像的代码示例Z. 我怎样才能将此代码转换为渐近线的代码?

\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage[top=1.5cm, bottom=1.5cm, left=1.5cm, right=1.5cm]{geometry}

\usetikzlibrary{intersections,shadings,calc}
\begin{document}
\begin{center}
\begin{tikzpicture}[line cap=round, line join=round,x=2mm,y=2mm]
\tikzset{
CungElip/.style args={#1:#2:#3}{
insert path={+ (#1:#3) arc (#1:#2:#3)}
}
}
\definecolor{nauden}{RGB}{52,32,0}
\definecolor{vangxam}{RGB}{190,155,100}
\fill[cyan!30] (-9,-2)rectangle(9,16);
\clip (8,0) arc (0:-180:16mm and 3.2mm) -- (-8,14) arc (180:0:16mm and 3.2mm) --cycle;
\shade[bottom color=vangxam!50!white,top color=vangxam!50!black] (0,0) [CungElip=0:360:16mm and 3.2mm];
\shade[yshift=23.2mm,bottom color=black,top color=gray!70] (0,0) [CungElip=0:360:16mm and 3.2mm];
\begin{scope}[even odd rule, overlay]
\clip (8,11.6) arc (0:-50:16mm and 3.2mm)--++(0,-9.2) arc (50:0:16mm and 3.2mm)--cycle
($(8,11.6)+(0,-0.5)$) arc (3:-47:16mm and 3.2mm)--++($(0,-9.2)+(0,1)$) arc (47:-3:16mm and 3.2mm)--cycle;
\fill[gray!80] (8,11.6) arc (0:-60:16mm and 3.2mm)--++(0,-9.2) arc (60:0:16mm and 3.2mm)--cycle;
\end{scope}
\begin{scope}[even odd rule, overlay]
\clip (-8,11.6) arc (-180:-130:16mm and 3.2mm)--++(0,-9.2) arc (130:180:16mm and 3.2mm)--cycle
($(-8,11.6)+(0,-0.5)$) arc (-177:-133:16mm and 3.2mm)--++($(0,-9.2)+(0,1)$) arc (133:177:16mm and 3.2mm)--cycle;
\fill[gray!80] (-8,11.6) arc (-180:-130:16mm and 3.2mm)--++(0,-9.2) arc (130:180:16mm and 3.2mm)--cycle;
\end{scope}
\fill[gray!50,opacity=0.3] ($(8,11.6)+(0,-0.5)$) arc (3:32:16mm and 3.2mm)--++($(0,-13.5)+(0,1.5)$) arc (-32:-3:16mm and 3.2mm)--cycle;
\fill[gray!50,opacity=0.3] ($(-8,11.6)+(0,-0.5)$) arc (177:148:16mm and 3.2mm)--++($(0,-13.5)+(0,1.5)$) arc (-148:-177:16mm and 3.2mm)--cycle;
\draw[gray!50,line width=1pt] (8,11.6) arc (0:35:16mm and 3.2mm)--++(0,-13.5) arc (-35:0:16mm and 3.2mm)--cycle;
\draw[gray!50,line width=1pt] (-8,11.6) arc (180:145:16mm and 3.2mm)--++(0,-13.5) arc (-145:-180:16mm and 3.2mm)--cycle;
\begin{scope}[even odd rule, overlay]
\clip (8,11.6) arc (0:35:16mm and 3.2mm)--++(0,-13.5) arc (-35:0:16mm and 3.2mm)--cycle
($(8,11.6)+(0,-0.5)$) arc (3:32:16mm and 3.2mm)--++($(0,-13.5)+(0,1.5)$) arc (-32:-3:16mm and 3.2mm)--cycle;
\fill[gray!50] (8,11.6) arc (0:35:16mm and 3.2mm)--++(0,-13.5) arc (-35:0:16mm and 3.2mm)--cycle;
\end{scope}
\begin{scope}[even odd rule, overlay]
\clip (-8,11.6) arc (180:145:16mm and 3.2mm)--++(0,-13.5) arc (-145:-180:16mm and 3.2mm)--cycle
($(-8,11.6)+(0,-0.5)$) arc (177:148:16mm and 3.2mm)--++($(0,-13.5)+(0,1.5)$) arc (-148:-177:16mm and 3.2mm)--cycle;
\fill[gray!50] (-8,11.6) arc (180:145:16mm and 3.2mm)--++(0,-13.5) arc (-145:-180:16mm and 3.2mm)--cycle;
\end{scope}
\begin{scope}[overlay]
\clip (8,11.6) arc (0:180:16mm and 3.2mm)--++(0,2.4) arc (180:0:16mm and 3.2mm)--++(0,-2.4)--cycle;
\shade[left color=white, right color=gray] (0,11)rectangle(8,17);
\shade[left color=gray, right color=white] (-8,11)rectangle(0,17);
\end{scope}
\coordinate (B) at ($(0,0)+(50:16mm and 3.2mm)$);
\coordinate (A) at ($(0,0)+(215:16mm and 3.2mm)$);
\coordinate (C) at ($(0,0)+(130:16mm and 3.2mm)$);
\coordinate (D) at ($(0,0)+(-35:16mm and 3.2mm)$);
\coordinate[yshift=23.2mm] (D1) at ($(0,0)+(35:16mm and 3.2mm)$);
\coordinate[yshift=23.2mm] (C1) at ($(0,0)+(-130:16mm and 3.2mm)$);
\coordinate[yshift=23.2mm] (B1) at ($(0,0)+(-50:16mm and 3.2mm)$);
\coordinate[yshift=23.2mm] (A1) at ($(0,0)+(-215:16mm and 3.2mm)$);
\path[name path=ab] (A)--(B); 
\path[name path=cd] (C)--(D);
\path[name path=a1b1] (A1)--(B1); 
\path[name path=c1d1] (C1)--(D1);
\path[name intersections={of=ab and cd,by=M}];
\path[name intersections={of=a1b1 and c1d1,by=N}];
\begin{scope}[even odd rule, overlay]
\clip (B)--(M)--(N)--(B1)--cycle ($(B)+(-.3,.6)$)--($(M)+(.3,.7)$)--($(N)+(.3,-.7)$)--($(B1)+(-.3,-.6)$)--cycle;
\fill[white] (B)--(M)--(N)--(B1)--cycle;
\end{scope}
\begin{scope}[even odd rule, overlay]
\clip (C)--(M)--(N)--(C1)--cycle ($(C)+(.3,.6)$)--($(M)+(-.3,.7)$)--($(N)+(-.3,-.7)$)--($(C1)+(.3,-.6)$)--cycle;
\fill[white] (C)--(M)--(N)--(C1)--cycle;
\end{scope}
\fill[gray!50,opacity=0.3] (C)--(M)--(N)--(C1)--cycle ($(C)+(.3,.6)$)--($(M)+(-.3,.7)$)--($(N)+(-.3,-.7)$)--($(C1)+(.3,-.6)$)--cycle;
\fill[gray!50,opacity=0.3] (B)--(M)--(N)--(B1)--cycle ($(B)+(-.3,.6)$)--($(M)+(.3,.7)$)--($(N)+(.3,-.7)$)--($(B1)+(-.3,-.6)$)--cycle;

\draw[line width=.4pt,nauden] ($(B)+(-.3,.6)$)--($(M)+(.3,.7)$)--($(N)+(.3,-.7)$)--($(B1)+(-.3,-.6)$)--cycle;
\draw[line width=.4pt,nauden] ($(C)+(.3,.6)$)--($(M)+(-.3,.7)$)--($(N)+(-.3,-.7)$)--($(C1)+(.3,-.6)$)--cycle;
\draw[line width=1.2pt,nauden] (M)--(B)--(B1)--(N) (M)--(C)--(C1)--(N);
\begin{scope}[even odd rule, overlay]
\clip (D)--(M)--(N)--(D1)--cycle ($(D)+(-.45,.8)$)--($(M)+(.3,.7)$)--($(N)+(.3,-.7)$)--($(D1)+(-.45,-.8)$)--cycle;
\fill[white] (D)--(M)--(N)--(D1)--cycle;
\end{scope}

\begin{scope}[even odd rule, overlay]
\clip (A)--(M)--(N)--(A1)--cycle ($(A)+(.45,.8)$)--($(M)+(-.3,.7)$)--($(N)+(-.3,-.7)$)--($(A1)+(.45,-.8)$)--cycle;
\fill[white] (A)--(M)--(N)--(A1)--cycle;
\end{scope}
\fill[gray!50,opacity=0.3] ($(D)+(-.45,.8)$)--($(M)+(.3,.7)$)--($(N)+(.3,-.7)$)--($(D1)+(-.45,-.8)$)--cycle;
\fill[gray!50,opacity=0.3] ($(A)+(.45,.8)$)--($(M)+(-.3,.7)$)--($(N)+(-.3,-.7)$)--($(A1)+(.45,-.8)$)--cycle;
\draw[line width=.4pt,nauden] ($(D)+(-.45,.8)$)--($(M)+(.3,.7)$)--($(N)+(.3,-.7)$)--($(D1)+(-.45,-.8)$)--cycle;
\draw[line width=.4pt,nauden] ($(A)+(.45,.8)$)--($(M)+(-.3,.7)$)--($(N)+(-.3,-.7)$)--($(A1)+(.45,-.8)$)--cycle;
\draw[line width=1.2pt,nauden] (M)--($(A)+(.2,0)$)--($(A1)+(.2,0)$)--(N)--cycle (M)--($(D)+(-.2,0)$)--($(D1)+(-.2,0)$)--(N);
\draw[line width=1pt,gray,rounded corners=1.2pt] ($(M)!.45!(N)+(-.1,-.2)$)--($(C)!.45!(C1)+(.2,-.2)$)--++(120:.05mm) ($(M)!.45!(N)+(.1,-.2)$)--($(B)!.45!(B1)+(-.2,-.2)$)--++(60:.05mm);
\draw[line width=1pt,gray!60,rounded corners=1.2pt] ($(M)!.45!(N)+(-.1,-.2)$)--($(A)!.45!(A1)+(.5,-.2)$)--++(120:.2mm) ($(M)!.45!(N)+(.1,-.2)$)--($(D)!.45!(D1)+(-.5,-.2)$)--++(60:.2mm);
\fill[gray!50] (0,12.5) ellipse (.3mm and .15 mm);
\fill[white] (0,12.5) ellipse (.15mm and .075 mm);
\fill[black!50] (-.3,14.2)--(.3,14.2)--(.4,14.6)--(-.4,14.6)--cycle ;
\fill[red!50!gray] (0,14.4) circle (.3pt);
\draw[gray!30,line width=1pt] (6.5,-1.2)--(6.5,15.5) (-6.5,-1.2)--(-6.5,15.5);
\end{tikzpicture}
\end{center}
\end{document}

答案1

首先恭喜你的照片,也祝贺你的自行车。这里有一个可以作为起点的渐近线代码。显然,我的才华远不如您,但我很乐意为您提供更多功能。请注意,使用pdflatex -shell-escape或类似的东西来编译它可能是最简单的,因为这样会自动调用渐近线。更新:事实证明,在渐近线中填充表面时,边界的方向很重要,请参阅第 78 页本教程。这解释了我之前的图中奇怪的对角线。在这次更新中,我修复了这个问题,并且还把门弄宽了一点。

\documentclass[border=5pt]{standalone}
\usepackage{asypictureB}
\def\myangle{45}
\begin{document}
\begin{asypicture}{name=AsyDoor}
import graph3;
import solids;

size(8cm,8cm);
settings.render = 4;
currentprojection = perspective((-3,20,1), up=Z,autoadjust=true);//,autoadjust=true
currentlight=(2,15,5);
int doorangle = 135;

real Rad=2; // that's not the "true" radius but some parameter controlling the width

picture fig;
size(fig,10cm);
// coordinate axes 
//draw(O -- 2X,L=Label("$x$",position=EndPoint));
//draw(O -- 2Y,L=Label("$y$", position=EndPoint));
//draw(-2Z -- 2Z,L=Label("$z$", position=EndPoint));
//
path3 uppercircle = circle(c=2Z, r=Rad*1.1*sqrt(2), normal=Z);
surface uppercylinder = extrude(uppercircle, 0.4Z);
draw(uppercylinder, surfacepen=blue);
//
path3 lowercircle = circle(c=-2Z, r=Rad*1.1*sqrt(2), normal=Z);
surface lowercylinder = extrude(lowercircle, 0.1Z);
draw(lowercylinder, surfacepen=blue);
//
path3 doorboundary =  Rad*sqrt(2)*X+2Z -- Rad*sqrt(2)*X-1.9*Z -- -1.9*Z -- 2*Z -- cycle;
surface door = surface(doorboundary);
//
material glassdoor = material(lightblue+opacity(0.3));
//
for (int ang=doorangle; ang<=doorangle+90;ang+=90)
{
draw(rotate(ang,Z)*door, glassdoor);
draw(rotate(ang,Z)*shift(-Rad*sqrt(2)*X)*door, glassdoor);
draw(rotate(ang,Z)*scale3(0.97)*doorboundary, p=lightgray+linewidth(3pt));
draw(rotate(ang,Z)*shift(-Rad*sqrt(2)*X)*scale3(0.97)*doorboundary, p=lightgray+linewidth(3pt));
draw(rotate(ang-90,Z)* (0.97*Rad*sqrt(2)*X-0.2*Z .. 
0.87*Rad*sqrt(2)*X-0.2*Z -0.1*Rad*sqrt(2)*Y 
-- 0.1*Rad*sqrt(2)*X-0.2*Z -0.1*Rad*sqrt(2)*Y .. 
-0.2*Z), p=lightgray+linewidth(5pt));
draw(rotate(ang+90,Z)* (0.97*Rad*sqrt(2)*X-0.2*Z .. 
0.87*Rad*sqrt(2)*X-0.2*Z -0.1*Rad*sqrt(2)*Y 
-- 0.1*Rad*sqrt(2)*X-0.2*Z -0.1*Rad*sqrt(2)*Y .. 
-0.2*Z), p=lightgray+linewidth(5pt));
}

//

// SURFACES
// left and right boundaries
triple S1(pair uv) {
  real x = 1.05*Rad*sqrt(2)*cos(uv.x);
  real y = 1.05*Rad*sqrt(2)*sin(uv.x);
  real z = uv.y;
  return (x, y, z);
}
// upper and lower
triple S2(pair uv) {
  real x = uv.y * 1.1* Rad*sqrt(2)*cos(uv.x);
  real y = uv.y * 1.1* Rad*sqrt(2)*sin(uv.x);
  real z =0;
  return (x, y, z);
}
//
for (int ang=135; ang<=315;ang+=180)
{
draw(rotate(ang,Z)*arc(c=1.95*Z, 1.05*Rad*sqrt(2)*X+1.95*Z, 1.05*Rad*sqrt(2)*Y+1.9*Z), p=gray+linewidth(4pt));
draw(rotate(ang,Z)*arc(c=-1.85*Z, 1.05*Rad*sqrt(2)*X-1.85*Z, 1.05*Rad*sqrt(2)*Y-1.85*Z), p=gray+linewidth(4pt));
draw(rotate(ang,Z)* (1.05*Rad*sqrt(2)*X+1.9*Z--1.05*Rad*sqrt(2)*X-1.85*Z), p=gray+linewidth(4pt));
draw(rotate(ang+90,Z)* (1.05*Rad*sqrt(2)*X+1.9*Z--1.05*Rad*sqrt(2)*X-1.85*Z), p=gray+linewidth(4pt));
}
//
surface leftboundary = surface(S1, (-pi/4, -2), (pi/4,2), 64, 64, Spline);
surface rightboundary = surface(S1, (pi-pi/4, -2), (pi+pi/4,2), 64, 64, Spline);
draw(leftboundary, surfacepen=material(diffusepen=gray(0.1)+opacity(0.5),emissivepen=gray(0.3),specularpen=gray(0.1)));
draw(rightboundary, surfacepen=material(diffusepen=gray(0.1)+opacity(0.5),emissivepen=gray(0.3),specularpen=gray(0.1)));
//
surface upperboundary = shift(2Z) *surface(S2, (0, 0), (2pi,1), 64, 64, Spline);
surface lowerboundary = shift(-1.9Z) *surface(S2, (0, 0), (2pi,1), 64, 64, Spline);
draw(upperboundary, surfacepen=material(diffusepen=gray(0.1),emissivepen=gray(0.3),specularpen=gray(0.1)));
draw(lowerboundary, surfacepen=material(diffusepen=yellow,emissivepen=gray(0.3),specularpen=gray(0.1)));
\end{asypicture}
\end{document}

在此处输入图片描述

这可以成为一扇真正的旋转门。

在此处输入图片描述

更新:我固定了门把手的长度(我希望如此),感谢 Charles Staats向我解释一些特点asypictureB 包。这些使我能够更方便地制作动画。(如果没有这个包,这个答案无论如何都不会存在。)讨论了制作动画的方法这里。(目前,我发现如果使用这条链,但很可能我做了一些愚蠢的事情。)

相关内容