8.2 Matematiikkafunktiot
Omat matematiikkafunktiot xy-koordinaatistossa
Aliohjelmia eli funktioita käyttämällä voidaan helposti luoda omia komentoja. Esitetään seuraavaksi matemaatikoille suunnatut komennot, joiden avulla voidaan havainnollistaa helposti matemaattisia ilmiöitä xy-koordinaatistossa. Matematiikkafunktioita käytetään PC-koneilla seuraavasti:
Tässä kappaleessa ei ole tuntitehtäviä. Tämän sivun matematiikka-funktioita on tarkoitus käydä rinnan oman oppikirjan kanssa silloin, kun asia käydään läpi kirjassa.
- Kopioi alla oleva koodi kokonaisuudessaan eli maalaa koko teksti hiirellä ja paina hiiren oikeaa painiketta ja valitse komento: Kopioi. Aukaise Processing-ohjelma ja ota komento: Liitä (Edit | Paste).
- Kirjoita komentoja vain void draw ()-lohkon sisälle. Alasivuilla on esimerkkejä komentojen käytöstä.
Tässä kappaleessa ei ole tuntitehtäviä. Tämän sivun matematiikka-funktioita on tarkoitus käydä rinnan oman oppikirjan kanssa silloin, kun asia käydään läpi kirjassa.
Jos käytät tablettia, koko koodi on liian raskas. Koodi löytyy myös osiin pilkottuna, eli kopioi tällöin vain se koodi, jota tarvitset. Käyttö toimii samalla tavalla.
Matematiikkafunktiot (koko kirjasto, sopii PC:lle)
// Ohjelman tehnyt e-Oppi Oy
// Viimeksi päivitetty: 11.3.2018
// Oletus täyttöväri
int R =250; // Oletus punainen
int G = 200; // Oletus vihreä
int B = 0; // Oletus sininen
int A = 100; // Oletus läpinäkyvyys
void setup () {
size(601,601); // Älä muuta ikkunan kokoa
}
// Kaikki komennot laitetaan void draw ()-lohkoon
void draw () {
koordinaatisto();
// Kirjoita tähän kaikki komennot
}
// Tästä alkaa funktiot eli aliohjelmat
// Älä tee näihin muutoksia !!
// Koordinaatisto on suunniteltu 600x600 ikkunaan
void koordinaatisto() {
fill(255);
noStroke();
rect(0,0,600,600);
stroke(128);
strokeWeight(1);
for (int z = 0; z < 21; z++) {
line(z*30,0,z*30,600);
line(0,0+z*30,600,z*30);
}
strokeWeight(3);
stroke(0,0,100);
line(300,3,300,600);
line(0,300,600,300);
fill(0,0,100);
triangle(590,290,598,300,590,310);
triangle(300,3,310,10,290,10);
text("x",580,285);
text("y",315,20);
textSize(20);
text("1",323,320);
text("1",280,280);
translate(300,300);
scale(1,-1);
strokeWeight(2); // Oletus paksuus
fill(R,G,B,A); // Oletusväri
stroke(0);
}
void suorakulmio(float x, float y, float leveys, float korkeus) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float leveys2 = map(leveys,-10,10,-300,300);
float korkeus2 = map(korkeus,-10,10,-300,300);
rect(x2,y2,leveys2,korkeus2);
}
void nelio(float x, float y, float sivu) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sivu2 = map(sivu,-10,10,-300,300);
rect(x2,y2,sivu2,sivu2);
}
void ympyra(float x, float y, float sade) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sade2 = map(sade,-10,10,-300,300);
ellipse(x2,y2,2*sade2,2*sade2);
point(x2,y2);
}
void ellipsi(float x, float y, float leveys, float korkeus) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float leveys2 = map(leveys,-10,10,-300,300);
float korkeus2 = map(korkeus,-10,10,-300,300);
ellipse(x2,y2,leveys2,korkeus2);
point(x2,y2);
}
void piste(float x, float y) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
strokeWeight(3);
// fill(255,0,0);
ellipse(x2,y2,10,10);
fill(R,G,B,A);
strokeWeight(2);
stroke(0);
}
void jana(float x1, float y1, float x2, float y2) {
float x12 = map(x1,-10,10,-300,300);
float y12 = map(y1,-10,10,-300,300);
float x22 = map(x2,-10,10,-300,300);
float y22 = map(y2,-10,10,-300,300);
strokeWeight(3);
// fill(255,0,0);
line(x12,y12,x22,y22);
ellipse(x12,y12,10,10);
ellipse(x22,y22,10,10);
fill(R,G,B,A);
strokeWeight(2);
stroke(0);
}
void keskipiste(float x1, float y1, float x2, float y2) {
float x12 = map(x1,-10,10,-300,300);
float y12 = map(y1,-10,10,-300,300);
float x22 = map(x2,-10,10,-300,300);
float y22 = map(y2,-10,10,-300,300);
float z1 = (x1+x2)/2;
float z2 = (y1+y2)/2;
strokeWeight(3);
// fill(255,0,0);
line(x12,y12,x22,y22);
ellipse(x12,y12,10,10);
ellipse(x22,y22,10,10);
fill(255,0,0);
ellipse(z1*30,z2*30,10,10);
fill(R,G,B,A);
strokeWeight(2);
stroke(0);
}
void normaali(float x1, float y1, float x2, float y2) {
float x12 = map(x1,-10,10,-300,300);
float y12 = map(y1,-10,10,-300,300);
float x22 = map(x2,-10,10,-300,300);
float y22 = map(y2,-10,10,-300,300);
strokeWeight(3);
// fill(255,0,0);
line(x12,y12,x22,y22);
float x0 = (x1+x2)/2;
float y0 = (y1+y2)/2;
float k = ((y22-y12)/(x22-x12));
if (y1 == y2) {
line(x0*30,300,x0*30,-300);
}
for (int s=-3000; s<3000; s++) {
float y = (-1/k)*(s/10.0)+((1/k)*x0+y0)*30;
ellipse((s/10.0),y,1,1);
}
ellipse(x12,y12,10,10);
ellipse(x22,y22,10,10);
fill(R,G,B,A);
strokeWeight(2);
stroke(0);
}
void sektori(float x, float y, float sade, float kulma1, float kulma2) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sade2 = map(sade,-10,10,-300,300);
if (kulma2 < kulma1) {
float muuta = kulma1;
kulma1 = kulma2;
kulma2 = muuta;
}
arc(x2,y2,2*sade2,2*sade2,radians(kulma1),radians(kulma2),PIE);
point(x2,y2);
}
void kaari(float x, float y, float sade, float kulma1, float kulma2) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sade2 = map(sade,-10,10,-300,300);
noFill();
if (kulma2 < kulma1) {
float muuta = kulma1;
kulma1 = kulma2;
kulma2 = muuta;
}
arc(x2,y2,2*sade2,2*sade2,radians(kulma1),radians(kulma2));
point(x2,y2);
fill(R,G,B,A); // Oletusväri
}
void janne(float x, float y, float sade, float kulma1, float kulma2) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sade2 = map(sade,-10,10,-300,300);
float rx1 = sade2*cos(radians(kulma1));
float ry1 = sade2*sin(radians(kulma1));
float rx2 = sade2*cos(radians(kulma2));
float ry2 = sade2*sin(radians(kulma2));
line(x2+rx1,y2+ry1,x2+rx2,y2+ry2);
point(x2,y2);
}
void segmentti(float x, float y, float sade, float kulma1, float kulma2) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sade2 = map(sade,-10,10,-300,300);
if (kulma2 < kulma1) {
float muuta = kulma1;
kulma1 = kulma2;
kulma2 = muuta;
}
arc(x2,y2,2*sade2,2*sade2,radians(kulma1),radians(kulma2),CHORD);
point(x2,y2);
}
void suunnikas(float x, float y, float sivu1, float sivu2, float kulma) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sivu12 = map(sivu1,-10,10,-300,300);
float sivu22 = map(sivu2,-10,10,-300,300);
quad(x2,y2, x2+sivu12,y2, x2+sivu12+sivu22*cos(radians(kulma)),y2+sivu22*sin(radians(kulma)), x2+sivu22*cos(radians(kulma)),y2+sivu22*sin(radians(kulma)) );
}
void puolisuunnikas(float x, float y, float a, float b, float h, float dx) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float a2 = map(a,-10,10,-300,300);
float b2 = map(b,-10,10,-300,300);
float h2 = map(h,-10,10,-300,300);
float dx2 = map(dx,-10,10,-300,300);
quad(x2,y2,x2+b2,y2,x2+a2+dx2,y2+h2,x2+dx2,y2+h2);
}
void kolmio(float x, float y, float sivu1, float sivu2, float kulma) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sivu12 = map(sivu1,-10,10,-300,300);
float sivu22 = map(sivu2,-10,10,-300,300);
triangle(x2,y2, x2+sivu12,y2, x2+sivu22*cos(radians(kulma)),y2+sivu22*sin(radians(kulma)) );
}
void kolmiokanta(float x1, float y1, float sivu, float kulma1, float kulma2) {
float x2 = map(x1,-10,10,-300,300);
float y2 = map(y1,-10,10,-300,300);
float sivu2 = map(sivu,-10,10,-300,300);
float a = (sin(radians(kulma2))*sivu)/sin(radians(180-(kulma1+kulma2)));
float x0 = x2+30*a*cos(radians(kulma1));
float y0 = y2+30*a*sin(radians(kulma1));
triangle(x2,y2,x2+sivu2,y2,x0,y0);
}
void nelikulmio(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
float x12 = map(x1,-10,10,-300,300);
float y12 = map(y1,-10,10,-300,300);
float x22 = map(x2,-10,10,-300,300);
float y22 = map(y2,-10,10,-300,300);
float x32 = map(x3,-10,10,-300,300);
float y32 = map(y3,-10,10,-300,300);
float x42 = map(x4,-10,10,-300,300);
float y42 = map(y4,-10,10,-300,300);
quad(x12,y12,x22,y22,x32,y32,x42,y42);
}
void kolmioXY(float x1, float y1, float x2, float y2, float x3, float y3) {
float x12 = map(x1,-10,10,-300,300);
float y12 = map(y1,-10,10,-300,300);
float x22 = map(x2,-10,10,-300,300);
float y22 = map(y2,-10,10,-300,300);
float x32 = map(x3,-10,10,-300,300);
float y32 = map(y3,-10,10,-300,300);
triangle(x12,y12,x22,y22,x32,y32);
}
void kulma(float x, float y, float sivu1, float sivu2, float kulma1, float kulma2) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sivu12 = map(sivu1,-10,10,-300,300);
float sivu22 = map(sivu2,-10,10,-300,300);
arc(x2,y2,30,30,radians(kulma1),radians(kulma1+kulma2),PIE);
line(x2,y2,x2+sivu12*cos(radians(kulma1)),y2+sivu12*sin(radians(kulma1)));
line(x2,y2,x2+sivu22*cos(radians(kulma1+kulma2)),y2+sivu22*sin(radians(kulma1+kulma2)));
}
void suora(float k, float b) {
float b2 = map(b,-10,10,-300,300);
for (int s=-3000; s<3000; s++) {
float y =k*(s/10.0)+b2;
ellipse((s/10.0),y,1,1);
}
}
void epayhtalo(float k, float b, String merkki, float arvo) {
float b2 = map(b,-10,10,-300,300);
for (int s=-3000; s<3000; s++) {
float y =k*(s/10.0)+b2;
ellipse((s/10.0),y,1,1);
}
float x = (arvo-b)/k;
strokeWeight(3);
if ((k == 0) && (merkki== ">")){
noStroke();
if (b > arvo) {
rect(-300,30*arvo,600,300-30*arvo);
}
}
if ((k == 0) && (merkki== "<")){
noStroke();
if (b < arvo) {
rect(-300,30*arvo,600,-300-30*arvo);
}
}
if ((k == 0) && (merkki== ">=")){
noStroke();
if (b >= arvo) {
rect(-300,30*arvo,600,300-30*arvo);
}
}
if ((k == 0) && (merkki== "<=")){
noStroke();
if (b <= arvo) {
rect(-300,30*arvo,600,-300-30*arvo);
}
}
if ((k > 0) && (merkki == "<")) {
noStroke();
rect(30*x,30*arvo,-300-30*x,-300-30*arvo);
noFill();
strokeWeight(5);
stroke(255,0,0);
ellipse(30*x,arvo*30,20,20);
line(30*x-10,30*arvo,-300,30*arvo);
}
if ((k < 0) && (merkki == "<")) {
noStroke();
rect(30*x,30*arvo,+300-30*x,-300-30*arvo);
noFill();
strokeWeight(5);
stroke(255,0,0);
ellipse(30*x,arvo*30,20,20);
line(30*x+10,30*arvo,300,30*arvo);
}
if ((k > 0) && (merkki == ">")) {
noStroke();
rect(30*x,30*arvo,300-30*x,300-30*arvo);
noFill();
strokeWeight(5);
stroke(255,0,0);
ellipse(30*x,arvo*30,20,20);
line(30*x+10,30*arvo,300,30*arvo);
}
if ((k < 0) && (merkki == ">")) {
noStroke();
rect(30*x,30*arvo,-300-30*x,300-30*arvo);
noFill();
strokeWeight(5);
stroke(255,0,0);
ellipse(30*x,arvo*30,20,20);
line(-300,arvo*30,30*x-10,arvo*30);
}
if ((k > 0) && (merkki == "<=")) {
noStroke();
rect(30*x,30*arvo,-300-30*x,-300-30*arvo);
fill(255,0,0);
strokeWeight(5);
stroke(255,0,0);
ellipse(30*x,arvo*30,20,20);
line(30*x-10,30*arvo,-300,30*arvo);
}
if ((k < 0) && (merkki == "<=")) {
noStroke();
rect(30*x,30*arvo,+300-30*x,-300-30*arvo);
fill(255,0,0);
strokeWeight(5);
stroke(255,0,0);
ellipse(30*x,arvo*30,20,20);
line(30*x+10,30*arvo,300,30*arvo);
}
if ((k > 0) && (merkki == ">=")) {
noStroke();
rect(30*x,30*arvo,300-30*x,300-30*arvo);
fill(255,0,0);
strokeWeight(5);
stroke(255,0,0);
ellipse(30*x,arvo*30,20,20);
line(30*x+10,30*arvo,300,30*arvo);
}
if ((k < 0) && (merkki == ">=")) {
noStroke();
rect(30*x,30*arvo,-300-30*x,300-30*arvo);
fill(255,0,0);
strokeWeight(5);
stroke(255,0,0);
ellipse(30*x,arvo*30,20,20);
line(-300,arvo*30,30*x-10,arvo*30);
}
strokeWeight(2);
fill(R,G,B,A);
}
void suoraXY(float x1, float y1, float x2, float y2) {
float x21 = map(x1,-10,10,-300,300);
float y21 = map(y1,-10,10,-300,300);
float x22 = map(x2,-10,10,-300,300);
float y22 = map(y2,-10,10,-300,300);
float k = ((y2-y1)/(x2-x1));
if (x1 == x2) {
line(x1*30,300,x1*30,-300);
}
for (int s=-3000; s<3000; s++) {
float y = k*(s/10.0)+(-k*x1+y1)*30;
ellipse((s/10.0),y,1,1);
}
ellipse(x21,y21,10,10);
ellipse(x22,y22,10,10);
}
void kulmakerroin(float x1, float y1, float x2, float y2) {
float k = ((y2-y1)/(x2-x1));
float x21 = map(x1,-10,10,-300,300);
float y21 = map(y1,-10,10,-300,300);
float x22 = map(x2,-10,10,-300,300);
float y22 = map(y2,-10,10,-300,300);
triangle(x21,y21,x22,y22,x22,y21);
if (x1 == x2) {
line(x1*30,300,x1*30,-300);
}
for (int s=-3000; s<3000; s++) {
float y = k*(s/10.0)+(-k*x1+y1)*30;
ellipse((s/10.0),y,1,1);
}
ellipse(x21,y21,10,10);
ellipse(x22,y22,10,10);
}
void suoranarvot(float x, float y, float k, float b) {
float x1 = map(x,-10,10,-300,300);
float y1 = map(y,-10,10,-300,300);
fill(255,255,255,200);
rect(x1,y1,105,-345);
pushMatrix();
scale(1,-1);
fill(0);
textSize(15);
text("x",x1+5,-y1+15);
text("y",x1+50,-y1+15);
for (int s=-10; s <=10; s++) {
text(s,x1+5,-y1+185+s*15);
text(""+round((k*s+b)*10)/10.0,x1+50,-y1+185+s*15);
}
popMatrix();
fill(R,G,B,A); // Oletusväri
textSize(20);
}
void paraabeli(float a, float b, float c) {
for (int s=-3000; s<3000; s++) {
float y =(a*((s/300.0)*(s/300.0))+b*(s/300.0)+c);
ellipse((s/10.0),y*30,1,1);
}
}
void polynomi(float a, float b, float c, float d) {
for (int s=-3000; s<3000; s++) {
float y = (a*(s/300.0)*(s/300.0)*(s/300.0)+b*(s/300.0)*(s/300.0)+c*(s/300.0)+d);
ellipse(s/10,y*30,1,1);
}
}
void monikulmio(float x, float y, float sade, float lukumaara, float alkukulma) {
if (lukumaara > 0) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
if (lukumaara == 1) {
ellipse(x2,y2,5,5);
} else {
float lisays = 360.0/lukumaara;
float kulma = alkukulma+lisays;
beginShape();
for (int s = 0; s<=lukumaara; s++) {
float x1 = sade*30*cos(radians(kulma));
float y1 = sade*30*sin(radians(kulma));
vertex(x2+x1,y2+y1);
kulma = kulma+lisays;
}
endShape();
}
}
}
void sarmio(float x, float y, float a, float b, float c) {
float x1 = map(x,-10,10,-300,300);
float y1 = map(y,-10,10,-300,300);
float a1 = map(a,-10,10,-300,300);
float b1 = map(b,-10,10,-300,300)/2.0;
float c1 = map(c,-10,10,-300,300);
float dx = b1*cos(radians(45));
float dy = b1*sin(radians(45));
quad(x1,y1,x1+dx,y1+dy,x1+dx,y1+c1+dy,x1,y1+c1);
quad(x1,y1,x1+dx,y1+dy,x1+a1+dx,y1+dy,x1+a1,y1);
quad(x1+dx,y1+dy,x1+a1+dx,y1+dy,x1+a1+dx,y1+c1+dy,x1+dx,y1+c1+dy);
rect(x1,y1,a1,c1);
quad(x1+a1,y1,x1+a1+dx,y1+dy,x1+a1+dx,y1+c1+dy,x1+a1,y1+c1);
quad(x1+a1+dx,y1+c1+dy,x1+a1,y1+c1,x1,y1+c1,x1+dx,y1+c1+dy);
}
void kartio(float x, float y, float r, float h) {
float x1 = map(x,-10,10,-300,300);
float y1 = map(y,-10,10,-300,300);
float r1 = map(r,-10,10,-300,300);
float h1 = map(h,-10,10,-300,300);
strokeWeight(2);
stroke(R,G,B,A);
for (int s= 0; s <= 360; s++) {
float xx = x1+r1*cos(radians(s));
float yy = y1+r1/2*sin(radians(s));
line(x1,y1+h1,xx,yy);
}
stroke(0);
strokeWeight(3);
ellipse(x1,y1,r1*2,r1);
noFill();
triangle(x1,y1,x1+r1,y1,x1,y1+h1);
triangle(x1,y1,x1-r1,y1,x1,y1+h1);
fill(R,G,B,A);
}
void lierio(float x, float y, float r, float h) {
float x1 = map(x,-10,10,-300,300);
float y1 = map(y,-10,10,-300,300);
float r1 = map(r,-10,10,-300,300);
float h1 = map(h,-10,10,-300,300);
fill(R,G,B,A);
strokeWeight(3);
stroke(R,G,B,A);
for (int s= 0; s <= 360; s++) {
float xx = x1+r1*cos(radians(s));
float yy = y1+r1/2*sin(radians(s));
line(xx,yy,xx,yy+h1);
}
noFill();
stroke(0);
ellipse(x1,y1,r1*2,r1);
rect(x1-r1,y1,r1,h1);
rect(x1,y1,r1,h1);
stroke(0);
fill(R,G,B,A);
strokeWeight(3);
ellipse(x1,y1+h1,r1*2,r1);
}
void pyramidi(float x, float y, float r, float h) {
float x1 = map(x,-10,10,-300,300);
float y1 = map(y,-10,10,-300,300);
float r1 = map(r,-10,10,-300,300);
float h1 = map(h,-10,10,-300,300);
float dx = (r1/2.0)*cos(radians(45));
float dy = (r1/2.0)*sin(radians(45));
noFill();
quad(x1-r1-dx,y1-dy,x1+r1-dx,y1-dy,x1+r1+dx,y1+dy,x1-r1+dx,y1+dy);
fill(R,G,B,A);
triangle(x1+r1+dx,y1+dy,x1-r1+dx,y1+dy,x1,y1+h1);
line(x1,y1,x1,y1+h1);
line(x1,y1,x1+r1,y1);
line(x1,y1+h1,x1+r1,y1);
triangle(x1-r1-dx,y1-dy,x1-r1+dx,y1+dy,x1,y1+h1);
triangle(x1+r1-dx,y1-dy,x1+r1+dx,y1+dy,x1,y1+h1);
triangle(x1-r1-dx,y1-dy,x1+r1-dx,y1-dy,x1,y1+h1);
}
void pallo(float x, float y, float r) {
float x1 = map(x,-10,10,-300,300);
float y1 = map(y,-10,10,-300,300);
float r1 = map(r,-10,10,-300,300);
ellipse(x1,y1,2*r1,2*r1);
noFill();
ellipse(x1,y1,2*r1,r1);
line(x1-r1,y1,x1+r1,y1);
line(x1,y1,x1,y1+r1);
fill(R,G,B,A);
}
void sarmiok(float x, float y, float a,float b, float h) {
float x1 = map(x,-10,10,-300,300);
float y1 = map(y,-10,10,-300,300);
float a1 = map(a,-10,10,-300,300);
// float b1 = map(b,-10,10,-300,300);
float h1 = map(h,-10,10,-300,300);
float kulma = atan(a/b);
float xx = b*30*cos(kulma);
float yy =b*30*sin(kulma)/2.0;
if (h < 0) {
fill(R,G,B,A);
} else {
noFill();
}
rect(x1,y1,a1,h1);
triangle(x1,y1,x1+a1,y1,x1+xx,y1-yy);
fill(R,G,B,A);
triangle(x1,y1+h1,x1+a1,y1+h1,x1+xx,y1+h1-yy);
quad(x1,y1,x1+xx,y1-yy,x1+xx,y1+h1-yy,x1,y1+h1);
quad(x1+a1,y1,x1+xx,y1-yy,x1+xx,y1+h1-yy,x1+a1,y1+h1);
}
void tangentti(float x, float y, float sade,float kulma) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sade2 = map(sade,-10,10,-300,300);
noFill();
ellipse(x2,y2,2*sade2,2*sade2);
float rx2 = sade2*cos(radians(kulma));
float ry2 = sade2*sin(radians(kulma));
float x0 = x+sade*cos(radians(kulma));
float y0 = y+sade*sin(radians(kulma));
line(x2,y2,x2+rx2,y2+ry2);
point(x2,y2);
float k = (y0-y)/(x0-x);
if (kulma%180 == 0) {
line(x0*30,300,x0*30,-300);
}
for (int s=-30000; s<30000; s++) {
float y22 = (-1/k)*(s/100.0)+((1/k)*x0+y0)*30;
ellipse((s/100.0),y22,1,1);
}
fill(R,G,B,A); // Oletusväri
}
void kommentti(String teksti,float x,float y,float koko) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
fill(0);
pushMatrix();
scale(1,-1);
fill(0);
textSize(koko);
text(teksti,x2,-y2);
popMatrix();
textSize(20);
fill(R,G,B,A); // Oletusväri
}
void x(float piste) {
float x2 = map(piste,-10,10,-300,300);
fill(255,0,0);
stroke(255,0,0);
strokeWeight(5);
ellipse(x2,0,20,20);
fill(R,G,B,A);
strokeWeight(2);
}
void lukusuora(String ehto, float piste) {
float x2 = map(piste,-10,10,-300,300);
strokeWeight(5);
stroke(255,0,0);
if (ehto == "<") {
noFill();
line(-300,10,x2,10);
}
if (ehto == ">") {
noFill();
line(300,10,x2,10);
}
if (ehto == "<=") {
fill(255,0,0);
line(-300,10,x2,10);
}
if (ehto == ">=") {
fill(255,0,0);
line(300,10,x2,10);
}
if (ehto == "<=") {
fill(255,0,0);
line(-300,10,x2,10);
}
if ((ehto == "=") || (ehto == "==")) {
fill(255,0,0);
}
if ((ehto == "!=") || (ehto == "<>")) {
noFill();
line(-300,10,300,10);
}
ellipse(x2,0,20,20);
fill(R,G,B,A);
strokeWeight(2);
stroke(0);
}
void lukusuoraJA(String ehto1, float piste1, String ehto2, float piste2) {
float x1 = map(piste1,-10,10,-300,300);
float x2 = map(piste2,-10,10,-300,300);
strokeWeight(5);
stroke(255,0,0);
if ((ehto1 == ">") && (ehto2 == "<")) {
if (piste2 > piste1) {
noFill();
line(x1,10,x2,10);
ellipse(x1,0,20,20);
ellipse(x2,0,20,20);
}
}
if ((ehto1 == ">=") && (ehto2 == "<=")) {
if (piste2 >= piste1) {
fill(255,0,0);
line(x1,10,x2,10);
ellipse(x1,0,20,20);
ellipse(x2,0,20,20);
}
}
if ((ehto1 == ">=") && (ehto2 == "<")) {
if (piste2 > piste1) {
fill(255,0,0);
line(x1,10,x2,10);
ellipse(x1,0,20,20);
noFill();
ellipse(x2,0,20,20);
}
}
if ((ehto1 == ">") && (ehto2 == "<=")) {
if (piste2 > piste1) {
fill(255,0,0);
line(x1,10,x2,10);
ellipse(x2,0,20,20);
noFill();
ellipse(x1,0,20,20);
}
}
if ((ehto1 == "<") && (ehto2 == ">")) {
if (piste2 < piste1) {
noFill();
line(x1,10,x2,10);
ellipse(x1,0,20,20);
ellipse(x2,0,20,20);
}
}
if ((ehto1 == "<=") && (ehto2 == ">=")) {
if (piste2 <= piste1) {
fill(255,0,0);
line(x1,10,x2,10);
ellipse(x1,0,20,20);
ellipse(x2,0,20,20);
}
}
if ((ehto1 == "<=") && (ehto2 == ">")) {
if (piste2 < piste1) {
fill(255,0,0);
line(x1,10,x2,10);
ellipse(x1,0,20,20);
noFill();
ellipse(x2,0,20,20);
}
}
if ((ehto1 == "<") && (ehto2 == ">=")) {
if (piste2 < piste1) {
fill(255,0,0);
line(x1,10,x2,10);
ellipse(x2,0,20,20);
noFill();
ellipse(x1,0,20,20);
}
}
if (((ehto1 == "=") || (ehto1 =="==")) && (ehto2 == ">")) {
if (piste1 > piste2) {
fill(255,0,0);
ellipse(x1,0,20,20);
}
}
if (((ehto1 == "=") || (ehto1 =="==")) && (ehto2 == ">=")) {
if (piste1 >= piste2) {
fill(255,0,0);
ellipse(x1,0,20,20);
}
}
if (((ehto1 == "=") || (ehto1 =="==")) && (ehto2 == "<")) {
if (piste1 < piste2) {
fill(255,0,0);
ellipse(x1,0,20,20);
}
}
if (((ehto1 == "=") || (ehto1 =="==")) && (ehto2 == "<=")) {
if (piste1 <= piste2) {
fill(255,0,0);
ellipse(x1,0,20,20);
}
}
if ((ehto1 == ">") && ((ehto2 == "=") || (ehto2 =="=="))) {
if (piste1 < piste2) {
fill(255,0,0);
ellipse(x2,0,20,20);
}
}
if ((ehto1 == ">=") && ((ehto2 == "=") || (ehto2 =="=="))) {
if (piste1 <= piste2) {
fill(255,0,0);
ellipse(x2,0,20,20);
}
}
if ((ehto1 == "<") && ((ehto2 == "=") || (ehto2 =="=="))) {
if (piste1 > piste2) {
fill(255,0,0);
ellipse(x2,0,20,20);
}
}
if ((ehto1 == "<=") && ((ehto2 == "=") || (ehto2 =="=="))) {
if (piste1 >= piste2) {
fill(255,0,0);
ellipse(x2,0,20,20);
}
}
if (((ehto1 == "=") || (ehto1 =="==")) && ((ehto2 == "=") || (ehto2 =="=="))) {
if (piste1 == piste2) {
fill(255,0,0);
ellipse(x1,0,20,20);
}
}
if ((ehto1 == "!=") && (ehto2 == ">")) {
if (piste1 < piste2) {
noFill();
ellipse(x2,0,20,20);
line(x2,10,300,10);
} else {
noFill();
ellipse(x2,0,20,20);
ellipse(x1,0,20,20);
line(x2,10,300,10);
}
}
if ((ehto1 == "!=") && (ehto2 == ">=")) {
if (piste1 <= piste2) {
fill(255,0,0);
ellipse(x2,0,20,20);
line(x2,10,300,10);
} else {
noFill();
ellipse(x1,0,20,20);
fill(255,0,0);
ellipse(x2,0,20,20);
line(x2,10,300,10);
}
}
if ((ehto1 == "!=") && (ehto2 == "<")) {
if (piste1 < piste2) {
noFill();
ellipse(x1,0,20,20);
ellipse(x2,0,20,20);
line(x2,10,-300,10);
} else {
noFill();
ellipse(x2,0,20,20);
line(x2,10,-300,10);
}
}
if ((ehto1 == "!=") && (ehto2 == "<=")) {
if (piste1 <= piste2) {
noFill();
ellipse(x1,0,20,20);
fill(255,0,0);
ellipse(x2,0,20,20);
line(x2,10,-300,10);
} else {
fill(255,0,0);
ellipse(x2,0,20,20);
line(x2,10,-300,10);
}
}
if ((ehto1 == "!=") && (ehto2 == ">")) {
if (piste1 > piste2) {
noFill();
ellipse(x1,0,20,20);
ellipse(x2,0,20,20);
line(x2,10,300,10);
} else {
noFill();
ellipse(x2,0,20,20);
line(x2,10,300,10);
}
}
if ((ehto1 == "!=") && (ehto2 == ">=")) {
if (piste1 >= piste2) {
noFill();
ellipse(x1,0,20,20);
fill(255,0,0);
ellipse(x2,0,20,20);
line(x2,10,300,10);
} else {
fill(255,0,0);
ellipse(x2,0,20,20);
line(x2,10,300,10);
}
}
if ((ehto1 == "!=") && ((ehto2 == "=") || (ehto2 =="=="))) {
if (piste1 != piste2) {
fill(255,0,0);
ellipse(x2,0,20,20);
}
}
if (((ehto1 == "=") || (ehto1 =="==")) && (ehto2 == "!=")) {
if (piste1 != piste2) {
fill(255,0,0);
ellipse(x1,0,20,20);
}
}
fill(R,G,B,A);
strokeWeight(2);
stroke(0);
}
void lukusuoraTAI(String ehto1, float piste1, String ehto2, float piste2) {
float x1 = map(piste1,-10,10,-300,300);
float x2 = map(piste2,-10,10,-300,300);
strokeWeight(5);
stroke(255,0,0);
if ((ehto1 == "<") && (ehto2 == ">")) {
noFill();
stroke(255,0,0);
ellipse(x1,0,20,20);
line(-300,10,x1,10);
stroke(255,0,255);
line(x2,-10,300,-10);
ellipse(x2,0,20,20);
}
if ((ehto1 == "<=") && (ehto2 == ">")) {
stroke(255,0,0);
fill(255,0,0);
ellipse(x1,0,20,20);
line(-300,10,x1,10);
stroke(255,0,255);
line(x2,-10,300,-10);
noFill();
ellipse(x2,0,20,20);
}
if ((ehto1 == "<") && (ehto2 == ">=")) {
noFill();
stroke(255,0,0);
ellipse(x1,0,20,20);
line(-300,10,x1,10);
stroke(255,0,255);
line(x2,-10,300,-10);
fill(255,0,255);
ellipse(x2,0,20,20);
}
if ((ehto1 == "<=") && (ehto2 == ">=")) {
fill(255,0,0);
stroke(255,0,0);
ellipse(x1,0,20,20);
line(-300,10,x1,10);
stroke(255,0,255);
line(x2,-10,300,-10);
fill(255,0,255);
ellipse(x2,0,20,20);
}
if ((ehto1 == ">") && (ehto2 == "<")) {
noFill();
stroke(255,0,0);
line(300,10,x1,10);
ellipse(x1,0,20,20);
stroke(255,0,255);
line(x2,-10,-300,-10);
ellipse(x2,0,20,20);
}
if ((ehto1 == ">=") && (ehto2 == "<")) {
stroke(255,0,0);
line(300,10,x1,10);
fill(255,0,0);
ellipse(x1,0,20,20);
stroke(255,0,255);
line(x2,-10,-300,-10);
noFill();
ellipse(x2,0,20,20);
}
if ((ehto1 == ">") && (ehto2 == "<=")) {
noFill();
stroke(255,0,0);
ellipse(x1,0,20,20);
line(300,10,x1,10);
stroke(255,0,255);
line(x2,-10,-300,-10);
fill(255,0,255);
ellipse(x2,0,20,20);
}
if ((ehto1 == ">=") && (ehto2 == "<=")) {
fill(255,0,0);
stroke(255,0,0);
ellipse(x1,0,20,20);
line(300,10,x1,10);
stroke(255,0,255);
fill(255,0,255);
line(x2,-10,-300,-10);
ellipse(x2,0,20,20);
}
if (((ehto1 == "=") || (ehto1 == "==")) && ((ehto2 == "=") || (ehto2 == "=="))) {
stroke(255,0,0);
fill(255,0,0);
ellipse(x1,0,20,20);
fill(255,0,255);
stroke(255,0,255);
ellipse(x2,0,20,20);
}
if (((ehto1 == "=") || (ehto1 == "==")) && (ehto2 == "<")) {
stroke(255,0,0);
fill(255,0,0);
ellipse(x1,0,20,20);
noFill();
stroke(255,0,255);
ellipse(x2,0,20,20);
line(-300,10,x2,10);
}
if (((ehto1 == "=") || (ehto1 == "==")) && (ehto2 == "<=")) {
stroke(255,0,0);
fill(255,0,0);
ellipse(x1,0,20,20);
stroke(255,0,255);
line(-300,10,x2,10);
fill(255,0,255);
ellipse(x2,0,20,20);
}
if (((ehto1 == "=") || (ehto1 == "==")) && (ehto2 == ">")) {
stroke(255,0,0);
fill(255,0,0);
ellipse(x1,0,20,20);
noFill();
stroke(255,0,255);
ellipse(x2,0,20,20);
line(x2,10,300,10);
}
if (((ehto1 == "=") || (ehto1 == "==")) && (ehto2 == ">=")) {
stroke(255,0,0);
fill(255,0,0);
ellipse(x1,0,20,20);
stroke(255,0,255);
fill(255,0,255);
ellipse(x2,0,20,20);
line(x2,10,300,10);
}
if ((ehto1 == ">") && ((ehto2 == "=") || (ehto2 == "=="))) {
stroke(255,0,0);
noFill();
line(300,10,x1,10);
ellipse(x1,0,20,20);
fill(255,0,255);
stroke(255,0,255);
ellipse(x2,0,20,20);
}
if ((ehto1 == ">=") && ((ehto2 == "=") || (ehto2 == "=="))) {
stroke(255,0,0);
fill(255,0,0);
line(300,10,x1,10);
ellipse(x1,0,20,20);
fill(255,0,255);
stroke(255,0,255);
ellipse(x2,0,20,20);
}
if ((ehto1 == "<") && ((ehto2 == "=") || (ehto2 == "=="))) {
stroke(255,0,0);
noFill();
line(x1,10,-300,10);
ellipse(x1,0,20,20);
stroke(255,0,255);
fill(255,0,255);
ellipse(x2,0,20,20);
}
if ((ehto1 == "<=") && ((ehto2 == "=") || (ehto2 == "=="))) {
stroke(255,0,0);
fill(255,0,0);
line(x1,10,-300,10);
ellipse(x1,0,20,20);
fill(255,0,255);
stroke(255,0,255);
ellipse(x2,0,20,20);
}
if ((ehto1 == "!=") && (ehto2 == "!=")) {
stroke(255,0,0);
noFill();
line(300,10,-300,10);
ellipse(x1,0,20,20);
stroke(255,0,255);
line(300,-10,-300,-10);
ellipse(x2,0,20,20);
}
if ((ehto1 == "!=") && (ehto2 == "<")) {
stroke(255,0,0);
noFill();
line(-300,10,300,10);
ellipse(x1,0,20,20);
noFill();
stroke(255,0,255);
ellipse(x2,0,20,20);
line(-300,-10,x2,-10);
}
if ((ehto1 == "!=") && (ehto2 == "<=")) {
stroke(255,0,0);
noFill();
ellipse(x1,0,20,20);
line(-300,10,300,10);
stroke(255,0,255);
line(-300,-10,x2,-10);
fill(255,0,255);
ellipse(x2,0,20,20);
}
if ((ehto1 == "!=") && (ehto2 == ">")) {
stroke(255,0,0);
noFill();
ellipse(x1,0,20,20);
line(-300,10,300,10);
stroke(255,0,255);
ellipse(x2,0,20,20);
line(x2,-10,300,-10);
}
if ((ehto1 == "!=") && (ehto2 == ">=")) {
stroke(255,0,0);
noFill();
line(-300,10,300,10);
ellipse(x1,0,20,20);
stroke(255,0,255);
fill(255,0,255);
ellipse(x2,0,20,20);
line(x2,-10,300,-10);
}
if ((ehto1 == ">") && (ehto2 == "!=")) {
stroke(255,0,0);
noFill();
line(300,10,x1,10);
ellipse(x1,0,20,20);
noFill();
stroke(255,0,255);
line(-300,-10,300,-10);
ellipse(x2,0,20,20);
}
if ((ehto1 == ">=") && (ehto2 == "!=")) {
stroke(255,0,0);
fill(255,0,0);
line(300,10,x1,10);
ellipse(x1,0,20,20);
noFill();
stroke(255,0,255);
line(-300,-10,300,-10);
ellipse(x2,0,20,20);
}
if ((ehto1 == "<") && (ehto2 == "!=")) {
stroke(255,0,0);
noFill();
line(x1,10,-300,10);
ellipse(x1,0,20,20);
stroke(255,0,255);
noFill();
line(-300,-10,300,-10);
ellipse(x2,0,20,20);
}
if ((ehto1 == "<=") && (ehto2 == "!=")) {
stroke(255,0,0);
fill(255,0,0);
line(x1,10,-300,10);
ellipse(x1,0,20,20);
noFill();
stroke(255,0,255);
line(-300,-10,300,-10);
ellipse(x2,0,20,20);
}
fill(R,G,B,A);
strokeWeight(2);
stroke(0);
}
void mittaakulma(float x1, float y1, float x2, float y2, float x3, float y3) {
float xx1 = map(x1,-10,10,-300,300);
float yy1 = map(y1,-10,10,-300,300);
float xx2 = map(x2,-10,10,-300,300);
float yy2 = map(y2,-10,10,-300,300);
float xx3 = map(x3,-10,10,-300,300);
float yy3 = map(y3,-10,10,-300,300);
float sade1 = sqrt((y1-y2)*(y1-y2)+(x1-x2)*(x1-x2));
float sade2 = sqrt((y3-y2)*(y3-y2)+(x3-x2)*(x3-x2));
float kulma1 = acos(abs(x1-x2)/sade1);
float kulma2 = acos(abs(x3-x2)/sade2);
float summa1 = 0;
float summa2 = 0;
float lisays = 0;
if ( ((y1-y2) == 0) && (x1 >= x2) ) { summa1 = 0; }
if ( ((y2-y1) == 0) && (x2 > x1) ) { summa1 = 180; }
if ( ((x1-x2) == 0) && (y1 >= y2) ) { summa1 = 90; }
if ( ((x2-x1) == 0) && (y2 > y1) ) { summa1 = 270; }
if (abs(x3-x2) == 0) {
lisays = 90-degrees(kulma1);
}
if ( ((x1-x2) > 0) && ((y1 -y2) > 0) ) {
summa1 = degrees(kulma1);
}
if ( ((x1-x2) < 0) && ((y1 -y2) > 0) ) {
summa1 = (90-degrees(kulma1))+90;
}
if ( ((x1-x2) < 0) && ((y1 -y2) < 0) ) {
summa1 = degrees(kulma1)+180;
}
if ( ((x1-x2) >=0) && ((y1 -y2) < 0) ) {
summa1 = 360-degrees(kulma1);
}
if ( ((x3-x2) > 0) && ((y3 -y2) > 0) ) {
summa2 = degrees(kulma2);
if ((summa1 >= 0) && (summa1 < 90)) {
if (summa2 > summa1) {
lisays = summa2-summa1;
} else {
lisays = 360-summa1+summa2;
}
}
if ((summa1 >= 90) && (summa1 < 180)) {
lisays = 360-summa1+summa2;
}
if ((summa1 >= 180) && (summa1 < 270)) {
lisays = 360-summa1+summa2;
}
if ((summa1 >= 270) && (summa1 < 360)) {
lisays = 360-summa1+summa2;
}
}
if ( ((x3-x2) <= 0) && ((y3 -y2) >= 0) ) {
summa2 = (90-degrees(kulma2))+90;
if ((summa1 >= 0) && (summa1 < 90)) {
lisays = summa2-summa1;
}
if ((summa1 >= 90) && (summa1 < 180)) {
if (summa2 > summa1) {
lisays = summa2-summa1;
} else {
lisays = 360-summa1+summa2;
}
}
if ((summa1 >= 180) && (summa1 < 270)) {
lisays = 360-summa1+summa2;
}
if ((summa1 >= 270) && (summa1 < 360)) {
lisays = 360-summa1+summa2;
}
}
if ( ((x3-x2) <= 0) && ((y3 -y2) <= 0) ) {
summa2 = degrees(kulma2)+180;
if ((summa1 >= 0) && (summa1 < 90)) {
lisays = summa2-summa1;
}
if ((summa1 >= 90) && (summa1 < 180)) {
lisays = summa2-summa1;
}
if ((summa1 >= 180) && (summa1 < 270)) {
if (summa2 > summa1) {
lisays = summa2-summa1;
} else {
lisays = 360-summa1+summa2;
}
}
if ((summa1 >= 270) && (summa1 < 360)) {
lisays = 360-summa1+summa2;
}
}
if ( ((x3-x2) >= 0) && ((y3 -y2) <= 0) ) {
summa2 = 360-degrees(kulma2);
if ((summa1 >= 0) && (summa1 < 90)) {
lisays = summa2-summa1;
}
if ((summa1 >= 90) && (summa1 < 180)) {
lisays = summa2-summa1;
}
if ((summa1 >= 180) && (summa1 < 270)) {
lisays = summa2-summa1;
}
if ((summa1 >= 270) && (summa1 < 360)) {
if (summa2 > summa1) {
lisays = summa2-summa1;
} else {
lisays = 360-summa1+summa2;
}
}
}
float summa3 = (summa1+summa1+lisays)/2;
strokeWeight(6);
point(xx1,yy1);
point(xx2,yy2);
point(xx3,yy3);
strokeWeight(3);
line(xx2,yy2,xx1,yy1);
line(xx2,yy2,xx3,yy3);
noFill();
arc(xx2,yy2,35,35,radians(summa1),radians(summa1+lisays),PIE);
float ds = 20*(sade1 + sade2)/2;
float dx = ds*cos(radians(summa3));
float dy = ds*sin(radians(summa3));
fill(0);
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+nfc(lisays,1)+"\u00B0",xx2+dx/2,-(yy2+dy/2));
popMatrix();
strokeWeight(2);
fill(R,G,B,A);
}
void mittaajana(float x1, float y1, float x2, float y2) {
float x12 = map(x1,-10,10,-300,300);
float y12 = map(y1,-10,10,-300,300);
float x22 = map(x2,-10,10,-300,300);
float y22 = map(y2,-10,10,-300,300);
float x0 = (x12+x22)/2;
float y0 = (y12+y22)/2;
float pituus = sqrt((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1));
strokeWeight(5);
line(x12,y12,x22,y22);
strokeWeight(10);
point(x12,y12);
point(x22,y22);
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+round(10*pituus)/10.0,x0+20,-y0+20);
popMatrix();
fill(R,G,B,A);
strokeWeight(2);
stroke(0);
}
void mittaasuora(float x1, float y1,float k, float b) {
float x12 = map(x1,-10,10,-300,300);
float y12 = map(y1,-10,10,-300,300);
float b2 = map(b,-10,10,-300,300);
float x2 = -300;
float y2 = k*x2+b2;
float pituus = sqrt((y2-y12)*(y2-y12)+(x2-x12)*(x2-x12));
float x0 = 0;
float y0 = 0;
for (int s=-3000; s<3000; s++) {
float y =k*(s/10.0)+b2;
ellipse((s/10.0),y,1,1);
float y3 = k*(s/10.0)+b2;
float pituus3 = sqrt((y3-y12)*(y3-y12)+((s/10.0)-x12)*((s/10.0)-x12));
if (pituus3 < pituus) {
pituus = pituus3;
x0 = (s/10);
y0 = y3;
}
}
strokeWeight(8);
point(x12,y12);
point(x0,y0);
strokeWeight(3);
line(x12,y12,x0,y0);
fill(0);
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+round(10*(pituus/30.0))/10.0,(x0+x12)/2.0+10,-((y0+y12)/2.0)+25);
popMatrix();
strokeWeight(2);
fill(R,G,B,A);
}
void mittaakaari(float x, float y, float sade, float kulma1, float kulma2) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sade2 = map(sade,-10,10,-300,300);
noFill();
if (kulma2 < kulma1) {
float muuta = kulma1;
kulma1 = kulma2;
kulma2 = muuta;
}
arc(x2,y2,2*sade2,2*sade2,radians(kulma1),radians(kulma2));
point(x2,y2);
fill(250,200,0,150); // Oletusväri
float pituus = ((kulma2-kulma1)/360)*2*PI*sade;
float dx = 35*sade*cos(radians((kulma2+kulma1)/2.0));
float dy = 35*sade*sin(radians((kulma2+kulma1)/2.0));
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+round(10*pituus)/10.0,x2+dx,-(y2+dy));
popMatrix();
strokeWeight(2);
fill(R,G,B,A);
}
void mittaahypotenuusa(float x, float y, float a, float b) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float a2 = map(a,-10,10,-300,300);
float b2 = map(b,-10,10,-300,300);
triangle(x2,y2,x2+a2,y2,x2,y2+b2);
float pituus = sqrt(a*a+b*b);
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+round(10*pituus)/10.0,(x2+(x2+a2))/2,-(y2+(y2+b2))/2);
popMatrix();
strokeWeight(2);
fill(R,G,B,A);
}
void mittaakateetti(float x, float y, float a, float c) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float a2 = map(a,-10,10,-300,300);
float b = sqrt(c*c-a*a);
float b2 = map(b,-10,10,-300,300);
triangle(x2,y2,x2+a2,y2,x2,y2+b2);
float pituus = sqrt(c*c-a*a);
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+round(10*pituus)/10.0,x2-35,-(y2+(y2+b2))/2);
popMatrix();
strokeWeight(2);
fill(R,G,B,A);
}
void tahti(float x, float y, float sade1, float sade2, float lukumaara, float alkukulma) {
if (lukumaara > 0) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
if (lukumaara == 1) {
ellipse(x2,y2,5,5);
} else {
float lisays = 360.0/lukumaara;
float kulma = alkukulma+lisays;
beginShape();
for (int s = 0; s<=lukumaara; s++) {
float x1 = sade1*30*cos(radians(kulma));
float y1 = sade1*30*sin(radians(kulma));
vertex(x2+x1,y2+y1);
float x12 = sade2*30*cos(radians(kulma+lisays/2));
float y12 = sade2*30*sin(radians(kulma+lisays/2));
vertex(x2+x12,y2+y12);
kulma = kulma+lisays;
}
endShape();
}
}
}
void piirtokolmio(float x, float y, float kulma) {
fill(0,100,255,100);
noStroke();
float h = 150;
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
pushMatrix();
translate(x2,y2);
rotate(radians(kulma));
triangle(-h,0,h,0,0,h);
fill(0);
ellipse(0,0,5,5);
for (int s = 0; s <= 180; s = s + 10) {
float a1 = 100*cos(radians(s));
float b1 = 100*sin(radians(s));
float a2 = 50*cos(radians(s));
float b2 = 50*sin(radians(s));
stroke(0,0,255);
strokeWeight(1);
line(a1,b1,a2,b2);
}
for (int s = 0; s <= 180; s = s + 5) {
float a1 = 100*cos(radians(s));
float b1 = 100*sin(radians(s));
float a2 = 90*cos(radians(s));
float b2 = 90*sin(radians(s));
stroke(0);
strokeWeight(1);
line(a1,b1,a2,b2);
}
for (int s = 0; s <= 180; s = s + 45) {
float a1 = 100*cos(radians(s));
float b1 = 100*sin(radians(s));
float a2 = 20*cos(radians(s));
float b2 = 20*sin(radians(s));
stroke(255,0,0);
strokeWeight(1);
line(a1,b1,a2,b2);
}
popMatrix();
stroke(0);
fill(R,G,B,A);
strokeWeight(2); // Oletus paksuus
}
void viivoitin(float x, float y, float kulma) {
fill(100,255,100,100);
noStroke();
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
pushMatrix();
translate(x2,y2);
rotate(radians(kulma));
rect(0,0,300,30);
fill(0);
ellipse(0,0,5,5);
for (int s=0; s <= 20; s=s+1) {
stroke(0);
strokeWeight(1);
line(s*15,0,s*15,10);
}
for (int s=0; s <= 10; s=s+1) {
stroke(0,0,255);
strokeWeight(1);
line(s*30,0,s*30,20);
}
for (int s=0; s <= 100; s=s+1) {
stroke(255,0,255);
strokeWeight(1);
line(s*3,0,s*3,5);
}
popMatrix();
stroke(0);
fill(R,G,B,A);
strokeWeight(2); // Oletus paksuus
}
void kartiomoni(float x, float y, float sade, float h, float lukumaara, float alkukulma) {
if (lukumaara > 0) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float h2 = map(h,-10,10,-300,300);
if (lukumaara == 1) {
ellipse(x2,y2,5,5);
} else {
float lisays = 360.0/lukumaara;
float kulma0 = alkukulma;
float x1 = sade*30*cos(radians(kulma0));
float y1 = sade*30*sin(radians(kulma0))/2.0;
line(x2,y2,x2+x1,y2+y1);
float kulma = alkukulma+lisays;
beginShape();
for (int s = 0; s < lukumaara; s++) {
x1 = sade*30*cos(radians(kulma));
y1 = sade*30*sin(radians(kulma))/2.0;
vertex(x2+x1,y2+y1);
kulma = kulma+lisays;
float x3 = sade*30*cos(radians(kulma));
float y3 = sade*30*sin(radians(kulma))/2.0;
triangle(x2+x1,y2+y1,x2,y2+h2,x2+x3,y2+y3);
}
endShape();
line(x2,y2,x2,y2+h2);
}
}
}
void lieriomoni(float x, float y, float sade, float h, float lukumaara, float alkukulma) {
if (lukumaara > 0) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float h2 = map(h,-10,10,-300,300);
if (lukumaara == 1) {
ellipse(x2,y2,5,5);
} else {
float lisays = 360.0/lukumaara;
float kulma0 = alkukulma;
float x1 = sade*30*cos(radians(kulma0));
float y1 = sade*30*sin(radians(kulma0))/2.0;
line(x2,y2,x2+x1,y2+y1);
line(x2,y2+h2,x2+x1,y2+y1+h2);
float kulma = alkukulma+lisays;
beginShape();
for (int s = 0; s < lukumaara; s++) {
x1 = sade*30*cos(radians(kulma));
y1 = sade*30*sin(radians(kulma))/2.0;
vertex(x2+x1,y2+y1);
kulma = kulma+lisays;
float x3 = sade*30*cos(radians(kulma));
float y3 = sade*30*sin(radians(kulma))/2.0;
quad(x2+x1,y2+y1,x2+x3,y2+y3,x2+x3,y2+y3+h2,x2+x1,y2+y1+h2);
}
endShape();
line(x2,y2,x2,y2+h2);
}
}
}
Geometria-funktiot (Kirjasto sopii iPAD:lle)
Tämä kirjasto sisältää seuraavat komennot
- Ellipsi
- Jana
- Janan keskinormaali
- Janan keskipiste
- Jänne
- Kaari
- Koordinaatisto
- Kolmio
- Kommentti
- Kulma
- Monikulmio
- Mittaa-funktiot
- Nelikulmio
- Neliö
- Piirtokolmio
- Piste
- Puolisuunnikas
- Segmentti
- Sektori
- Suorakulmio
- Suunnikas
- Tangentti
- Tähti
- Viivoitin
- Ympyrä
// Ohjelman tehnyt e-Oppi Oy, Geometria kirjasto iPAD:lle
// Viimeksi päivitetty: 31.8.2017
// Oletus täyttöväri
int R =250; // Oletus punainen
int G = 200; // Oletus vihreä
int B = 0; // Oletus sininen
int A = 100; // Oletus läpinäkyvyys
void setup () {
size(601,601); // Älä muuta ikkunan kokoa
}
// Kaikki komennot laitetaan void draw ()-lohkoon
void draw () {
koordinaatisto();
// Kirjoita tähän kaikki komennot
}
// Tästä alkaa funktiot eli aliohjelmat
// Älä tee näihin muutoksia !!
// Koordinaatisto on suunniteltu 600x600 ikkunaan
void koordinaatisto() {
fill(255);
noStroke();
rect(0,0,600,600);
stroke(128);
strokeWeight(1);
for (int z = 0; z < 21; z++) {
line(z*30,0,z*30,600);
line(0,0+z*30,600,z*30);
}
strokeWeight(3);
stroke(0,0,100);
line(300,3,300,600);
line(0,300,600,300);
fill(0,0,100);
triangle(590,290,598,300,590,310);
triangle(300,3,310,10,290,10);
text("x",580,285);
text("y",315,20);
textSize(20);
text("1",323,320);
text("1",280,280);
translate(300,300);
scale(1,-1);
strokeWeight(2); // Oletus paksuus
fill(R,G,B,A); // Oletusväri
stroke(0);
}
void suorakulmio(float x, float y, float leveys, float korkeus) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float leveys2 = map(leveys,-10,10,-300,300);
float korkeus2 = map(korkeus,-10,10,-300,300);
rect(x2,y2,leveys2,korkeus2);
}
void nelio(float x, float y, float sivu) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sivu2 = map(sivu,-10,10,-300,300);
rect(x2,y2,sivu2,sivu2);
}
void ympyra(float x, float y, float sade) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sade2 = map(sade,-10,10,-300,300);
ellipse(x2,y2,2*sade2,2*sade2);
point(x2,y2);
}
void ellipsi(float x, float y, float leveys, float korkeus) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float leveys2 = map(leveys,-10,10,-300,300);
float korkeus2 = map(korkeus,-10,10,-300,300);
ellipse(x2,y2,leveys2,korkeus2);
point(x2,y2);
}
void piste(float x, float y) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
strokeWeight(3);
// fill(255,0,0);
ellipse(x2,y2,10,10);
fill(R,G,B,A);
strokeWeight(2);
stroke(0);
}
void jana(float x1, float y1, float x2, float y2) {
float x12 = map(x1,-10,10,-300,300);
float y12 = map(y1,-10,10,-300,300);
float x22 = map(x2,-10,10,-300,300);
float y22 = map(y2,-10,10,-300,300);
strokeWeight(3);
// fill(255,0,0);
line(x12,y12,x22,y22);
ellipse(x12,y12,10,10);
ellipse(x22,y22,10,10);
fill(R,G,B,A);
strokeWeight(2);
stroke(0);
}
void keskipiste(float x1, float y1, float x2, float y2) {
float x12 = map(x1,-10,10,-300,300);
float y12 = map(y1,-10,10,-300,300);
float x22 = map(x2,-10,10,-300,300);
float y22 = map(y2,-10,10,-300,300);
float z1 = (x1+x2)/2;
float z2 = (y1+y2)/2;
strokeWeight(3);
// fill(255,0,0);
line(x12,y12,x22,y22);
ellipse(x12,y12,10,10);
ellipse(x22,y22,10,10);
fill(255,0,0);
ellipse(z1*30,z2*30,10,10);
fill(R,G,B,A);
strokeWeight(2);
stroke(0);
}
void normaali(float x1, float y1, float x2, float y2) {
float x12 = map(x1,-10,10,-300,300);
float y12 = map(y1,-10,10,-300,300);
float x22 = map(x2,-10,10,-300,300);
float y22 = map(y2,-10,10,-300,300);
strokeWeight(3);
// fill(255,0,0);
line(x12,y12,x22,y22);
float x0 = (x1+x2)/2;
float y0 = (y1+y2)/2;
float k = ((y22-y12)/(x22-x12));
if (y1 == y2) {
line(x0*30,300,x0*30,-300);
}
for (int s=-3000; s<3000; s++) {
float y = (-1/k)*(s/10.0)+((1/k)*x0+y0)*30;
ellipse((s/10.0),y,1,1);
}
ellipse(x12,y12,10,10);
ellipse(x22,y22,10,10);
fill(R,G,B,A);
strokeWeight(2);
stroke(0);
}
void sektori(float x, float y, float sade, float kulma1, float kulma2) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sade2 = map(sade,-10,10,-300,300);
if (kulma2 < kulma1) {
float muuta = kulma1;
kulma1 = kulma2;
kulma2 = muuta;
}
arc(x2,y2,2*sade2,2*sade2,radians(kulma1),radians(kulma2),PIE);
point(x2,y2);
}
void kaari(float x, float y, float sade, float kulma1, float kulma2) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sade2 = map(sade,-10,10,-300,300);
noFill();
if (kulma2 < kulma1) {
float muuta = kulma1;
kulma1 = kulma2;
kulma2 = muuta;
}
arc(x2,y2,2*sade2,2*sade2,radians(kulma1),radians(kulma2));
point(x2,y2);
fill(R,G,B,A); // Oletusväri
}
void janne(float x, float y, float sade, float kulma1, float kulma2) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sade2 = map(sade,-10,10,-300,300);
float rx1 = sade2*cos(radians(kulma1));
float ry1 = sade2*sin(radians(kulma1));
float rx2 = sade2*cos(radians(kulma2));
float ry2 = sade2*sin(radians(kulma2));
line(x2+rx1,y2+ry1,x2+rx2,y2+ry2);
point(x2,y2);
}
void segmentti(float x, float y, float sade, float kulma1, float kulma2) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sade2 = map(sade,-10,10,-300,300);
if (kulma2 < kulma1) {
float muuta = kulma1;
kulma1 = kulma2;
kulma2 = muuta;
}
arc(x2,y2,2*sade2,2*sade2,radians(kulma1),radians(kulma2),CHORD);
point(x2,y2);
}
void suunnikas(float x, float y, float sivu1, float sivu2, float kulma) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sivu12 = map(sivu1,-10,10,-300,300);
float sivu22 = map(sivu2,-10,10,-300,300);
quad(x2,y2, x2+sivu12,y2, x2+sivu12+sivu22*cos(radians(kulma)),y2+sivu22*sin(radians(kulma)), x2+sivu22*cos(radians(kulma)),y2+sivu22*sin(radians(kulma)) );
}
void puolisuunnikas(float x, float y, float a, float b, float h, float dx) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float a2 = map(a,-10,10,-300,300);
float b2 = map(b,-10,10,-300,300);
float h2 = map(h,-10,10,-300,300);
float dx2 = map(dx,-10,10,-300,300);
quad(x2,y2,x2+b2,y2,x2+a2+dx2,y2+h2,x2+dx2,y2+h2);
}
void kolmio(float x, float y, float sivu1, float sivu2, float kulma) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sivu12 = map(sivu1,-10,10,-300,300);
float sivu22 = map(sivu2,-10,10,-300,300);
triangle(x2,y2, x2+sivu12,y2, x2+sivu22*cos(radians(kulma)),y2+sivu22*sin(radians(kulma)) );
}
void kolmiokanta(float x1, float y1, float sivu, float kulma1, float kulma2) {
float x2 = map(x1,-10,10,-300,300);
float y2 = map(y1,-10,10,-300,300);
float sivu2 = map(sivu,-10,10,-300,300);
float a = (sin(radians(kulma2))*sivu)/sin(radians(180-(kulma1+kulma2)));
float x0 = x2+30*a*cos(radians(kulma1));
float y0 = y2+30*a*sin(radians(kulma1));
triangle(x2,y2,x2+sivu2,y2,x0,y0);
}
void nelikulmio(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
float x12 = map(x1,-10,10,-300,300);
float y12 = map(y1,-10,10,-300,300);
float x22 = map(x2,-10,10,-300,300);
float y22 = map(y2,-10,10,-300,300);
float x32 = map(x3,-10,10,-300,300);
float y32 = map(y3,-10,10,-300,300);
float x42 = map(x4,-10,10,-300,300);
float y42 = map(y4,-10,10,-300,300);
quad(x12,y12,x22,y22,x32,y32,x42,y42);
}
void kolmioXY(float x1, float y1, float x2, float y2, float x3, float y3) {
float x12 = map(x1,-10,10,-300,300);
float y12 = map(y1,-10,10,-300,300);
float x22 = map(x2,-10,10,-300,300);
float y22 = map(y2,-10,10,-300,300);
float x32 = map(x3,-10,10,-300,300);
float y32 = map(y3,-10,10,-300,300);
triangle(x12,y12,x22,y22,x32,y32);
}
void kulma(float x, float y, float sivu1, float sivu2, float kulma1, float kulma2) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sivu12 = map(sivu1,-10,10,-300,300);
float sivu22 = map(sivu2,-10,10,-300,300);
arc(x2,y2,30,30,radians(kulma1),radians(kulma1+kulma2),PIE);
line(x2,y2,x2+sivu12*cos(radians(kulma1)),y2+sivu12*sin(radians(kulma1)));
line(x2,y2,x2+sivu22*cos(radians(kulma1+kulma2)),y2+sivu22*sin(radians(kulma1+kulma2)));
}
void monikulmio(float x, float y, float sade, float lukumaara, float alkukulma) {
if (lukumaara > 0) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
if (lukumaara == 1) {
ellipse(x2,y2,5,5);
} else {
float lisays = 360.0/lukumaara;
float kulma = alkukulma+lisays;
beginShape();
for (int s = 0; s<=lukumaara; s++) {
float x1 = sade*30*cos(radians(kulma));
float y1 = sade*30*sin(radians(kulma));
vertex(x2+x1,y2+y1);
kulma = kulma+lisays;
}
endShape();
}
}
}
void tangentti(float x, float y, float sade,float kulma) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sade2 = map(sade,-10,10,-300,300);
noFill();
ellipse(x2,y2,2*sade2,2*sade2);
float rx2 = sade2*cos(radians(kulma));
float ry2 = sade2*sin(radians(kulma));
float x0 = x+sade*cos(radians(kulma));
float y0 = y+sade*sin(radians(kulma));
line(x2,y2,x2+rx2,y2+ry2);
point(x2,y2);
float k = (y0-y)/(x0-x);
if (kulma%180 == 0) {
line(x0*30,300,x0*30,-300);
}
for (int s=-30000; s<30000; s++) {
float y22 = (-1/k)*(s/100.0)+((1/k)*x0+y0)*30;
ellipse((s/100.0),y22,1,1);
}
fill(R,G,B,A); // Oletusväri
}
void kommentti(String teksti,float x,float y,float koko) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
fill(0);
pushMatrix();
scale(1,-1);
fill(0);
textSize(koko);
text(teksti,x2,-y2);
popMatrix();
textSize(20);
fill(R,G,B,A); // Oletusväri
}
void mittaakulma(float x1, float y1, float x2, float y2, float x3, float y3) {
float xx1 = map(x1,-10,10,-300,300);
float yy1 = map(y1,-10,10,-300,300);
float xx2 = map(x2,-10,10,-300,300);
float yy2 = map(y2,-10,10,-300,300);
float xx3 = map(x3,-10,10,-300,300);
float yy3 = map(y3,-10,10,-300,300);
float sade1 = sqrt((y1-y2)*(y1-y2)+(x1-x2)*(x1-x2));
float sade2 = sqrt((y3-y2)*(y3-y2)+(x3-x2)*(x3-x2));
float kulma1 = acos(abs(x1-x2)/sade1);
float kulma2 = acos(abs(x3-x2)/sade2);
float summa1 = 0;
float summa2 = 0;
float lisays = 0;
if ( ((y1-y2) == 0) && (x1 >= x2) ) { summa1 = 0; }
if ( ((y2-y1) == 0) && (x2 > x1) ) { summa1 = 180; }
if ( ((x1-x2) == 0) && (y1 >= y2) ) { summa1 = 90; }
if ( ((x2-x1) == 0) && (y2 > y1) ) { summa1 = 270; }
if (abs(x3-x2) == 0) {
lisays = 90-degrees(kulma1);
}
if ( ((x1-x2) > 0) && ((y1 -y2) > 0) ) {
summa1 = degrees(kulma1);
}
if ( ((x1-x2) < 0) && ((y1 -y2) > 0) ) {
summa1 = (90-degrees(kulma1))+90;
}
if ( ((x1-x2) < 0) && ((y1 -y2) < 0) ) {
summa1 = degrees(kulma1)+180;
}
if ( ((x1-x2) >=0) && ((y1 -y2) < 0) ) {
summa1 = 360-degrees(kulma1);
}
if ( ((x3-x2) > 0) && ((y3 -y2) > 0) ) {
summa2 = degrees(kulma2);
if ((summa1 >= 0) && (summa1 < 90)) {
if (summa2 > summa1) {
lisays = summa2-summa1;
} else {
lisays = 360-summa1+summa2;
}
}
if ((summa1 >= 90) && (summa1 < 180)) {
lisays = 360-summa1+summa2;
}
if ((summa1 >= 180) && (summa1 < 270)) {
lisays = 360-summa1+summa2;
}
if ((summa1 >= 270) && (summa1 < 360)) {
lisays = 360-summa1+summa2;
}
}
if ( ((x3-x2) <= 0) && ((y3 -y2) >= 0) ) {
summa2 = (90-degrees(kulma2))+90;
if ((summa1 >= 0) && (summa1 < 90)) {
lisays = summa2-summa1;
}
if ((summa1 >= 90) && (summa1 < 180)) {
if (summa2 > summa1) {
lisays = summa2-summa1;
} else {
lisays = 360-summa1+summa2;
}
}
if ((summa1 >= 180) && (summa1 < 270)) {
lisays = 360-summa1+summa2;
}
if ((summa1 >= 270) && (summa1 < 360)) {
lisays = 360-summa1+summa2;
}
}
if ( ((x3-x2) <= 0) && ((y3 -y2) <= 0) ) {
summa2 = degrees(kulma2)+180;
if ((summa1 >= 0) && (summa1 < 90)) {
lisays = summa2-summa1;
}
if ((summa1 >= 90) && (summa1 < 180)) {
lisays = summa2-summa1;
}
if ((summa1 >= 180) && (summa1 < 270)) {
if (summa2 > summa1) {
lisays = summa2-summa1;
} else {
lisays = 360-summa1+summa2;
}
}
if ((summa1 >= 270) && (summa1 < 360)) {
lisays = 360-summa1+summa2;
}
}
if ( ((x3-x2) >= 0) && ((y3 -y2) <= 0) ) {
summa2 = 360-degrees(kulma2);
if ((summa1 >= 0) && (summa1 < 90)) {
lisays = summa2-summa1;
}
if ((summa1 >= 90) && (summa1 < 180)) {
lisays = summa2-summa1;
}
if ((summa1 >= 180) && (summa1 < 270)) {
lisays = summa2-summa1;
}
if ((summa1 >= 270) && (summa1 < 360)) {
if (summa2 > summa1) {
lisays = summa2-summa1;
} else {
lisays = 360-summa1+summa2;
}
}
}
float summa3 = (summa1+summa1+lisays)/2;
strokeWeight(6);
point(xx1,yy1);
point(xx2,yy2);
point(xx3,yy3);
strokeWeight(3);
line(xx2,yy2,xx1,yy1);
line(xx2,yy2,xx3,yy3);
noFill();
arc(xx2,yy2,35,35,radians(summa1),radians(summa1+lisays),PIE);
float ds = 20*(sade1 + sade2)/2;
float dx = ds*cos(radians(summa3));
float dy = ds*sin(radians(summa3));
fill(0);
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+nfc(lisays,1)+"\u00B0",xx2+dx/2,-(yy2+dy/2));
popMatrix();
strokeWeight(2);
fill(R,G,B,A);
}
void mittaajana(float x1, float y1, float x2, float y2) {
float x12 = map(x1,-10,10,-300,300);
float y12 = map(y1,-10,10,-300,300);
float x22 = map(x2,-10,10,-300,300);
float y22 = map(y2,-10,10,-300,300);
float x0 = (x12+x22)/2;
float y0 = (y12+y22)/2;
float pituus = sqrt((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1));
strokeWeight(5);
line(x12,y12,x22,y22);
strokeWeight(10);
point(x12,y12);
point(x22,y22);
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+round(10*pituus)/10.0,x0+20,-y0+20);
popMatrix();
fill(R,G,B,A);
strokeWeight(2);
stroke(0);
}
void mittaasuora(float x1, float y1,float k, float b) {
float x12 = map(x1,-10,10,-300,300);
float y12 = map(y1,-10,10,-300,300);
float b2 = map(b,-10,10,-300,300);
float x2 = -300;
float y2 = k*x2+b2;
float pituus = sqrt((y2-y12)*(y2-y12)+(x2-x12)*(x2-x12));
float x0 = 0;
float y0 = 0;
for (int s=-3000; s<3000; s++) {
float y =k*(s/10.0)+b2;
ellipse((s/10.0),y,1,1);
float y3 = k*(s/10.0)+b2;
float pituus3 = sqrt((y3-y12)*(y3-y12)+((s/10.0)-x12)*((s/10.0)-x12));
if (pituus3 < pituus) {
pituus = pituus3;
x0 = (s/10);
y0 = y3;
}
}
strokeWeight(8);
point(x12,y12);
point(x0,y0);
strokeWeight(3);
line(x12,y12,x0,y0);
fill(0);
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+round(10*(pituus/30.0))/10.0,(x0+x12)/2.0+10,-((y0+y12)/2.0)+25);
popMatrix();
strokeWeight(2);
fill(R,G,B,A);
}
void mittaakaari(float x, float y, float sade, float kulma1, float kulma2) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sade2 = map(sade,-10,10,-300,300);
noFill();
if (kulma2 < kulma1) {
float muuta = kulma1;
kulma1 = kulma2;
kulma2 = muuta;
}
arc(x2,y2,2*sade2,2*sade2,radians(kulma1),radians(kulma2));
point(x2,y2);
fill(250,200,0,150); // Oletusväri
float pituus = ((kulma2-kulma1)/360)*2*PI*sade;
float dx = 35*sade*cos(radians((kulma2+kulma1)/2.0));
float dy = 35*sade*sin(radians((kulma2+kulma1)/2.0));
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+round(10*pituus)/10.0,x2+dx,-(y2+dy));
popMatrix();
strokeWeight(2);
fill(R,G,B,A);
}
void mittaahypotenuusa(float x, float y, float a, float b) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float a2 = map(a,-10,10,-300,300);
float b2 = map(b,-10,10,-300,300);
triangle(x2,y2,x2+a2,y2,x2,y2+b2);
float pituus = sqrt(a*a+b*b);
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+round(10*pituus)/10.0,(x2+(x2+a2))/2,-(y2+(y2+b2))/2);
popMatrix();
strokeWeight(2);
fill(R,G,B,A);
}
void mittaakateetti(float x, float y, float a, float c) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float a2 = map(a,-10,10,-300,300);
float b = sqrt(c*c-a*a);
float b2 = map(b,-10,10,-300,300);
triangle(x2,y2,x2+a2,y2,x2,y2+b2);
float pituus = sqrt(c*c-a*a);
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+round(10*pituus)/10.0,x2-35,-(y2+(y2+b2))/2);
popMatrix();
strokeWeight(2);
fill(R,G,B,A);
}
void tahti(float x, float y, float sade1, float sade2, float lukumaara, float alkukulma) {
if (lukumaara > 0) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
if (lukumaara == 1) {
ellipse(x2,y2,5,5);
} else {
float lisays = 360.0/lukumaara;
float kulma = alkukulma+lisays;
beginShape();
for (int s = 0; s<=lukumaara; s++) {
float x1 = sade1*30*cos(radians(kulma));
float y1 = sade1*30*sin(radians(kulma));
vertex(x2+x1,y2+y1);
float x12 = sade2*30*cos(radians(kulma+lisays/2));
float y12 = sade2*30*sin(radians(kulma+lisays/2));
vertex(x2+x12,y2+y12);
kulma = kulma+lisays;
}
endShape();
}
}
}
void piirtokolmio(float x, float y, float kulma) {
fill(0,100,255,100);
noStroke();
float h = 150;
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
pushMatrix();
translate(x2,y2);
rotate(radians(kulma));
triangle(-h,0,h,0,0,h);
fill(0);
ellipse(0,0,5,5);
for (int s = 0; s <= 180; s = s + 10) {
float a1 = 100*cos(radians(s));
float b1 = 100*sin(radians(s));
float a2 = 50*cos(radians(s));
float b2 = 50*sin(radians(s));
stroke(0,0,255);
strokeWeight(1);
line(a1,b1,a2,b2);
}
for (int s = 0; s <= 180; s = s + 5) {
float a1 = 100*cos(radians(s));
float b1 = 100*sin(radians(s));
float a2 = 90*cos(radians(s));
float b2 = 90*sin(radians(s));
stroke(0);
strokeWeight(1);
line(a1,b1,a2,b2);
}
for (int s = 0; s <= 180; s = s + 45) {
float a1 = 100*cos(radians(s));
float b1 = 100*sin(radians(s));
float a2 = 20*cos(radians(s));
float b2 = 20*sin(radians(s));
stroke(255,0,0);
strokeWeight(1);
line(a1,b1,a2,b2);
}
popMatrix();
stroke(0);
fill(R,G,B,A);
strokeWeight(2); // Oletus paksuus
}
void viivoitin(float x, float y, float kulma) {
fill(100,255,100,100);
noStroke();
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
pushMatrix();
translate(x2,y2);
rotate(radians(kulma));
rect(0,0,300,30);
fill(0);
ellipse(0,0,5,5);
for (int s=0; s <= 20; s=s+1) {
stroke(0);
strokeWeight(1);
line(s*15,0,s*15,10);
}
for (int s=0; s <= 10; s=s+1) {
stroke(0,0,255);
strokeWeight(1);
line(s*30,0,s*30,20);
}
for (int s=0; s <= 100; s=s+1) {
stroke(255,0,255);
strokeWeight(1);
line(s*3,0,s*3,5);
}
popMatrix();
stroke(0);
fill(R,G,B,A);
strokeWeight(2); // Oletus paksuus
}
Analyyttisen geometrian funktiot (Tämä kirjasto sopii iPAD:lle)
Tämä kirjasto sisältää seuraavat komennot
- Epäyhtälö
- Koordinaatisto
- Kommentti
- Kulmakerroin
- Lukusuora
- Paraabeli
- Piirtokolmio
- Piste
- Polynomi
- Mittaa-funktiot
- Suora y = kx + b
- Suoran arvot
- Suora kahden pisteen avulla
- Viivoitin
// Ohjelman tehnyt e-Oppi Oy, Analyyttisen geometrian funktiot
// Viimeksi päivitetty: 31.8.2017
// Oletus täyttöväri
int R =250; // Oletus punainen
int G = 200; // Oletus vihreä
int B = 0; // Oletus sininen
int A = 100; // Oletus läpinäkyvyys
void setup () {
size(601,601); // Älä muuta ikkunan kokoa
}
// Kaikki komennot laitetaan void draw ()-lohkoon
void draw () {
koordinaatisto();
// Kirjoita tähän kaikki komennot
}
// Tästä alkaa funktiot eli aliohjelmat
// Älä tee näihin muutoksia !!
// Koordinaatisto on suunniteltu 600x600 ikkunaan
void koordinaatisto() {
fill(255);
noStroke();
rect(0,0,600,600);
stroke(128);
strokeWeight(1);
for (int z = 0; z < 21; z++) {
line(z*30,0,z*30,600);
line(0,0+z*30,600,z*30);
}
strokeWeight(3);
stroke(0,0,100);
line(300,3,300,600);
line(0,300,600,300);
fill(0,0,100);
triangle(590,290,598,300,590,310);
triangle(300,3,310,10,290,10);
text("x",580,285);
text("y",315,20);
textSize(20);
text("1",323,320);
text("1",280,280);
translate(300,300);
scale(1,-1);
strokeWeight(2); // Oletus paksuus
fill(R,G,B,A); // Oletusväri
stroke(0);
}
void piste(float x, float y) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
strokeWeight(3);
// fill(255,0,0);
ellipse(x2,y2,10,10);
fill(R,G,B,A);
strokeWeight(2);
stroke(0);
}
void suora(float k, float b) {
float b2 = map(b,-10,10,-300,300);
for (int s=-3000; s<3000; s++) {
float y =k*(s/10.0)+b2;
ellipse((s/10.0),y,1,1);
}
}
void epayhtalo(float k, float b, String merkki, float arvo) {
float b2 = map(b,-10,10,-300,300);
for (int s=-3000; s<3000; s++) {
float y =k*(s/10.0)+b2;
ellipse((s/10.0),y,1,1);
}
float x = (arvo-b)/k;
strokeWeight(3);
if ((k == 0) && (merkki== ">")){
noStroke();
if (b > arvo) {
rect(-300,30*arvo,600,300-30*arvo);
}
}
if ((k == 0) && (merkki== "<")){
noStroke();
if (b < arvo) {
rect(-300,30*arvo,600,-300-30*arvo);
}
}
if ((k == 0) && (merkki== ">=")){
noStroke();
if (b >= arvo) {
rect(-300,30*arvo,600,300-30*arvo);
}
}
if ((k == 0) && (merkki== "<=")){
noStroke();
if (b <= arvo) {
rect(-300,30*arvo,600,-300-30*arvo);
}
}
if ((k > 0) && (merkki == "<")) {
noStroke();
rect(30*x,30*arvo,-300-30*x,-300-30*arvo);
noFill();
strokeWeight(5);
stroke(255,0,0);
ellipse(30*x,arvo*30,20,20);
line(30*x-10,30*arvo,-300,30*arvo);
}
if ((k < 0) && (merkki == "<")) {
noStroke();
rect(30*x,30*arvo,+300-30*x,-300-30*arvo);
noFill();
strokeWeight(5);
stroke(255,0,0);
ellipse(30*x,arvo*30,20,20);
line(30*x+10,30*arvo,300,30*arvo);
}
if ((k > 0) && (merkki == ">")) {
noStroke();
rect(30*x,30*arvo,300-30*x,300-30*arvo);
noFill();
strokeWeight(5);
stroke(255,0,0);
ellipse(30*x,arvo*30,20,20);
line(30*x+10,30*arvo,300,30*arvo);
}
if ((k < 0) && (merkki == ">")) {
noStroke();
rect(30*x,30*arvo,-300-30*x,300-30*arvo);
noFill();
strokeWeight(5);
stroke(255,0,0);
ellipse(30*x,arvo*30,20,20);
line(-300,arvo*30,30*x-10,arvo*30);
}
if ((k > 0) && (merkki == "<=")) {
noStroke();
rect(30*x,30*arvo,-300-30*x,-300-30*arvo);
fill(255,0,0);
strokeWeight(5);
stroke(255,0,0);
ellipse(30*x,arvo*30,20,20);
line(30*x-10,30*arvo,-300,30*arvo);
}
if ((k < 0) && (merkki == "<=")) {
noStroke();
rect(30*x,30*arvo,+300-30*x,-300-30*arvo);
fill(255,0,0);
strokeWeight(5);
stroke(255,0,0);
ellipse(30*x,arvo*30,20,20);
line(30*x+10,30*arvo,300,30*arvo);
}
if ((k > 0) && (merkki == ">=")) {
noStroke();
rect(30*x,30*arvo,300-30*x,300-30*arvo);
fill(255,0,0);
strokeWeight(5);
stroke(255,0,0);
ellipse(30*x,arvo*30,20,20);
line(30*x+10,30*arvo,300,30*arvo);
}
if ((k < 0) && (merkki == ">=")) {
noStroke();
rect(30*x,30*arvo,-300-30*x,300-30*arvo);
fill(255,0,0);
strokeWeight(5);
stroke(255,0,0);
ellipse(30*x,arvo*30,20,20);
line(-300,arvo*30,30*x-10,arvo*30);
}
strokeWeight(2);
fill(R,G,B,A);
}
void suoraXY(float x1, float y1, float x2, float y2) {
float x21 = map(x1,-10,10,-300,300);
float y21 = map(y1,-10,10,-300,300);
float x22 = map(x2,-10,10,-300,300);
float y22 = map(y2,-10,10,-300,300);
float k = ((y2-y1)/(x2-x1));
if (x1 == x2) {
line(x1*30,300,x1*30,-300);
}
for (int s=-3000; s<3000; s++) {
float y = k*(s/10.0)+(-k*x1+y1)*30;
ellipse((s/10.0),y,1,1);
}
ellipse(x21,y21,10,10);
ellipse(x22,y22,10,10);
}
void kulmakerroin(float x1, float y1, float x2, float y2) {
float k = ((y2-y1)/(x2-x1));
float x21 = map(x1,-10,10,-300,300);
float y21 = map(y1,-10,10,-300,300);
float x22 = map(x2,-10,10,-300,300);
float y22 = map(y2,-10,10,-300,300);
triangle(x21,y21,x22,y22,x22,y21);
if (x1 == x2) {
line(x1*30,300,x1*30,-300);
}
for (int s=-3000; s<3000; s++) {
float y = k*(s/10.0)+(-k*x1+y1)*30;
ellipse((s/10.0),y,1,1);
}
ellipse(x21,y21,10,10);
ellipse(x22,y22,10,10);
}
void suoranarvot(float x, float y, float k, float b) {
float x1 = map(x,-10,10,-300,300);
float y1 = map(y,-10,10,-300,300);
fill(255,255,255,200);
rect(x1,y1,105,-345);
pushMatrix();
scale(1,-1);
fill(0);
textSize(15);
text("x",x1+5,-y1+15);
text("y",x1+50,-y1+15);
for (int s=-10; s <=10; s++) {
text(s,x1+5,-y1+185+s*15);
text(""+round((k*s+b)*10)/10.0,x1+50,-y1+185+s*15);
}
popMatrix();
fill(R,G,B,A); // Oletusväri
textSize(20);
}
void paraabeli(float a, float b, float c) {
for (int s=-3000; s<3000; s++) {
float y =(a*((s/300.0)*(s/300.0))+b*(s/300.0)+c);
ellipse((s/10.0),y*30,1,1);
}
}
void polynomi(float a, float b, float c, float d) {
for (int s=-3000; s<3000; s++) {
float y = (a*(s/300.0)*(s/300.0)*(s/300.0)+b*(s/300.0)*(s/300.0)+c*(s/300.0)+d);
ellipse(s/10,y*30,1,1);
}
}
void kommentti(String teksti,float x,float y,float koko) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
fill(0);
pushMatrix();
scale(1,-1);
fill(0);
textSize(koko);
text(teksti,x2,-y2);
popMatrix();
textSize(20);
fill(R,G,B,A); // Oletusväri
}
void x(float piste) {
float x2 = map(piste,-10,10,-300,300);
fill(255,0,0);
stroke(255,0,0);
strokeWeight(5);
ellipse(x2,0,20,20);
fill(R,G,B,A);
strokeWeight(2);
}
void lukusuora(String ehto, float piste) {
float x2 = map(piste,-10,10,-300,300);
strokeWeight(5);
stroke(255,0,0);
if (ehto == "<") {
noFill();
line(-300,10,x2,10);
}
if (ehto == ">") {
noFill();
line(300,10,x2,10);
}
if (ehto == "<=") {
fill(255,0,0);
line(-300,10,x2,10);
}
if (ehto == ">=") {
fill(255,0,0);
line(300,10,x2,10);
}
if (ehto == "<=") {
fill(255,0,0);
line(-300,10,x2,10);
}
if ((ehto == "=") || (ehto == "==")) {
fill(255,0,0);
}
if ((ehto == "!=") || (ehto == "<>")) {
noFill();
line(-300,10,300,10);
}
ellipse(x2,0,20,20);
fill(R,G,B,A);
strokeWeight(2);
stroke(0);
}
void lukusuoraJA(String ehto1, float piste1, String ehto2, float piste2) {
float x1 = map(piste1,-10,10,-300,300);
float x2 = map(piste2,-10,10,-300,300);
strokeWeight(5);
stroke(255,0,0);
if ((ehto1 == ">") && (ehto2 == "<")) {
if (piste2 > piste1) {
noFill();
line(x1,10,x2,10);
ellipse(x1,0,20,20);
ellipse(x2,0,20,20);
}
}
if ((ehto1 == ">=") && (ehto2 == "<=")) {
if (piste2 >= piste1) {
fill(255,0,0);
line(x1,10,x2,10);
ellipse(x1,0,20,20);
ellipse(x2,0,20,20);
}
}
if ((ehto1 == ">=") && (ehto2 == "<")) {
if (piste2 > piste1) {
fill(255,0,0);
line(x1,10,x2,10);
ellipse(x1,0,20,20);
noFill();
ellipse(x2,0,20,20);
}
}
if ((ehto1 == ">") && (ehto2 == "<=")) {
if (piste2 > piste1) {
fill(255,0,0);
line(x1,10,x2,10);
ellipse(x2,0,20,20);
noFill();
ellipse(x1,0,20,20);
}
}
if ((ehto1 == "<") && (ehto2 == ">")) {
if (piste2 < piste1) {
noFill();
line(x1,10,x2,10);
ellipse(x1,0,20,20);
ellipse(x2,0,20,20);
}
}
if ((ehto1 == "<=") && (ehto2 == ">=")) {
if (piste2 <= piste1) {
fill(255,0,0);
line(x1,10,x2,10);
ellipse(x1,0,20,20);
ellipse(x2,0,20,20);
}
}
if ((ehto1 == "<=") && (ehto2 == ">")) {
if (piste2 < piste1) {
fill(255,0,0);
line(x1,10,x2,10);
ellipse(x1,0,20,20);
noFill();
ellipse(x2,0,20,20);
}
}
if ((ehto1 == "<") && (ehto2 == ">=")) {
if (piste2 < piste1) {
fill(255,0,0);
line(x1,10,x2,10);
ellipse(x2,0,20,20);
noFill();
ellipse(x1,0,20,20);
}
}
if (((ehto1 == "=") || (ehto1 =="==")) && (ehto2 == ">")) {
if (piste1 > piste2) {
fill(255,0,0);
ellipse(x1,0,20,20);
}
}
if (((ehto1 == "=") || (ehto1 =="==")) && (ehto2 == ">=")) {
if (piste1 >= piste2) {
fill(255,0,0);
ellipse(x1,0,20,20);
}
}
if (((ehto1 == "=") || (ehto1 =="==")) && (ehto2 == "<")) {
if (piste1 < piste2) {
fill(255,0,0);
ellipse(x1,0,20,20);
}
}
if (((ehto1 == "=") || (ehto1 =="==")) && (ehto2 == "<=")) {
if (piste1 <= piste2) {
fill(255,0,0);
ellipse(x1,0,20,20);
}
}
if ((ehto1 == ">") && ((ehto2 == "=") || (ehto2 =="=="))) {
if (piste1 < piste2) {
fill(255,0,0);
ellipse(x2,0,20,20);
}
}
if ((ehto1 == ">=") && ((ehto2 == "=") || (ehto2 =="=="))) {
if (piste1 <= piste2) {
fill(255,0,0);
ellipse(x2,0,20,20);
}
}
if ((ehto1 == "<") && ((ehto2 == "=") || (ehto2 =="=="))) {
if (piste1 > piste2) {
fill(255,0,0);
ellipse(x2,0,20,20);
}
}
if ((ehto1 == "<=") && ((ehto2 == "=") || (ehto2 =="=="))) {
if (piste1 >= piste2) {
fill(255,0,0);
ellipse(x2,0,20,20);
}
}
if (((ehto1 == "=") || (ehto1 =="==")) && ((ehto2 == "=") || (ehto2 =="=="))) {
if (piste1 == piste2) {
fill(255,0,0);
ellipse(x1,0,20,20);
}
}
if ((ehto1 == "!=") && (ehto2 == ">")) {
if (piste1 < piste2) {
noFill();
ellipse(x2,0,20,20);
line(x2,10,300,10);
} else {
noFill();
ellipse(x2,0,20,20);
ellipse(x1,0,20,20);
line(x2,10,300,10);
}
}
if ((ehto1 == "!=") && (ehto2 == ">=")) {
if (piste1 <= piste2) {
fill(255,0,0);
ellipse(x2,0,20,20);
line(x2,10,300,10);
} else {
noFill();
ellipse(x1,0,20,20);
fill(255,0,0);
ellipse(x2,0,20,20);
line(x2,10,300,10);
}
}
if ((ehto1 == "!=") && (ehto2 == "<")) {
if (piste1 < piste2) {
noFill();
ellipse(x1,0,20,20);
ellipse(x2,0,20,20);
line(x2,10,-300,10);
} else {
noFill();
ellipse(x2,0,20,20);
line(x2,10,-300,10);
}
}
if ((ehto1 == "!=") && (ehto2 == "<=")) {
if (piste1 <= piste2) {
noFill();
ellipse(x1,0,20,20);
fill(255,0,0);
ellipse(x2,0,20,20);
line(x2,10,-300,10);
} else {
fill(255,0,0);
ellipse(x2,0,20,20);
line(x2,10,-300,10);
}
}
if ((ehto1 == "!=") && (ehto2 == ">")) {
if (piste1 > piste2) {
noFill();
ellipse(x1,0,20,20);
ellipse(x2,0,20,20);
line(x2,10,300,10);
} else {
noFill();
ellipse(x2,0,20,20);
line(x2,10,300,10);
}
}
if ((ehto1 == "!=") && (ehto2 == ">=")) {
if (piste1 >= piste2) {
noFill();
ellipse(x1,0,20,20);
fill(255,0,0);
ellipse(x2,0,20,20);
line(x2,10,300,10);
} else {
fill(255,0,0);
ellipse(x2,0,20,20);
line(x2,10,300,10);
}
}
if ((ehto1 == "!=") && ((ehto2 == "=") || (ehto2 =="=="))) {
if (piste1 != piste2) {
fill(255,0,0);
ellipse(x2,0,20,20);
}
}
if (((ehto1 == "=") || (ehto1 =="==")) && (ehto2 == "!=")) {
if (piste1 != piste2) {
fill(255,0,0);
ellipse(x1,0,20,20);
}
}
fill(R,G,B,A);
strokeWeight(2);
stroke(0);
}
void lukusuoraTAI(String ehto1, float piste1, String ehto2, float piste2) {
float x1 = map(piste1,-10,10,-300,300);
float x2 = map(piste2,-10,10,-300,300);
strokeWeight(5);
stroke(255,0,0);
if ((ehto1 == "<") && (ehto2 == ">")) {
noFill();
stroke(255,0,0);
ellipse(x1,0,20,20);
line(-300,10,x1,10);
stroke(255,0,255);
line(x2,-10,300,-10);
ellipse(x2,0,20,20);
}
if ((ehto1 == "<=") && (ehto2 == ">")) {
stroke(255,0,0);
fill(255,0,0);
ellipse(x1,0,20,20);
line(-300,10,x1,10);
stroke(255,0,255);
line(x2,-10,300,-10);
noFill();
ellipse(x2,0,20,20);
}
if ((ehto1 == "<") && (ehto2 == ">=")) {
noFill();
stroke(255,0,0);
ellipse(x1,0,20,20);
line(-300,10,x1,10);
stroke(255,0,255);
line(x2,-10,300,-10);
fill(255,0,255);
ellipse(x2,0,20,20);
}
if ((ehto1 == "<=") && (ehto2 == ">=")) {
fill(255,0,0);
stroke(255,0,0);
ellipse(x1,0,20,20);
line(-300,10,x1,10);
stroke(255,0,255);
line(x2,-10,300,-10);
fill(255,0,255);
ellipse(x2,0,20,20);
}
if ((ehto1 == ">") && (ehto2 == "<")) {
noFill();
stroke(255,0,0);
line(300,10,x1,10);
ellipse(x1,0,20,20);
stroke(255,0,255);
line(x2,-10,-300,-10);
ellipse(x2,0,20,20);
}
if ((ehto1 == ">=") && (ehto2 == "<")) {
stroke(255,0,0);
line(300,10,x1,10);
fill(255,0,0);
ellipse(x1,0,20,20);
stroke(255,0,255);
line(x2,-10,-300,-10);
noFill();
ellipse(x2,0,20,20);
}
if ((ehto1 == ">") && (ehto2 == "<=")) {
noFill();
stroke(255,0,0);
ellipse(x1,0,20,20);
line(300,10,x1,10);
stroke(255,0,255);
line(x2,-10,-300,-10);
fill(255,0,255);
ellipse(x2,0,20,20);
}
if ((ehto1 == ">=") && (ehto2 == "<=")) {
fill(255,0,0);
stroke(255,0,0);
ellipse(x1,0,20,20);
line(300,10,x1,10);
stroke(255,0,255);
fill(255,0,255);
line(x2,-10,-300,-10);
ellipse(x2,0,20,20);
}
if (((ehto1 == "=") || (ehto1 == "==")) && ((ehto2 == "=") || (ehto2 == "=="))) {
stroke(255,0,0);
fill(255,0,0);
ellipse(x1,0,20,20);
fill(255,0,255);
stroke(255,0,255);
ellipse(x2,0,20,20);
}
if (((ehto1 == "=") || (ehto1 == "==")) && (ehto2 == "<")) {
stroke(255,0,0);
fill(255,0,0);
ellipse(x1,0,20,20);
noFill();
stroke(255,0,255);
ellipse(x2,0,20,20);
line(-300,10,x2,10);
}
if (((ehto1 == "=") || (ehto1 == "==")) && (ehto2 == "<=")) {
stroke(255,0,0);
fill(255,0,0);
ellipse(x1,0,20,20);
stroke(255,0,255);
line(-300,10,x2,10);
fill(255,0,255);
ellipse(x2,0,20,20);
}
if (((ehto1 == "=") || (ehto1 == "==")) && (ehto2 == ">")) {
stroke(255,0,0);
fill(255,0,0);
ellipse(x1,0,20,20);
noFill();
stroke(255,0,255);
ellipse(x2,0,20,20);
line(x2,10,300,10);
}
if (((ehto1 == "=") || (ehto1 == "==")) && (ehto2 == ">=")) {
stroke(255,0,0);
fill(255,0,0);
ellipse(x1,0,20,20);
stroke(255,0,255);
fill(255,0,255);
ellipse(x2,0,20,20);
line(x2,10,300,10);
}
if ((ehto1 == ">") && ((ehto2 == "=") || (ehto2 == "=="))) {
stroke(255,0,0);
noFill();
line(300,10,x1,10);
ellipse(x1,0,20,20);
fill(255,0,255);
stroke(255,0,255);
ellipse(x2,0,20,20);
}
if ((ehto1 == ">=") && ((ehto2 == "=") || (ehto2 == "=="))) {
stroke(255,0,0);
fill(255,0,0);
line(300,10,x1,10);
ellipse(x1,0,20,20);
fill(255,0,255);
stroke(255,0,255);
ellipse(x2,0,20,20);
}
if ((ehto1 == "<") && ((ehto2 == "=") || (ehto2 == "=="))) {
stroke(255,0,0);
noFill();
line(x1,10,-300,10);
ellipse(x1,0,20,20);
stroke(255,0,255);
fill(255,0,255);
ellipse(x2,0,20,20);
}
if ((ehto1 == "<=") && ((ehto2 == "=") || (ehto2 == "=="))) {
stroke(255,0,0);
fill(255,0,0);
line(x1,10,-300,10);
ellipse(x1,0,20,20);
fill(255,0,255);
stroke(255,0,255);
ellipse(x2,0,20,20);
}
if ((ehto1 == "!=") && (ehto2 == "!=")) {
stroke(255,0,0);
noFill();
line(300,10,-300,10);
ellipse(x1,0,20,20);
stroke(255,0,255);
line(300,-10,-300,-10);
ellipse(x2,0,20,20);
}
if ((ehto1 == "!=") && (ehto2 == "<")) {
stroke(255,0,0);
noFill();
line(-300,10,300,10);
ellipse(x1,0,20,20);
noFill();
stroke(255,0,255);
ellipse(x2,0,20,20);
line(-300,-10,x2,-10);
}
if ((ehto1 == "!=") && (ehto2 == "<=")) {
stroke(255,0,0);
noFill();
ellipse(x1,0,20,20);
line(-300,10,300,10);
stroke(255,0,255);
line(-300,-10,x2,-10);
fill(255,0,255);
ellipse(x2,0,20,20);
}
if ((ehto1 == "!=") && (ehto2 == ">")) {
stroke(255,0,0);
noFill();
ellipse(x1,0,20,20);
line(-300,10,300,10);
stroke(255,0,255);
ellipse(x2,0,20,20);
line(x2,-10,300,-10);
}
if ((ehto1 == "!=") && (ehto2 == ">=")) {
stroke(255,0,0);
noFill();
line(-300,10,300,10);
ellipse(x1,0,20,20);
stroke(255,0,255);
fill(255,0,255);
ellipse(x2,0,20,20);
line(x2,-10,300,-10);
}
if ((ehto1 == ">") && (ehto2 == "!=")) {
stroke(255,0,0);
noFill();
line(300,10,x1,10);
ellipse(x1,0,20,20);
noFill();
stroke(255,0,255);
line(-300,-10,300,-10);
ellipse(x2,0,20,20);
}
if ((ehto1 == ">=") && (ehto2 == "!=")) {
stroke(255,0,0);
fill(255,0,0);
line(300,10,x1,10);
ellipse(x1,0,20,20);
noFill();
stroke(255,0,255);
line(-300,-10,300,-10);
ellipse(x2,0,20,20);
}
if ((ehto1 == "<") && (ehto2 == "!=")) {
stroke(255,0,0);
noFill();
line(x1,10,-300,10);
ellipse(x1,0,20,20);
stroke(255,0,255);
noFill();
line(-300,-10,300,-10);
ellipse(x2,0,20,20);
}
if ((ehto1 == "<=") && (ehto2 == "!=")) {
stroke(255,0,0);
fill(255,0,0);
line(x1,10,-300,10);
ellipse(x1,0,20,20);
noFill();
stroke(255,0,255);
line(-300,-10,300,-10);
ellipse(x2,0,20,20);
}
fill(R,G,B,A);
strokeWeight(2);
stroke(0);
}
void mittaakulma(float x1, float y1, float x2, float y2, float x3, float y3) {
float xx1 = map(x1,-10,10,-300,300);
float yy1 = map(y1,-10,10,-300,300);
float xx2 = map(x2,-10,10,-300,300);
float yy2 = map(y2,-10,10,-300,300);
float xx3 = map(x3,-10,10,-300,300);
float yy3 = map(y3,-10,10,-300,300);
float sade1 = sqrt((y1-y2)*(y1-y2)+(x1-x2)*(x1-x2));
float sade2 = sqrt((y3-y2)*(y3-y2)+(x3-x2)*(x3-x2));
float kulma1 = acos(abs(x1-x2)/sade1);
float kulma2 = acos(abs(x3-x2)/sade2);
float summa1 = 0;
float summa2 = 0;
float lisays = 0;
if ( ((y1-y2) == 0) && (x1 >= x2) ) { summa1 = 0; }
if ( ((y2-y1) == 0) && (x2 > x1) ) { summa1 = 180; }
if ( ((x1-x2) == 0) && (y1 >= y2) ) { summa1 = 90; }
if ( ((x2-x1) == 0) && (y2 > y1) ) { summa1 = 270; }
if (abs(x3-x2) == 0) {
lisays = 90-degrees(kulma1);
}
if ( ((x1-x2) > 0) && ((y1 -y2) > 0) ) {
summa1 = degrees(kulma1);
}
if ( ((x1-x2) < 0) && ((y1 -y2) > 0) ) {
summa1 = (90-degrees(kulma1))+90;
}
if ( ((x1-x2) < 0) && ((y1 -y2) < 0) ) {
summa1 = degrees(kulma1)+180;
}
if ( ((x1-x2) >=0) && ((y1 -y2) < 0) ) {
summa1 = 360-degrees(kulma1);
}
if ( ((x3-x2) > 0) && ((y3 -y2) > 0) ) {
summa2 = degrees(kulma2);
if ((summa1 >= 0) && (summa1 < 90)) {
if (summa2 > summa1) {
lisays = summa2-summa1;
} else {
lisays = 360-summa1+summa2;
}
}
if ((summa1 >= 90) && (summa1 < 180)) {
lisays = 360-summa1+summa2;
}
if ((summa1 >= 180) && (summa1 < 270)) {
lisays = 360-summa1+summa2;
}
if ((summa1 >= 270) && (summa1 < 360)) {
lisays = 360-summa1+summa2;
}
}
if ( ((x3-x2) <= 0) && ((y3 -y2) >= 0) ) {
summa2 = (90-degrees(kulma2))+90;
if ((summa1 >= 0) && (summa1 < 90)) {
lisays = summa2-summa1;
}
if ((summa1 >= 90) && (summa1 < 180)) {
if (summa2 > summa1) {
lisays = summa2-summa1;
} else {
lisays = 360-summa1+summa2;
}
}
if ((summa1 >= 180) && (summa1 < 270)) {
lisays = 360-summa1+summa2;
}
if ((summa1 >= 270) && (summa1 < 360)) {
lisays = 360-summa1+summa2;
}
}
if ( ((x3-x2) <= 0) && ((y3 -y2) <= 0) ) {
summa2 = degrees(kulma2)+180;
if ((summa1 >= 0) && (summa1 < 90)) {
lisays = summa2-summa1;
}
if ((summa1 >= 90) && (summa1 < 180)) {
lisays = summa2-summa1;
}
if ((summa1 >= 180) && (summa1 < 270)) {
if (summa2 > summa1) {
lisays = summa2-summa1;
} else {
lisays = 360-summa1+summa2;
}
}
if ((summa1 >= 270) && (summa1 < 360)) {
lisays = 360-summa1+summa2;
}
}
if ( ((x3-x2) >= 0) && ((y3 -y2) <= 0) ) {
summa2 = 360-degrees(kulma2);
if ((summa1 >= 0) && (summa1 < 90)) {
lisays = summa2-summa1;
}
if ((summa1 >= 90) && (summa1 < 180)) {
lisays = summa2-summa1;
}
if ((summa1 >= 180) && (summa1 < 270)) {
lisays = summa2-summa1;
}
if ((summa1 >= 270) && (summa1 < 360)) {
if (summa2 > summa1) {
lisays = summa2-summa1;
} else {
lisays = 360-summa1+summa2;
}
}
}
float summa3 = (summa1+summa1+lisays)/2;
strokeWeight(6);
point(xx1,yy1);
point(xx2,yy2);
point(xx3,yy3);
strokeWeight(3);
line(xx2,yy2,xx1,yy1);
line(xx2,yy2,xx3,yy3);
noFill();
arc(xx2,yy2,35,35,radians(summa1),radians(summa1+lisays),PIE);
float ds = 20*(sade1 + sade2)/2;
float dx = ds*cos(radians(summa3));
float dy = ds*sin(radians(summa3));
fill(0);
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+nfc(lisays,1)+"\u00B0",xx2+dx/2,-(yy2+dy/2));
popMatrix();
strokeWeight(2);
fill(R,G,B,A);
}
void mittaajana(float x1, float y1, float x2, float y2) {
float x12 = map(x1,-10,10,-300,300);
float y12 = map(y1,-10,10,-300,300);
float x22 = map(x2,-10,10,-300,300);
float y22 = map(y2,-10,10,-300,300);
float x0 = (x12+x22)/2;
float y0 = (y12+y22)/2;
float pituus = sqrt((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1));
strokeWeight(5);
line(x12,y12,x22,y22);
strokeWeight(10);
point(x12,y12);
point(x22,y22);
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+round(10*pituus)/10.0,x0+20,-y0+20);
popMatrix();
fill(R,G,B,A);
strokeWeight(2);
stroke(0);
}
void mittaasuora(float x1, float y1,float k, float b) {
float x12 = map(x1,-10,10,-300,300);
float y12 = map(y1,-10,10,-300,300);
float b2 = map(b,-10,10,-300,300);
float x2 = -300;
float y2 = k*x2+b2;
float pituus = sqrt((y2-y12)*(y2-y12)+(x2-x12)*(x2-x12));
float x0 = 0;
float y0 = 0;
for (int s=-3000; s<3000; s++) {
float y =k*(s/10.0)+b2;
ellipse((s/10.0),y,1,1);
float y3 = k*(s/10.0)+b2;
float pituus3 = sqrt((y3-y12)*(y3-y12)+((s/10.0)-x12)*((s/10.0)-x12));
if (pituus3 < pituus) {
pituus = pituus3;
x0 = (s/10);
y0 = y3;
}
}
strokeWeight(8);
point(x12,y12);
point(x0,y0);
strokeWeight(3);
line(x12,y12,x0,y0);
fill(0);
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+round(10*(pituus/30.0))/10.0,(x0+x12)/2.0+10,-((y0+y12)/2.0)+25);
popMatrix();
strokeWeight(2);
fill(R,G,B,A);
}
void mittaakaari(float x, float y, float sade, float kulma1, float kulma2) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sade2 = map(sade,-10,10,-300,300);
noFill();
if (kulma2 < kulma1) {
float muuta = kulma1;
kulma1 = kulma2;
kulma2 = muuta;
}
arc(x2,y2,2*sade2,2*sade2,radians(kulma1),radians(kulma2));
point(x2,y2);
fill(250,200,0,150); // Oletusväri
float pituus = ((kulma2-kulma1)/360)*2*PI*sade;
float dx = 35*sade*cos(radians((kulma2+kulma1)/2.0));
float dy = 35*sade*sin(radians((kulma2+kulma1)/2.0));
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+round(10*pituus)/10.0,x2+dx,-(y2+dy));
popMatrix();
strokeWeight(2);
fill(R,G,B,A);
}
void mittaahypotenuusa(float x, float y, float a, float b) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float a2 = map(a,-10,10,-300,300);
float b2 = map(b,-10,10,-300,300);
triangle(x2,y2,x2+a2,y2,x2,y2+b2);
float pituus = sqrt(a*a+b*b);
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+round(10*pituus)/10.0,(x2+(x2+a2))/2,-(y2+(y2+b2))/2);
popMatrix();
strokeWeight(2);
fill(R,G,B,A);
}
void mittaakateetti(float x, float y, float a, float c) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float a2 = map(a,-10,10,-300,300);
float b = sqrt(c*c-a*a);
float b2 = map(b,-10,10,-300,300);
triangle(x2,y2,x2+a2,y2,x2,y2+b2);
float pituus = sqrt(c*c-a*a);
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+round(10*pituus)/10.0,x2-35,-(y2+(y2+b2))/2);
popMatrix();
strokeWeight(2);
fill(R,G,B,A);
}
void piirtokolmio(float x, float y, float kulma) {
fill(0,100,255,100);
noStroke();
float h = 150;
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
pushMatrix();
translate(x2,y2);
rotate(radians(kulma));
triangle(-h,0,h,0,0,h);
fill(0);
ellipse(0,0,5,5);
for (int s = 0; s <= 180; s = s + 10) {
float a1 = 100*cos(radians(s));
float b1 = 100*sin(radians(s));
float a2 = 50*cos(radians(s));
float b2 = 50*sin(radians(s));
stroke(0,0,255);
strokeWeight(1);
line(a1,b1,a2,b2);
}
for (int s = 0; s <= 180; s = s + 5) {
float a1 = 100*cos(radians(s));
float b1 = 100*sin(radians(s));
float a2 = 90*cos(radians(s));
float b2 = 90*sin(radians(s));
stroke(0);
strokeWeight(1);
line(a1,b1,a2,b2);
}
for (int s = 0; s <= 180; s = s + 45) {
float a1 = 100*cos(radians(s));
float b1 = 100*sin(radians(s));
float a2 = 20*cos(radians(s));
float b2 = 20*sin(radians(s));
stroke(255,0,0);
strokeWeight(1);
line(a1,b1,a2,b2);
}
popMatrix();
stroke(0);
fill(R,G,B,A);
strokeWeight(2); // Oletus paksuus
}
void viivoitin(float x, float y, float kulma) {
fill(100,255,100,100);
noStroke();
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
pushMatrix();
translate(x2,y2);
rotate(radians(kulma));
rect(0,0,300,30);
fill(0);
ellipse(0,0,5,5);
for (int s=0; s <= 20; s=s+1) {
stroke(0);
strokeWeight(1);
line(s*15,0,s*15,10);
}
for (int s=0; s <= 10; s=s+1) {
stroke(0,0,255);
strokeWeight(1);
line(s*30,0,s*30,20);
}
for (int s=0; s <= 100; s=s+1) {
stroke(255,0,255);
strokeWeight(1);
line(s*3,0,s*3,5);
}
popMatrix();
stroke(0);
fill(R,G,B,A);
strokeWeight(2); // Oletus paksuus
}
3D-geometrian funktiot (Tämä kirjasto sopii iPAD:lle)
Tämä kirjasto sisältää seuraavat komennot
- Kartio
- Koordinaatisto
- Kommentti
- Lieriö
- Mittaa-funktiot
- Pallo
- Piirtokolmio
- Piste
- Pyramidi
- Särmiö
- Viivoitin
// Ohjelman tehnyt e-Oppi Oy, 3D-Geometrian funktiot
// Viimeksi päivitetty: 31.8.2017
// Oletus täyttöväri
int R =250; // Oletus punainen
int G = 200; // Oletus vihreä
int B = 0; // Oletus sininen
int A = 100; // Oletus läpinäkyvyys
void setup () {
size(601,601); // Älä muuta ikkunan kokoa
}
// Kaikki komennot laitetaan void draw ()-lohkoon
void draw () {
koordinaatisto();
// Kirjoita tähän kaikki komennot
}
// Tästä alkaa funktiot eli aliohjelmat
// Älä tee näihin muutoksia !!
// Koordinaatisto on suunniteltu 600x600 ikkunaan
void koordinaatisto() {
fill(255);
noStroke();
rect(0,0,600,600);
stroke(128);
strokeWeight(1);
for (int z = 0; z < 21; z++) {
line(z*30,0,z*30,600);
line(0,0+z*30,600,z*30);
}
strokeWeight(3);
stroke(0,0,100);
line(300,3,300,600);
line(0,300,600,300);
fill(0,0,100);
triangle(590,290,598,300,590,310);
triangle(300,3,310,10,290,10);
text("x",580,285);
text("y",315,20);
textSize(20);
text("1",323,320);
text("1",280,280);
translate(300,300);
scale(1,-1);
strokeWeight(2); // Oletus paksuus
fill(R,G,B,A); // Oletusväri
stroke(0);
}
void piste(float x, float y) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
strokeWeight(3);
// fill(255,0,0);
ellipse(x2,y2,10,10);
fill(R,G,B,A);
strokeWeight(2);
stroke(0);
}
void sarmio(float x, float y, float a, float b, float c) {
float x1 = map(x,-10,10,-300,300);
float y1 = map(y,-10,10,-300,300);
float a1 = map(a,-10,10,-300,300);
float b1 = map(b,-10,10,-300,300)/2.0;
float c1 = map(c,-10,10,-300,300);
float dx = b1*cos(radians(45));
float dy = b1*sin(radians(45));
quad(x1,y1,x1+dx,y1+dy,x1+dx,y1+c1+dy,x1,y1+c1);
quad(x1,y1,x1+dx,y1+dy,x1+a1+dx,y1+dy,x1+a1,y1);
quad(x1+dx,y1+dy,x1+a1+dx,y1+dy,x1+a1+dx,y1+c1+dy,x1+dx,y1+c1+dy);
rect(x1,y1,a1,c1);
quad(x1+a1,y1,x1+a1+dx,y1+dy,x1+a1+dx,y1+c1+dy,x1+a1,y1+c1);
quad(x1+a1+dx,y1+c1+dy,x1+a1,y1+c1,x1,y1+c1,x1+dx,y1+c1+dy);
}
void kartio(float x, float y, float r, float h) {
float x1 = map(x,-10,10,-300,300);
float y1 = map(y,-10,10,-300,300);
float r1 = map(r,-10,10,-300,300);
float h1 = map(h,-10,10,-300,300);
strokeWeight(2);
stroke(R,G,B,A);
for (int s= 0; s <= 360; s++) {
float xx = x1+r1*cos(radians(s));
float yy = y1+r1/2*sin(radians(s));
line(x1,y1+h1,xx,yy);
}
stroke(0);
strokeWeight(3);
ellipse(x1,y1,r1*2,r1);
noFill();
triangle(x1,y1,x1+r1,y1,x1,y1+h1);
triangle(x1,y1,x1-r1,y1,x1,y1+h1);
fill(R,G,B,A);
}
void lierio(float x, float y, float r, float h) {
float x1 = map(x,-10,10,-300,300);
float y1 = map(y,-10,10,-300,300);
float r1 = map(r,-10,10,-300,300);
float h1 = map(h,-10,10,-300,300);
fill(R,G,B,A);
strokeWeight(3);
stroke(R,G,B,A);
for (int s= 0; s <= 360; s++) {
float xx = x1+r1*cos(radians(s));
float yy = y1+r1/2*sin(radians(s));
line(xx,yy,xx,yy+h1);
}
noFill();
stroke(0);
ellipse(x1,y1,r1*2,r1);
rect(x1-r1,y1,r1,h1);
rect(x1,y1,r1,h1);
stroke(0);
fill(R,G,B,A);
strokeWeight(3);
ellipse(x1,y1+h1,r1*2,r1);
}
void pyramidi(float x, float y, float r, float h) {
float x1 = map(x,-10,10,-300,300);
float y1 = map(y,-10,10,-300,300);
float r1 = map(r,-10,10,-300,300);
float h1 = map(h,-10,10,-300,300);
float dx = (r1/2.0)*cos(radians(45));
float dy = (r1/2.0)*sin(radians(45));
noFill();
quad(x1-r1-dx,y1-dy,x1+r1-dx,y1-dy,x1+r1+dx,y1+dy,x1-r1+dx,y1+dy);
fill(R,G,B,A);
triangle(x1+r1+dx,y1+dy,x1-r1+dx,y1+dy,x1,y1+h1);
line(x1,y1,x1,y1+h1);
line(x1,y1,x1+r1,y1);
line(x1,y1+h1,x1+r1,y1);
triangle(x1-r1-dx,y1-dy,x1-r1+dx,y1+dy,x1,y1+h1);
triangle(x1+r1-dx,y1-dy,x1+r1+dx,y1+dy,x1,y1+h1);
triangle(x1-r1-dx,y1-dy,x1+r1-dx,y1-dy,x1,y1+h1);
}
void pallo(float x, float y, float r) {
float x1 = map(x,-10,10,-300,300);
float y1 = map(y,-10,10,-300,300);
float r1 = map(r,-10,10,-300,300);
ellipse(x1,y1,2*r1,2*r1);
noFill();
ellipse(x1,y1,2*r1,r1);
line(x1-r1,y1,x1+r1,y1);
line(x1,y1,x1,y1+r1);
fill(R,G,B,A);
}
void sarmiok(float x, float y, float a,float b, float h) {
float x1 = map(x,-10,10,-300,300);
float y1 = map(y,-10,10,-300,300);
float a1 = map(a,-10,10,-300,300);
// float b1 = map(b,-10,10,-300,300);
float h1 = map(h,-10,10,-300,300);
float kulma = atan(a/b);
float xx = b*30*cos(kulma);
float yy =b*30*sin(kulma)/2.0;
if (h < 0) {
fill(R,G,B,A);
} else {
noFill();
}
rect(x1,y1,a1,h1);
triangle(x1,y1,x1+a1,y1,x1+xx,y1-yy);
fill(R,G,B,A);
triangle(x1,y1+h1,x1+a1,y1+h1,x1+xx,y1+h1-yy);
quad(x1,y1,x1+xx,y1-yy,x1+xx,y1+h1-yy,x1,y1+h1);
quad(x1+a1,y1,x1+xx,y1-yy,x1+xx,y1+h1-yy,x1+a1,y1+h1);
}
void kommentti(String teksti,float x,float y,float koko) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
fill(0);
pushMatrix();
scale(1,-1);
fill(0);
textSize(koko);
text(teksti,x2,-y2);
popMatrix();
textSize(20);
fill(R,G,B,A); // Oletusväri
}
void mittaakulma(float x1, float y1, float x2, float y2, float x3, float y3) {
float xx1 = map(x1,-10,10,-300,300);
float yy1 = map(y1,-10,10,-300,300);
float xx2 = map(x2,-10,10,-300,300);
float yy2 = map(y2,-10,10,-300,300);
float xx3 = map(x3,-10,10,-300,300);
float yy3 = map(y3,-10,10,-300,300);
float sade1 = sqrt((y1-y2)*(y1-y2)+(x1-x2)*(x1-x2));
float sade2 = sqrt((y3-y2)*(y3-y2)+(x3-x2)*(x3-x2));
float kulma1 = acos(abs(x1-x2)/sade1);
float kulma2 = acos(abs(x3-x2)/sade2);
float summa1 = 0;
float summa2 = 0;
float lisays = 0;
if ( ((y1-y2) == 0) && (x1 >= x2) ) { summa1 = 0; }
if ( ((y2-y1) == 0) && (x2 > x1) ) { summa1 = 180; }
if ( ((x1-x2) == 0) && (y1 >= y2) ) { summa1 = 90; }
if ( ((x2-x1) == 0) && (y2 > y1) ) { summa1 = 270; }
if (abs(x3-x2) == 0) {
lisays = 90-degrees(kulma1);
}
if ( ((x1-x2) > 0) && ((y1 -y2) > 0) ) {
summa1 = degrees(kulma1);
}
if ( ((x1-x2) < 0) && ((y1 -y2) > 0) ) {
summa1 = (90-degrees(kulma1))+90;
}
if ( ((x1-x2) < 0) && ((y1 -y2) < 0) ) {
summa1 = degrees(kulma1)+180;
}
if ( ((x1-x2) >=0) && ((y1 -y2) < 0) ) {
summa1 = 360-degrees(kulma1);
}
if ( ((x3-x2) > 0) && ((y3 -y2) > 0) ) {
summa2 = degrees(kulma2);
if ((summa1 >= 0) && (summa1 < 90)) {
if (summa2 > summa1) {
lisays = summa2-summa1;
} else {
lisays = 360-summa1+summa2;
}
}
if ((summa1 >= 90) && (summa1 < 180)) {
lisays = 360-summa1+summa2;
}
if ((summa1 >= 180) && (summa1 < 270)) {
lisays = 360-summa1+summa2;
}
if ((summa1 >= 270) && (summa1 < 360)) {
lisays = 360-summa1+summa2;
}
}
if ( ((x3-x2) <= 0) && ((y3 -y2) >= 0) ) {
summa2 = (90-degrees(kulma2))+90;
if ((summa1 >= 0) && (summa1 < 90)) {
lisays = summa2-summa1;
}
if ((summa1 >= 90) && (summa1 < 180)) {
if (summa2 > summa1) {
lisays = summa2-summa1;
} else {
lisays = 360-summa1+summa2;
}
}
if ((summa1 >= 180) && (summa1 < 270)) {
lisays = 360-summa1+summa2;
}
if ((summa1 >= 270) && (summa1 < 360)) {
lisays = 360-summa1+summa2;
}
}
if ( ((x3-x2) <= 0) && ((y3 -y2) <= 0) ) {
summa2 = degrees(kulma2)+180;
if ((summa1 >= 0) && (summa1 < 90)) {
lisays = summa2-summa1;
}
if ((summa1 >= 90) && (summa1 < 180)) {
lisays = summa2-summa1;
}
if ((summa1 >= 180) && (summa1 < 270)) {
if (summa2 > summa1) {
lisays = summa2-summa1;
} else {
lisays = 360-summa1+summa2;
}
}
if ((summa1 >= 270) && (summa1 < 360)) {
lisays = 360-summa1+summa2;
}
}
if ( ((x3-x2) >= 0) && ((y3 -y2) <= 0) ) {
summa2 = 360-degrees(kulma2);
if ((summa1 >= 0) && (summa1 < 90)) {
lisays = summa2-summa1;
}
if ((summa1 >= 90) && (summa1 < 180)) {
lisays = summa2-summa1;
}
if ((summa1 >= 180) && (summa1 < 270)) {
lisays = summa2-summa1;
}
if ((summa1 >= 270) && (summa1 < 360)) {
if (summa2 > summa1) {
lisays = summa2-summa1;
} else {
lisays = 360-summa1+summa2;
}
}
}
float summa3 = (summa1+summa1+lisays)/2;
strokeWeight(6);
point(xx1,yy1);
point(xx2,yy2);
point(xx3,yy3);
strokeWeight(3);
line(xx2,yy2,xx1,yy1);
line(xx2,yy2,xx3,yy3);
noFill();
arc(xx2,yy2,35,35,radians(summa1),radians(summa1+lisays),PIE);
float ds = 20*(sade1 + sade2)/2;
float dx = ds*cos(radians(summa3));
float dy = ds*sin(radians(summa3));
fill(0);
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+nfc(lisays,1)+"\u00B0",xx2+dx/2,-(yy2+dy/2));
popMatrix();
strokeWeight(2);
fill(R,G,B,A);
}
void mittaajana(float x1, float y1, float x2, float y2) {
float x12 = map(x1,-10,10,-300,300);
float y12 = map(y1,-10,10,-300,300);
float x22 = map(x2,-10,10,-300,300);
float y22 = map(y2,-10,10,-300,300);
float x0 = (x12+x22)/2;
float y0 = (y12+y22)/2;
float pituus = sqrt((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1));
strokeWeight(5);
line(x12,y12,x22,y22);
strokeWeight(10);
point(x12,y12);
point(x22,y22);
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+round(10*pituus)/10.0,x0+20,-y0+20);
popMatrix();
fill(R,G,B,A);
strokeWeight(2);
stroke(0);
}
void mittaasuora(float x1, float y1,float k, float b) {
float x12 = map(x1,-10,10,-300,300);
float y12 = map(y1,-10,10,-300,300);
float b2 = map(b,-10,10,-300,300);
float x2 = -300;
float y2 = k*x2+b2;
float pituus = sqrt((y2-y12)*(y2-y12)+(x2-x12)*(x2-x12));
float x0 = 0;
float y0 = 0;
for (int s=-3000; s<3000; s++) {
float y =k*(s/10.0)+b2;
ellipse((s/10.0),y,1,1);
float y3 = k*(s/10.0)+b2;
float pituus3 = sqrt((y3-y12)*(y3-y12)+((s/10.0)-x12)*((s/10.0)-x12));
if (pituus3 < pituus) {
pituus = pituus3;
x0 = (s/10);
y0 = y3;
}
}
strokeWeight(8);
point(x12,y12);
point(x0,y0);
strokeWeight(3);
line(x12,y12,x0,y0);
fill(0);
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+round(10*(pituus/30.0))/10.0,(x0+x12)/2.0+10,-((y0+y12)/2.0)+25);
popMatrix();
strokeWeight(2);
fill(R,G,B,A);
}
void mittaakaari(float x, float y, float sade, float kulma1, float kulma2) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float sade2 = map(sade,-10,10,-300,300);
noFill();
if (kulma2 < kulma1) {
float muuta = kulma1;
kulma1 = kulma2;
kulma2 = muuta;
}
arc(x2,y2,2*sade2,2*sade2,radians(kulma1),radians(kulma2));
point(x2,y2);
fill(250,200,0,150); // Oletusväri
float pituus = ((kulma2-kulma1)/360)*2*PI*sade;
float dx = 35*sade*cos(radians((kulma2+kulma1)/2.0));
float dy = 35*sade*sin(radians((kulma2+kulma1)/2.0));
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+round(10*pituus)/10.0,x2+dx,-(y2+dy));
popMatrix();
strokeWeight(2);
fill(R,G,B,A);
}
void mittaahypotenuusa(float x, float y, float a, float b) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float a2 = map(a,-10,10,-300,300);
float b2 = map(b,-10,10,-300,300);
triangle(x2,y2,x2+a2,y2,x2,y2+b2);
float pituus = sqrt(a*a+b*b);
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+round(10*pituus)/10.0,(x2+(x2+a2))/2,-(y2+(y2+b2))/2);
popMatrix();
strokeWeight(2);
fill(R,G,B,A);
}
void mittaakateetti(float x, float y, float a, float c) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float a2 = map(a,-10,10,-300,300);
float b = sqrt(c*c-a*a);
float b2 = map(b,-10,10,-300,300);
triangle(x2,y2,x2+a2,y2,x2,y2+b2);
float pituus = sqrt(c*c-a*a);
pushMatrix();
scale(1,-1);
fill(255,0,0);
text(""+round(10*pituus)/10.0,x2-35,-(y2+(y2+b2))/2);
popMatrix();
strokeWeight(2);
fill(R,G,B,A);
}
void piirtokolmio(float x, float y, float kulma) {
fill(0,100,255,100);
noStroke();
float h = 150;
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
pushMatrix();
translate(x2,y2);
rotate(radians(kulma));
triangle(-h,0,h,0,0,h);
fill(0);
ellipse(0,0,5,5);
for (int s = 0; s <= 180; s = s + 10) {
float a1 = 100*cos(radians(s));
float b1 = 100*sin(radians(s));
float a2 = 50*cos(radians(s));
float b2 = 50*sin(radians(s));
stroke(0,0,255);
strokeWeight(1);
line(a1,b1,a2,b2);
}
for (int s = 0; s <= 180; s = s + 5) {
float a1 = 100*cos(radians(s));
float b1 = 100*sin(radians(s));
float a2 = 90*cos(radians(s));
float b2 = 90*sin(radians(s));
stroke(0);
strokeWeight(1);
line(a1,b1,a2,b2);
}
for (int s = 0; s <= 180; s = s + 45) {
float a1 = 100*cos(radians(s));
float b1 = 100*sin(radians(s));
float a2 = 20*cos(radians(s));
float b2 = 20*sin(radians(s));
stroke(255,0,0);
strokeWeight(1);
line(a1,b1,a2,b2);
}
popMatrix();
stroke(0);
fill(R,G,B,A);
strokeWeight(2); // Oletus paksuus
}
void viivoitin(float x, float y, float kulma) {
fill(100,255,100,100);
noStroke();
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
pushMatrix();
translate(x2,y2);
rotate(radians(kulma));
rect(0,0,300,30);
fill(0);
ellipse(0,0,5,5);
for (int s=0; s <= 20; s=s+1) {
stroke(0);
strokeWeight(1);
line(s*15,0,s*15,10);
}
for (int s=0; s <= 10; s=s+1) {
stroke(0,0,255);
strokeWeight(1);
line(s*30,0,s*30,20);
}
for (int s=0; s <= 100; s=s+1) {
stroke(255,0,255);
strokeWeight(1);
line(s*3,0,s*3,5);
}
popMatrix();
stroke(0);
fill(R,G,B,A);
strokeWeight(2); // Oletus paksuus
}
void kartiomoni(float x, float y, float sade, float h, float lukumaara, float alkukulma) {
if (lukumaara > 0) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float h2 = map(h,-10,10,-300,300);
if (lukumaara == 1) {
ellipse(x2,y2,5,5);
} else {
float lisays = 360.0/lukumaara;
float kulma0 = alkukulma;
float x1 = sade*30*cos(radians(kulma0));
float y1 = sade*30*sin(radians(kulma0))/2.0;
line(x2,y2,x2+x1,y2+y1);
float kulma = alkukulma+lisays;
beginShape();
for (int s = 0; s < lukumaara; s++) {
x1 = sade*30*cos(radians(kulma));
y1 = sade*30*sin(radians(kulma))/2.0;
vertex(x2+x1,y2+y1);
kulma = kulma+lisays;
float x3 = sade*30*cos(radians(kulma));
float y3 = sade*30*sin(radians(kulma))/2.0;
triangle(x2+x1,y2+y1,x2,y2+h2,x2+x3,y2+y3);
}
endShape();
line(x2,y2,x2,y2+h2);
}
}
}
void lieriomoni(float x, float y, float sade, float h, float lukumaara, float alkukulma) {
if (lukumaara > 0) {
float x2 = map(x,-10,10,-300,300);
float y2 = map(y,-10,10,-300,300);
float h2 = map(h,-10,10,-300,300);
if (lukumaara == 1) {
ellipse(x2,y2,5,5);
} else {
float lisays = 360.0/lukumaara;
float kulma0 = alkukulma;
float x1 = sade*30*cos(radians(kulma0));
float y1 = sade*30*sin(radians(kulma0))/2.0;
line(x2,y2,x2+x1,y2+y1);
line(x2,y2+h2,x2+x1,y2+y1+h2);
float kulma = alkukulma+lisays;
beginShape();
for (int s = 0; s < lukumaara; s++) {
x1 = sade*30*cos(radians(kulma));
y1 = sade*30*sin(radians(kulma))/2.0;
vertex(x2+x1,y2+y1);
kulma = kulma+lisays;
float x3 = sade*30*cos(radians(kulma));
float y3 = sade*30*sin(radians(kulma))/2.0;
quad(x2+x1,y2+y1,x2+x3,y2+y3,x2+x3,y2+y3+h2,x2+x1,y2+y1+h2);
}
endShape();
line(x2,y2,x2,y2+h2);
}
}
}