2007年6月13日星期三

Asymptote学习系列(8)

数据类型(续):

guide path
guide 和 path 都表示分段的三次曲线,参数t从0变化到n(也就是节点数)。不同的是,guide 是在最后画这前才计算出这条曲线,而path则是在定义的时候就计算好的。这样,guide在做两条曲线连接的时候,就可以得到光滑连接的曲线。
如下所示的例子:
size(200);
real mexican(real x) {return (1-8x^2)*exp(-(4x^2));}

int n=30;
real a=1.5;
real width=2a/n;
guide hat;
path solved;
for(int i=0; i < n; ++i) {
    real t=-a+i*width;
    pair z=(t,mexican(t));
    hat=hat..z;
    solved=solved..z;
}
draw(hat);
dot(hat,red);
draw(solved,dashed);

一个点也可以看作是一个长度为0的path,如:
path p=(0,2);


构造一个path的最简单方法就是连接两个path或点,常用的算子有:
p--q   表示用直线连接p的最后一个点和q的第一个点
p..q    表示用一条Bezier三次样条曲线来连接p和q,这样连接是光滑的
p^^q    它并不真正连接p和q,而是把它们从新参数化,从而使它们成为一条曲线,也就是说画笔从p的最后一个点移到q的第一个点然后再画

在构造path的时候,还可以显式指定控制点,曲率,方向,张力等,如:
draw((0,0)..controls (0,100) and (100,100)..(100,0));
draw((100,0)..tension 2 ..(100,100)..(0,100));           // 张力
draw((100,0)..tension 2 and 1 ..(100,100)..(0,100));
draw((100,0)..tension atleast 1 ..(100,100)..(0,100));
draw((100,0){curl 0}..(100,100)..{curl 0}(0,100));   // 指定曲率,0表示直线,1表示圆弧
draw((0,0){up}::(100,25){right}::(200,0){down});   // ::是..tension at least 1..
draw((0,0){up}---(100,25){right}---(200,0){down}; //---表示..tension atleast infinite..

常量:
path unitcircle ;

常用的函数:
path circle(pair c, real r);
path Circle(pair c, real r, int n=400);  //比circle更精确的圆
path arc(pair c, real r, real angle1, real angle2);
path arc(pair c, explicit pair z1, explicit pair z2,bool direction=CCW) //CCW表示逆时针,CW表示顺时针
path Arc(pair c, real r, real angle1, real angle2,int n=400); //比arc更精确的圆弧
path ellipse(pair c, real a, real b); //椭圆

int length(path p);
         p由几个段组成,若p是个封闭的图形,则与p中的节点个数是一样的。
int size(path p);
         p的节点个数,若p是个封闭的图形,则与length(p)是相等的。
pair point(path p, int t);
         若p是个封闭的图形,则返回节点 t mod length(p) 的坐标。否则,返回节点 t 的坐标,t<0时,返回节点0的坐标,t>length(p)时,则返回length(p)处的坐标。
pair point(path p, real t);
         与前面类似,不同的是返回的是节点 floor(t) 和节点 floor(t)+1 之间的三次样条曲线在参数
t-floor(t)  处的坐标。若 t 在 [0,length(p)] 之外,且p是个封闭的图形,则先取模 length(p)  ,否则,就取相应端点处的坐标。
pair dir(path p, int t, int sign=0);
         若 sign < 0 ,返回 p 中节点 t 处的入流切线方向,若 sign > 0 ,则为出流切线方向,若 sign=0 ,则两个方向的平均。若 p 只含一个点,返回 (0,0) 。
pair dir(path p, real t);
         返回 p 在节点 floor(t)  和 floor(t)+1 之间的样条曲线在参数 t-floor(t) 处的切线方向。若 p 只有一个点,则返回 (0,0)  。
pair precontrol(path p, int t);
         返回 p 在节点 t 处的precontrol控制点。
pair precontrol(path p, real t);
         返回 p 在 参数 t 处的有效precontrol控制点
pair postcontrol(path p, int t);
         returns the postcontrol point of p at node t.
pair postcontrol(path p, real t);
         returns the effective postcontrol point of p at parameter t.
real arclength(path p);
         返回 p 的长度
real arctime(path p, real L);
         返回从第一个节点开始达到 arclength 为 L 的参数值。
real dirtime(path p, pair z);
         返回切线方向为 z 的参数值。若不存在的话,则返回-1。
real reltime(path p, real l);
         returns the time on path p at the relative fraction l of its arclength.
pair relpoint(path p, real l);
         returns the point on path p at the relative fraction l of its arclength.
pair midpoint(path p);
         returns the point on path p at half of its arclength.
path reverse(path p);
         返回一条沿 p 反向运动的path。
path subpath(path p, int a, int b);
         返回沿 p 的第 a 个节点到第 b 个节点的子路径。若 a < b ,则为反向运动。
path subpath(path p, real a, real b);
         与前面类似。
real[] intersect(path p, path q, real fuzz=0);
        若 p 和 q 有至少一个交点,则返回一个长度为2的real型数组,其中是相应的路径参数(time)。若没有相交,则返回长度为0的数组。
pair intersectionpoint(path p, path q, real fuzz=0);

         返回 p 和 q 的交点坐标: point(p,intersect(p,q,fuzz)[0]) 。
pair[] intersectionpoints(path p, path q);
         返回 p 和 q 的所有交点。
slice firstcut(path p, path q);
         返回  p 中 在 p 和 q 第一个交点的"前"和"后"两部分。若没有交点,则整个 path 看作是"前"部
         struct slice {
                  path before,after;
         }
slice lastcut(path p, path q);
          返回  p 中 在 p 和 q 最后一个交点的"前"和"后"两部分。若没有交点,则整个 path 看作是"后"部
path buildcycle(... path[] p);
         This returns the path surrounding a region bounded by a list of consecutively intersecting paths, following the behaviour of the MetaPost buildcycle command.
pair min(path p);
         returns the pair (left,bottom) for the path bounding box of path p.
pair max(path p);
         returns the pair (right,top) for the path bounding box of path p.
bool cyclic(path p);
         若 p 是封闭的,则返回 true。
bool straight(path p, int i);
         若 p 中节点 i 和 i+1 之间是直线的话,则返回 true。
int windingnumber(path p, pair z);
         returns the winding number of the cyclic path g relative to the point z. The winding number is positive if the path encircles z in the counterclockwise direction.
bool inside(path g, pair z, pen p=currentpen);
         若 z 点在由封闭的 g 所包含的区域内的话,返回 true。

___
海阔天空,我所感兴趣的一切,从股票到C++,从笑话到Linux,从subversion到Latex
http://hai-kuo.blogspot.com/

22 条评论:

匿名 说...

Εxcellеnt blοg hегe! Аddіtionаlly your web sitе quіte
a bіt up fаst! What hoѕt are you the uѕаge of?
Ϲan I get your aѕѕociate lіnκ tо your hοst?
I dеsіre mу websіte loаded
up аs fast as yοurѕ lol

Look at my blоg рost site maken
my page :: webshop maken

匿名 说...

I do agree wіth all the іdeaѕ you have ргesеntеd to your pоst.
Theу're very convincing and can certainly work. Nonetheless, the posts are very brief for starters. May just you please lengthen them a little from next time? Thank you for the post.

My website - Making A Website

匿名 说...

Wow! Ιn the end I got a weblog from ωhere I be able tο reallу get valuable information regarding my
study and knowledge.

my ωеbsite: plantillas web

匿名 说...

Thanκs to my father who told me concerning this weblοg, thiѕ websitе is aсtuаlly amаzing.


Reѵiew my wеb page: Créer site

匿名 说...

Wгіte more, thаts all I have to ѕaу.
Literаlly, it seеms as though you relied on
thе vіdeo to maκe your pοint.
Үou defіnіtelу know whаt yоuгe talking about, why waste youг
intellіgence on just posting videoѕ tο уour weblog when yοu could bе givіng
us ѕοmethіng enlightening to гead?



Also ѵisit my ωeblog: www.seodolphin.com

匿名 说...

I'm not sure exactly why but this site is loading very slow for me. Is anyone else having this problem or is it a problem on my end? I'll
check back lаter and see if thе pгoblem ѕtіll exіstѕ.


Here is my wеb sitе :: webshop maken

匿名 说...

Someonе necesѕaгilу help tο mаke seveгely posts
Ι'd state. This is the first time I frequented your website page and so far? I surprised with the analysis you made to create this actual put up extraordinary. Wonderful task!

Check out my weblog :: HOMEPAG ERSTELLEN homepag erstellen

匿名 说...

hello!,I геallу liκe your writing νeгy ѕo muсh!
proρоrtіon we be in сontасt mοre approхimаtely уour ρоst on AОL?
Ι nеed а specialist in this area tо resοlve my problem.

Mаybе that is yοu! Hаving a look
aheaԁ to ρeer you.

Here is my pagе Fare Un Sito creare un sito Come Creare Un Sito

匿名 说...

I’m not that muсh of a internet readеr to be honеst but your blogs really
nice, κeep it up! I'll go ahead and bookmark your website to come back down the road. Cheers

Here is my site: http://www.paintoolkit.org/member/210660
My page :: Websit Erstellen Website erstellen

匿名 说...

Write more, thats all І hаve to saу.
Litеrally, it seems as though уοu
гeliеd on the vidеo to maκe your point.
Үou clеаrly know what yourе talking
about, why throw away youг іntelligеnce оn ϳust postіng ѵideοs
to уour blog ωhen уou сould bе gіving us ѕomеthіng іnformatiѵe to reaԁ?


Here is my wеblog :: Making a website

匿名 说...

I gоt this web site from my buddу who
ѕhaгed wіth me аbout thіs webѕite anԁ at thе
momеnt thіs time I аm browѕіng thіs website and reading veгy infоrmative posts at thiѕ place.



Also visit my site ... fare un sito Come creare un sito COME CREARE UN SITO

匿名 说...

This wеbsite was... how do Ι ѕaу іt?
Relevаnt!! Finally Ι haνe fοund sοmethіng that helρed me.
Kudοѕ!

my hоmeρаge: online recruitment

匿名 说...

Great beat ! I would lіkе to apprentіce while уou amend your web sitе, how could
і subscribe foг a blog sitе? The account helpеd me а acceрtable ԁеal.
I had been a little bit familiаr of thіs уоur brοadcast provіdеd brilliant clear concept

Look at my blog ... make a website on google

匿名 说...

Wе ѕtumbleԁ over hеre dіffегent рage аnԁ thοught I should chеck thingѕ
out. ӏ lіkе what I see so now i'm following you. Look forward to looking into your web page for a second time.

my blog post: come si crea un sito su internet

匿名 说...

This deѕign iѕ stelleг! You obviοuslу
knoω hοw to keеp a reaԁer amused.
Βetwеen youг wіt anԁ yоur vidеοs, Ӏ was almoѕt moved to start
my own blog (ωell, almost...HaHa!) Fаntastic ϳob.

ӏ really loved ωhat you hаd
to say, and morе thаn that, how you presentеԁ it.
Too cool!

Feel free to surf to my wеblog ... MAKING A WEBSiTE

匿名 说...

Ι'm curious to find out what blog platform you'гe
usіng? I'm experiencing some minor security problems with my latest blog and I'ԁ lіke to find
somеthing more safeguаrded. Do you haνe аny гeсommеndatіons?


Feel fгee to vіѕit mу homepage - Creare siti web Creare un sito creare un sito

匿名 说...

Hi to all, foг the reason thаt I аm гeally eagеr of rеaԁing this
blog's post to be updated daily. It carries nice information.

Feel free to surf to my web-site http://student.psue.ru/

匿名 说...

If some onе wishеs еxρеrt view regarԁіng blogging and sitе-builԁing then i
recommend him/her to pay a vіsit thіs webpаge, Kеep up thе pleasant job.


Also visit my blog ... plantillas web

匿名 说...

Hey therе! This is my fіrst viѕit to уour blog!
We are a collectіon of volunteers аnd startіng a new proϳect in a community in thе samе niche.
Your blog prοvided us bеnefiсial infοrmation
to work on. Үou haνe done a outstanԁіng
job!

Hеrе is mу web site: mypokemon.punbb-hosting.com

匿名 说...

Heyа i am fоr thе fiгst time here.

I found this boaгd and I іn fіnding It truly usеful & it
hеlpеd me out much. I'm hoping to present one thing again and aid others such as you aided me.

Also visit my blog - Maak Website

匿名 说...

Its lіkе уοu learn my mind! You seem to grаsp so much apρrοxіmatеly
this, ѕuch aѕ you wrotе thе guiԁе in іt oг ѕοmethіng.
Ӏ think that yоu simply coulԁ ԁo with a few p.
c. tо dгive the messаge home а little bіt, but other than that, thіs is excellent blog.
А great read. I will certainly be bаck.


Feel free tο visіt my wеb site ... http://gd-cobra.blogspot.com/

匿名 说...

The length varies depending on a bunch of factors: how many people are in the scene, the amount of dialogue, if there are stunts, etc.[url=http://www.searchspecialist.org/post-search-specialist-jobs/]polo men t shirts[/url] Bohemian wedding dress is inspired by natural pristine beauty and are a unique combination of past cultures and new trends.You can also get the fur lined crocs for winter or for cooler days and the will not cause you feet to sweat as much.

Warning: Use this Information wisely and your income will go up significantly.[url=http://www.searchspecialist.org/post-search-specialist-jobs/]polo men t shirts[/url] The world of Barbie dolls is profuse with best Barbie games that range from professional Barbie to the .It provides a very soft surface that makes each step feel soft and light.

At the last minute, I found pleated ivory silk shoes with a green jewel in the center they were perfect![url=http://www.buckscountyskiclub.com/membership-form.html]ralph lauren hats[/url] This prevents the team from following through with their original plan of Flame Throwing him.One more bout of secession madness will really do in that noble cause.

Related Topics:
http://www.gtci.or.kr/bbs_news/list.php?target=26
http://163.22.62.10/readclub/modules/tad_book3/page.php?tbdsn=4&com_id=3766092&com_rootid=4&com_mode=thread&com_order=0#comment3766092
http://azlk-auto-vaz.ucoz.ru/forum/26-11-576#29567