Difference between revisions of "Asymptote: Useful functions"

(Added another example)
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{Asymptote}}
 
{{Asymptote}}
  
{{stub}}
 
  
 
== Intersection points ==
 
== Intersection points ==
function <b>intersectionpoints</b>( path, path)
+
pair[] <b>intersectionpoints</b>(path, path);
{
 
returns pair[]
 
}
 
  
Example:  
+
Examples:  
 
<pre><nowiki>size(8cm,0);
 
<pre><nowiki>size(8cm,0);
 
import math;
 
import math;
Line 46: Line 42:
 
draw(x[0] -- x[1],1bp+red);</asy>
 
draw(x[0] -- x[1],1bp+red);</asy>
  
== Stub stuff ==
+
<pre><nowiki>
 +
path g=(-3,-sqrt(3))--(3,-sqrt(3))--(0,2*sqrt(3))--cycle;
 +
draw(g,black);
 +
path p=-2/3*(-3,-sqrt(3))--(-2/3)*(3,-sqrt(3))--(-2/3)*(0,2*sqrt(3))--cycle;
 +
draw(p,black);
 +
pair [] x=intersectionpoints(g, p);
 +
fill(x[0]--x[1]--x[2]--x[3]--x[4]--x[5]--cycle,black);
 +
dot((0,0),white);
 +
</nowiki></pre>
 +
<asy>
 +
path g=(-3,-sqrt(3))--(3,-sqrt(3))--(0,2*sqrt(3))--cycle;
 +
draw(g,black);
 +
path p=-2/3*(-3,-sqrt(3))--(-2/3)*(3,-sqrt(3))--(-2/3)*(0,2*sqrt(3))--cycle;
 +
draw(p,black);
 +
pair [] x=intersectionpoints(g, p);
 +
fill(x[0]--x[1]--x[2]--x[3]--x[4]--x[5]--cycle,black);
 +
dot((0,0),white);
 +
</asy>
 +
Note that this function will cause an error if the paths involved do not intersect.
 +
 
 +
<!--
 
Can someone put a table of contents, and hiding widgets?  
 
Can someone put a table of contents, and hiding widgets?  
 
This page should comprised the most used functions in Asymptote for regular drawings.
 
This page should comprised the most used functions in Asymptote for regular drawings.
 +
-->
  
 +
[[Asymptote: CSE5|Next: CSE5]]
 
[[Category: Asymptote]]
 
[[Category: Asymptote]]

Revision as of 13:46, 26 November 2011

Asymptote (Vector Graphics Language)
Getting Started - Basics - Drawing - Labeling - Filling - Useful functions - Examples - Macros and Packages

Help - Reference - Advanced Asymptote - 3D Graphics - CSE5 Package - How to


Intersection points

pair[] intersectionpoints(path, path);

Examples:

size(8cm,0);
import math;
import graph;
real r,s;
pair a,b, common;
path circ1, circ2;
r=1; s=1;
a=(0,0);
b=(1,0);
circ1=circle(a,r);
circ2=circle(b,s);
draw(circ1,linewidth(1bp));
draw(circ2,1bp+green);
pair [] x=intersectionpoints(circ1, circ2);
dot(x[0],3bp+blue);
dot(x[1],3bp+blue);
draw(x[0] -- x[1],1bp+red);

[asy]size(200,200); import math; import graph; real r,s; pair a,b, common; path circ1, circ2; r=1; s=1; a=(0,0); b=(1,0); circ1=circle(a,r); circ2=circle(b,s); draw(circ1,linewidth(1bp)); draw(circ2,1bp+green); pair [] x=intersectionpoints(circ1, circ2); dot(x[0],3bp+blue); dot(x[1],3bp+blue); draw(x[0] -- x[1],1bp+red);[/asy]

path g=(-3,-sqrt(3))--(3,-sqrt(3))--(0,2*sqrt(3))--cycle;
draw(g,black);
path p=-2/3*(-3,-sqrt(3))--(-2/3)*(3,-sqrt(3))--(-2/3)*(0,2*sqrt(3))--cycle;
draw(p,black);
pair [] x=intersectionpoints(g, p);
fill(x[0]--x[1]--x[2]--x[3]--x[4]--x[5]--cycle,black);
dot((0,0),white);

[asy] path g=(-3,-sqrt(3))--(3,-sqrt(3))--(0,2*sqrt(3))--cycle; draw(g,black); path p=-2/3*(-3,-sqrt(3))--(-2/3)*(3,-sqrt(3))--(-2/3)*(0,2*sqrt(3))--cycle; draw(p,black); pair [] x=intersectionpoints(g, p); fill(x[0]--x[1]--x[2]--x[3]--x[4]--x[5]--cycle,black); dot((0,0),white); [/asy] Note that this function will cause an error if the paths involved do not intersect.


Next: CSE5