I am trying to draw an interactive planar straight line graph (PSLG) on a JApplet. I am using mouse-clicks to determine the vertices of the PSLG.
Here is the algorithm which I am following for drawing edges of the PSLG
1. The point where user performs a mouse-click is added as a vertex of the PSLG.
2. If he clicks a second point,an edge is directly created among the point and the previously clicked-point
Here are certain flaws which I observed due to the use of this algorithm:
Inability to create disjoint-planar sets like say just a line segment
A closed polygon is only created if the user clicks at the exact location where the start point was [Essentially, if the user clicks very close to the start point, there is no way to tell that this point is actually the start point since it appears within a certain tolerance range from the point].
I've checked out some similar questions over here and people suggest to use the JFreeChart library. But as far as I get, the scenario in those questions was that the points of the PSLG were already known. I do not know whether JFreeChart can be used for creating interactive PSLG's
I thought about adding points and having a button which would say add edges among points,but if that's the case selecting the 2 points will still involve the proximity problem encountered in 2.
I was wondering if anybody could suggest me a better approach on how to handle this situation.
Thanks in advance
GraphPanel could be adapted to this task, although it might benefit from a more advanced edge model for faster searching. Also consider JGraph.
Related
I was trying to generate the human like mouse movement. While finding the correct model I come to know about Fitts's law.
You can read more about the law and the reason behind the mathematical model of it here. I want to generate the human like mouse pointer data given distance between source to target and width of target object.
I am not able to come up with the good model to find the radius of circle of error and position and number of circle of error explained in the below image.
Also I am planning to use Bézier curve to achieve random curves in intermediate stages.
I believe the solution of the problem contains following steps
1) Find out the time going to take for the whole interaction, (after removing some initial extra waiting time ) using Fitts's Law.
2) Based on time and distance find the number of circle of error, and using that number also find the decreasing radius of each circle. One of the possible approach is to use log function.
3) Find out position of each circle which is random but still in the intended direction. This is one of the most confusing task. There are many possibilities but there is few particular model behind where circle of errors are placed.
4) Find out the random points inside the circle but still in intended direction.
5) Pass the (Time, X,Y) triplets to MouseMove function of selenium
I am not sure how to achieve step 3,4 and 5.
Preferred language to achieve this is Java using selenium.
So I have to create a project in java and I need steps on how to consider thinking about the problem.
Its a GUI related project. What is required is that there are two objects that a user would place on the screen window(imagine them like rectangles on the screen).
And these rectangle objects have connector points. One point on the middle of each side of the rectangle(Hope that made sense). And the user will choose one point in each rectangle and my program will have to find a path between those two connector points. There could be obstacles like other rectangles between those two rectangles or walls.
So I am thinking I could use a path finding algorithm(like A*) to find a path between the two points but that's all I could figure out till now.
I need help on how to think about this problem especially with the GUI part.
Also the problem also requires that the number of turns be minimum. But I think I could work on that later. But if you've got an idea please share it here
Thank you so much in advance
So I'm doing the project of an introduction to Java course and it seems that I chose something that goes way beyond what I'm able to do. :P
Any help would be greatly appreciated. This is what I'm having problems with:
You have a cursor that is controlled by a player (goes forward or
turns 90°) which leaves a colored line as it goes. If you manage to go
over your own line and close a polygon of any shape (only right angles
though), its surface changes color into the color of your line.
I can detect when this situation arises but I am kind of lost as how to actually fill the correct polygon just closed. I can't seem to imagine an algorithm that would cover any case possible.
I looked at the Scanline fill algorithm but I think it would start having problems by the time there are already some polygons already filled in the map.
The Floodfill algorithm would be perfect if I had a way of finding a point inside the polygon, but, as there are many different possibilities, I can't think of a general rule for this.
I'm using an array 2x2 of integers where each color is represented by a number.
Does anyone have an idea on how to approach this problem?
If you can detect the situation then this can be solved in very simple manner. The question is which point to choose as start point for floodfill. The simple answer is: try all of them. Of course it makes a sense to start only with points adjacent to the one where your cursor is located. In this case you will have at most 8 points to check. Even better - at least 2 of them are definitely painted already if current point forms a polygon.
So you have 8 points to check. Launch floodfill 8 times starting from each of those points.
Two things which you probably should keep in mind:
You should try filling the area in cloned version of your field in order to be able to get back if floodfill will not find a polygon.
Launching floodfill second time and later you should reuse this cloned version of your field to see whether it was filled there. This will allow you to check every point at most once and this will make your 8 floodfills almost as fast as 1 floodfill.
Check this question, using Graphics2 and Polygon to fill an arbitrary polygon: java swing : Polygon fill color problem
Finding out whether a point is inside or outside a polygon: http://en.wikipedia.org/wiki/Point_in_polygon
Make sure you use double buffering. If you set individual pixels and don't use double buffering the component may redraw after every pixel was set.
Yesterday I came across Craig Reynolds' Boids, and subsequently figured that I'd give implementing a simple 2D version in Java a go.
I've put together a fairly basic setup based closely on Conrad Parker's notes.
However, I'm getting some rather bizarre (in my opinion) behaviour. Currently, my boids move reasonably quickly into a rough grid or lattice, and proceed to twitch on the spot. By that I mean they move around a little and rotate very frequently.
Currently, I have implemented:
Alignment
Cohesion
Separation
Velocity limiting
Initially, my boids are randomly distributed across the screen area (slightly different to Parker's method), and their velocities are all directed towards the centre of the screen area (note that randomly initialised velocities give the same result). Changing the velocity limit value only changes how quickly the boids move into this pattern, not formation of the pattern.
As I see it, this could be:
A consequence of the parameters I'm using (right now my code is as described in Parker's pseudocode; I have not yet tried areas of influence defined by an angle and a radius as described by Reynolds.)
Something I need to implement but am not aware of.
Something I am doing wrong.
The expected behaviour would be something more along the lines of a two dimensional version of what happens in the applet on Reynolds' boids page, although right now I haven't implemented any way to keep the boids on screen.
Has anyone encountered this before? Any ideas about the cause and/or how to fix it? I can post a .gif of the behaviour in question if it helps.
Perhaps your weighting for the separation rule is too strong, causing all the boids to move as far away from all neighboring boids as they can. There are various constants in my pseudocode which act as weights: /100 in rule 1 and /8 in rule 3 (and an implicit *1 in rule 2); these can be tweaked, which is often useful for modelling different behaviors such as closely-swarming insects or gliding birds.
Also the arbitrary |distance| < 100 in the separation rule should be modified to match the units of your simulation; this rule should only apply to boids within close proximity, basically to avoid collisions.
Have fun!
If they see everyone, they will all try to move with average velocity. If they see only some there can be some separated groups.
And if they are randomly distributed, it will be close to zero.
If you limit them by rectangle and either repulse them from walls or teleport them to other side when they got close) and have too high separation, they will be pushed from walls (from walls itself or from other who just were teleported, who will then be pushed to other side (and push and be pushed again)).
So try tighter cohesion, limited sight, more space and distribute them clustered (pick random point and place multiple of them small random distance from there), not uniformly or normaly.
I encountered this problem as well. I solved it by making sure that the method for updating each boid's velocity added the new velocity onto the old, instead of resetting it. Essentially, what's happening is this: The boids are trying to move away from each other but can't accelerate (because their velocities are being reset instead of increasing, as they should), thus the "twitching". Your method for updating velocities should look like
def set_velocity(self, dxdy):
self.velocity = (self.velocity[0] + dxdy[0], self.velocity[1] + dxdy[1])
where velocity and dxdy are 2-tuples.
I wonder if you have a problem with collision rectangles. If you implemented something based on overlapping rectangles (like, say, this), you can end up with the behaviour you describe when two rectangles are close enough that any movement causes them to intersect. (Or even worse if one rectangle can end up totally inside another.)
One solution to this problem is to make sure each boid only looks in a forwards direction. Then you avoid the situation where A cannot move because B is too close in front, but B cannot move because A is too close behind.
A quick check is to actually paint all of your collision rectangles and colour any intersecting ones a different colour. It often gives a clue as to the cause of the stopping and twitching.
In weka I load an arff file. I can view the relationship between attributes using the visualize tab.
However I can't understand the meaning of the jitter slider. What is its purpose?
You can find the answer in the mailing list archives:
The jitter function in the Visualize panel just adds artificial random
noise to the coordinates of the plotted points in order to spread the
data out a bit (so that you can see points that might have been
obscured by others).
I don't know weka, but generally jitter is a term for the variation of a periodic signal to some reference interval. I'm guessing the slider allows you to set some range or threshold below which data points are treated as being regular, or to modify the output to introduce some variation. The wikipedia entry can give you some background.
Update: from this pdf, the jitter slider is for this purpose:
“Jitter” option to deal with nominal attributes (and to detect “hidden”data points)
Based on the accompanying slide it looks like it introduces some variation in the visualisation, perhaps to show when two data points overlap.
Update 2: This google books extract (to Data mining By Ian H. Witten, Eibe Frank) seems to confirm my guess:
[jitter] is a random displacement applied to X and Y values to separate points that lie on top of one another. Without jitter, 1000 instances at the same data point would look just the same as 1 instance
I don't know the products you mention, but jittering generally means randomising the sample positions. Eg, in ray tracing you would normally render a ray though each pixel on the screen. Jittering adds a random offset to each ray to reduce issues caused by regular aliasing.