find distance to edge
in
Programming Questions
•
1 year ago
How can i find the distance to the edge pointing from the center in the direction of the mouse?
or... check bottom post
- PVector center;
- void setup() {
- size(400, 400);
- smooth();
- center = new PVector(width/2, height/2);
- }
- // . . . . . . . . . . . . . . . . . . .
- void draw() {
- background(255);
- ellipse(center.x, center.y, 5, 5);
- line(mouseX, mouseY, center.x, center.y);
- float d1 = dist(mouseX, 0, center.x, center.y);
- float d2 = dist(0, mouseY, center.x, center.y);
- float d = (d1+d2)/2;
- translate(center.x, center.y);
- float a = atan2(mouseY - center.y, mouseX - center.x );
- rotate(a);
- line(d, 0, 0, 0);
- }
- // . . . . . . . . . . . . . . . . . . .
if i have a grid float[][]
[][][][][][][][][][][][]
[][][][][][][][][][][][]
[][][][][][][][][][][][]
[][][][][][][][][][][][]
[][][][][][][][][][][][]
[][][][][][][][][][][][]
[][][][][][][][][][][][]
then i want to know the distance between the center and any other index to the edge.
For example:
c = center of 2d array
i = index
p = what i'm interested in since it's the edge in the direction c i.
[][][p][][][][][][][][][]
[][][][][][][][][][][][]
[][][][][i][][][][][][][]
[][][][][][][c][][][][][]
[][][][][][][][][][][][]
[][][][][][][][][][][][]
[][][][][][][][][][][][]
1