Hi, I'm trying to write a code to make convex polygon tesellations. I have just started, and I'm having problems regarding finding a point on a circumference (over its perimeter).
As the image shows, I have 4 points and 2 circumferences.
p1 is the center of circumference 1
p2 is the center of circumference 2
p3 is a point wich controls the radius of circumference 1 (therefore, it's contained in its perimeter)
p4 is the one giving me troubles; this point should control the circumference 2 radius (they are not linked yet, but it doesn't matter now). this point should be at an 120º angle with p3.
in order to do that, i calculated the gradient of the segment p1_p3. Having that, I used the atan() function to get its angle in radians (I assume it's the angle between that segment and an horizontal one). After that, I converted the angle from radians to degrees, and I used it to find the (x,y) coordinates over the circumference using trigonometric equations.
The problem is that p4, wich in the image is at 120º from p3, goes from that to 60º, depending on the value of the angle calculation based on the p1_p3 segment. And I would like it to be allways 120º... I'm sorry I can't be more specific, my english is not good, specially in math specialized terms.
Here is the code, highlighting the part regarding my issues.
- // GLOBAL VARIABLES
- float Radio1 = 300;
- float RadioVariable1;
- // Coordenadas Punto Móvil 1 (centro Circulo 1)
- float Pto1X;
- float Pto1Y;
- float NewPto1X = 0.0;
- float NewPto1Y = 0.0;
- //Coordenadas Punto Móvil 2 (centro Circulo 2)
- float Pto2X;
- float Pto2Y;
- float NewPto2X;
- float NewPto2Y;
- //Coordenadas Punto Móvil 3 (Determina Radio Circulo 1)
- float Pto3X;
- float Pto3Y;
- float NewPto3X;
- float NewPto3Y;
- //Booleanas
- boolean locked1 = false;
- boolean over1 = false;
- boolean locked2 = false;
- boolean over2 = false;
- boolean locked3 = false;
- boolean over3 = false;
- void setup () {
- size (800,600);
- Pto1X = width/2.0;
- Pto1Y = height/2.0;
- Pto2X = width/1.5;
- Pto2Y = height/2.0;
- Pto3X = height/1.1;
- Pto3Y = width /2.0;
- smooth();
- }
- void draw () {
- background (0);
- // Circulo 1
- if (pow(mouseX - Pto1X, 2) + pow(mouseY - Pto1Y, 2) <= pow(2,5)) {
- over1 = true;
- if (!locked1) {
- fill (255);
- stroke (255,0,0);
- }
- }
- else {
- fill (255);
- stroke (255);
- over1 = false;
- }
- RadioVariable1 = sqrt(pow(Pto1X - Pto3X,2)+ pow(Pto1Y - Pto3Y,2));
- ellipse (Pto1X, Pto1Y, 10, 10);
- Circulo (Pto1X, Pto1Y, RadioVariable1*2, RadioVariable1*2);
- //Circulo 2
- if (pow(mouseX - Pto2X, 2) + pow(mouseY - Pto2Y, 2) <= pow(2,5)) {
- over2 = true;
- if (!locked2) {
- fill (255);
- stroke (255,0,0);
- }
- }
- else {
- fill (255);
- stroke (255);
- over2 = false;
- }
- ellipse (Pto2X, Pto2Y, 10, 10);
- Circulo (Pto2X, Pto2Y, Radio1, Radio1);
- //Circulo 3
- if (pow(mouseX - Pto3X, 2) + pow(mouseY - Pto3Y, 2) <= pow(2,5)) {
- over3 = true;
- if (!locked3) {
- fill (255);
- stroke (255,0,0);
- }
- }
- else {
- fill (255);
- stroke (255);
- over3 = false;
- }
- // Calculo Pendiente
- float M = (Pto1X - Pto3X) / (Pto1Y - Pto3Y);
- float preAnguloRad = atan (M);
- float preAnguloDeg = preAnguloRad*(180/3.14159265);
- float Angulo = 330 - preAnguloDeg;
- println (preAnguloDeg);
- float Pto4X = Pto1X + cos(radians(Angulo)) * RadioVariable1;
- float Pto4Y = Pto1Y + sin(radians(Angulo)) * RadioVariable1;
- ellipse (Pto3X, Pto3Y, 10, 10);
- ellipse (Pto4X, Pto4Y, 10,10);
- translate (width - Pto1X, height - Pto1Y);
- }
- void mousePressed () {
- if (over1) {
- locked1 = true;
- fill (255);
- }
- else {
- locked1 = false;
- }
- if (over2) {
- locked2 = true;
- fill (255);
- }
- else {
- locked2 = false;
- }
- if (over3) {
- locked3 = true;
- fill (255);
- }
- else {
- locked3 = false;
- }
- NewPto1X = mouseX - Pto1X;
- NewPto1Y = mouseY - Pto1Y;
- NewPto2X = mouseX - Pto2X;
- NewPto2Y = mouseY - Pto2Y;
- NewPto3X = mouseX - Pto3X;
- NewPto3Y = mouseY - Pto3Y;
- }
- void mouseDragged() {
- if (locked1) {
- Pto1X = mouseX - NewPto1X;
- Pto1Y = mouseY - NewPto1Y;
- }
- if (locked2) {
- Pto2X = mouseX - NewPto2X;
- Pto2Y = mouseY - NewPto2Y;
- }
- if (locked3) {
- Pto3X = mouseX - NewPto3X;
- Pto3Y = mouseY - NewPto3Y;
- }
- }
- void mouseReleased(){
- locked1 = false;
- locked2 = false;
- locked3 = false;
- }
- void Circulo (float x,float y,float r1,float r2){
- noFill();
- stroke (255);
- ellipse (x,y,r1,r2);
- }
Thanks in advance.
1