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
}