Lines intersecting a square.........
in
Programming Questions
•
1 year ago
Hi all,
I would like to ask if anyone knows how can I make the lines only to reach the edges of the square? Without going over the edges.....
to draw the red lines I am using a boolean......
boolean intersect(PVector h, PVector g, PVector j)
{
// if(a.x>100 && a.y<-100 && b.x<200 && b.y>-200)
if((h.x>100 && h.x<200 && h.y<-100 &&h.y>-200) ||( g.x>100 && g.x<200 && g.y<-100 &&g.y>-200)||
(j.x>100 && j.x<200 && j.y<-100 &&j.y>-200))
{
return true;
} else return false;
and then calling it in my void draw Triangle()
void drawTriangle(PVector A, PVector B, PVector C)
{
triangle(A.x, A.y, B.x, B.y, C.x, C.y);
if(intersect(A,B,C)){
stroke(255,0,0);
line(A.x,A.y,B.x,B.y);
}
if(intersect(B,C,A)){
stroke(255,0,0);
line(B.x,B.y,C.x,C.y);
}
if(intersect(A,C,B)){
stroke(255,0,0);
line(A.x,A.y,C.x,C.y);
}
}
I draw my square like this.............
void rectangle()
{
strokeWeight(3);
stroke(255, 0, 0);
beginShape();
vertex(100, -100);
vertex(100, -200);
vertex(200, -200);
vertex(200, -100);
endShape(CLOSE);
}
any guidance?
Much appreciate it ;)))))
1