I have a 3D world with curves. Each curve is simply a list of 3D points.
When user clicks on the scree, i would like to test if the point is in a closed area.
For example, the user draws four curves that form a rectangle. If he clicks inside this rectangle i would like to "know" that it is a closed area.
I could not find any known algorithms - how i can achieve this behaviour?
Assuming your "closed areas" are all planar: For each area, find the point of intersection between the pick-ray and the area's plane. Then use an odd-even crossing test (following a ray in that plane) to determine whether the point is inside that area.
If your areas are not planar, you can instead use a winding test, where you sum the signed angles about the pick-ray of each consecutive pair of points in the area, and see whether that sum is nonzero (accounting for numerical drift).
Related
As the title suggest my problem lies in some representation of a sphere surface in computer memory. For simplicity, let's say we are making a chess game where the board is on a sphere. If the board was a classic flat board, then the solution is simple: use a 2D table.
But I don't know what kind of a memory structure I should chose for a sphere. Namely, what I want from this representation are:
If I move a pawn stubbornly in one direction, then I should return to the point where I started,
During such "journey" I should cross a point directly on the other side of the sphere (I mean to avoid a common "error" in a 2D game where moving pass an edge of a board will move an object to the opposite edge, thus making the board a torus, not a real sphere)
the area of one board cell should be approximately equal to any other cell
a cell should have got an associated longitude-latitude coordinates (I wrote "associated" because I want from the representation to only have got some way to obtain these coordinates from the position of a cell, not to be eg. a table with lat-long indexes)
There's no simple geometric solution to this. The crux of the problem is that, say you have n columns at the equator, and you're currently near the north poll, and heading north. Then the combination of the direction and the column number from the top row (and second from top row) must be able to uniquely identify which one of the n positions at the equator that path is going to cross. Therefore, direction could not be an integer unless you have n columns in the top (or second to top) row. Notice that if the polygons have more than three sides, then they must have common edges (and triangles won't work for other reasons). So now you have a grid, but if you have more than three rows (i.e. a cube, or other regular prism), then moving sideways on the second-to-top row will not navigate you to the southern hemisphere.
The best bet might be to create a regular polyhedron, and keep the point and direction as floating point vectors/points, and calculate the actual position when you move, and figure out which polygon you land in (note, you would have the possibility of moving to non-adjacent polygons with this method, and you might have issues if you land exactly on an edge/vertex, etc).
I am trying to write a Rigid body simulator, and during simulation, I am not only interested in finding whether two objects collide or not, but also the point as well as normal of collision. I have found lots of resources which actually says whether two OBB are colliding or not using separating axis theorem. Also I am interested in 3D representation of OBB. Now, if I know the axis with minimum overlap region for two colliding OBB, is there any way to find the point of collision and normal of collision? Also, there are two major cases of collision, first, point-face and second edge-edge.
I tried to google this problem, but almost every solution is only detecting collision with true or false.
Kindly somebody help!
Look at the scene in the direction of the motion (in other terms, apply a change of coordinates such that this direction becomes vertical, and drop the altitude). You get a 2D figure.
Considering the faces of the two boxes that face each other, you will see two hexagons each split in three parallelograms.
Then
Detect the intersections between the edges in 2D. From the section ratios along the edges, you can determine the actual z distances.
For all vertices, determine the face they fall on in the other box; and from the 3D equations, the piercing point of the viewing line into the face plane, hence the distance. (Repeat this for the vertices of A and B.)
Comparing the distances will tell you which collision happens first and give you the coordinates of the first meeting point (in the transformed system, the back to absolute coordinates).
The point-in-face problem is easy to implement as the facesare convex polygons.
I am developing a web app and I need to find a way to draw an outline rectangular polygon connecting the given points to form a perimeter on a coordinate system.
I found this ordering shuffled points that can be joined to form a polygon (in python)
to be quite relevant to my problem, but it has the problem that, if any points surpasses the center of the polygon the algorithm does not work...
To make it more clear what I want I am attaching two pictures to show what I want to achieve with given points:
Correct way to join points
Wrong way to connect points
Is there an algorithm that given point coordinates creates the rectangular perimeter as I want it? Thanks
I am pretty new to XNA 4.0 and have a problem I can't seem to figure out. So far I have been detecting mouse clicks by creating rectangles and checking the rectangle.contains method, but what if I don't want to check inside a rectangle?
In one part of my map I have a triangle button that I want to let the user click, but I want to only count it as a click if it is actually inside the triangle. If I create a rectangle around the triangle the user will be able to click outside the texture area, if you know what I mean.
How do I go about doing this?
You will have to use a Point in Polygon Algorithm for more complex shapes:
C# Point in polygon
Determining Whether A Point Is Inside A Complex Polygon
The check for convex polygons (your triangle) is simpler than for concave ones (see first linked article).
If you have to do lots of checks and are hitting performance limits, consider using some kind of hierarchy, a Quadtree or an LOD system. For example, you can calculate an additional bounding rectangle for very complex polygons and only do the expensive in-check with the polygon if the point lies inside the rectangle.
I'm looking for a way to generate a set of random sided, but regular, polygons, inside a given rectangle or sector of a circle. To better explain, my given 2d space should have a random arrangement of regular polygons with various numbers of sides, so, e.g, if two hexagons are separated by a rectangle equal in length to their sides, the whole space cannot be filled with only more hexagons, some triangles may be required, etc.
I'm looking for one segment of a sort of kaleidoscope effect.
You are looking for tiling algorithms. See, for example, Penrose Tiler and Tilings and Tesselations pages for a start.
Another approach, I can think of:
First decide on how many objects you want. Say 'N'
Randomly Select 3 Points in your 2D Space.
Make use of 3 points to get a virtual triangle.
Now Select another point such a way that the point is outside the virtual triangle. Now form another virtual triangle by joining this point to 2 points from previous virtual triangle and then recurisevely form "N" virtual trianlges. Incase virtual triangles crossed, then you ignore the bigger trianlge and take triangles which had formed because of crossing points as new virtualtriangles
Now Generate a INSCRIBED Circle virtually to all virtual triangles which will never be able to intersect another virtual triangle since all virtual triangles are formed by without crossing any of the triangles as expalined above.
Make use of virtual circles to form any number of regular sides by dividing 360 degress to equal slices.
Now You can draw random regular polygons
I'm not sure I understand the requirements, but you can generate random regular polygons by randomly generating the following numbers:
radius (0 to whatever)
x and y of center (must be within radius of edges)
number of points (3 to whatever)
rotation (0 to 360)
To prevent overlapping, you can test each new polygon against each existing polygon and reject the new one if the distance between the centers is less than the sum of the radii.
Drawing the polygons is then a simple trig exercise.
See: "Heuristics for Generation of Random Polygons"
Generate N random points on a plane and extract the convex hull of the object (that is, if all polygons should be convex).
You can trivially reject before generating the convex hull if one of the points is inside another polygon. If it's not you still need to test the generated polygon against other polygons near it. (If you need to do this often, a spatial data structure is probably a something to look into).