Loading...
Logo
Processing Forum
Ok so stupid question, but I'm going to ask it because my googling hasn't turned up anything and I'm hoping for an easy answer.

Is there a quick/easy way to find out if (regardless of transformations, scaling, skewing, etc) a point/line is successfully drawn? I'm working in 2D and it'd be a great shortcut for what I'm doing.

I'm just looking for a boolean value (true if drawn, false if failed to draw).

for example:

point(-1,-1) on untransformed coordinates would return false

any ideas?

Replies(2)

I don't see why Processing would fail to draw... But I see what you mean, basically you want to see if a point falls inside the drawing surface of the sketch. It might be possible to answer for a point, it is harder for a line, which can have both ends outside of the sketch's surface and yet have a visible part...
I am not sure why you need this info, actually.
There is modelX() and modelY(), but I think they don't work in 2D.
If you don't mind (very) slow speed, you can compare the pixels[] array before and after drawing...
Basically I've got a dynamic system being drawn which I want to auto-zoom as things leave the viewing area. I've got the zoom thing set up and I can look at the locations of the particles, but I'm failing at coming up with a simple equation to check if a point is on the screen (after the transformations used to zoom).

I've got one that works for positive numbers, but it breaks for negative.

I do the following to zoom:

g.translate(viewWidth/2,viewHeight/2);
g.scale(scaleFactor);
g.translate(-viewWidth/2,-viewHeight/2);

I don't think I fully understand what the scale function does, and I'd prefer not to have to check each point in a loop to calculate their new location after those transformations, but I will if it's the only way.

I've tried running a check equation like
scaleY = ((particles[i].position.y+(viewHeight/2))/zoomFactor)-(viewHeight/2);
then checking the boundries 0,viewHeight but it seems to break on negative numbers (it just keeps zooming out). Also, it doesn't appear to work at all when I zoom in manually (at which point it should auto-zoom back out).

Hope this clarifies my intentions!

Suggestions/ideas are welcome.