my question should be simple (even if I can't find a way out).
When two BoundingSphere intersects they should share one or two points. I wanna know if there is any chance to know those points exactly (or approximately) or not.
I was thinking something like this:
-check if the spheres intersect
-calculate radius_1 distance from center_1 in the direction of center_2
-calculate radius_2 distance from center_2 in the direction of center_1
-substract the smaller to the larger and have that one as "collision" point
but since this sounds to me a little too tricky, I wanted to know if there is a simplier way to achieve this.
Hope to have made myself clear
Posting the same question on gamedev I got this answer.
It seems quite complete and it allowed me to understand things better and solve my problem.
Related
I want to slice a 3D model relative to an infinite plane(In WPF). I'm checking if edges intersect with the infinite plane. If true, I'll create a new point at the intersection position, so I'm getting a couple of points that I want to generate a cap on so that the model is closed after slicing. For example, if this is the cross section, the result would be as follows:
Note: The triangulation ain't important. I just need triangles.
I also need to detect the holes as follows(holes are marked in red):
If it is impossible to do it the way I think(It seems to be so), the how should I do it? How do developers cap an object after being sliced?
There is also too much confusion. For example, The first picture's result may be:
What am I missing??
EDIT:
After some research, I knew one thing that I am missing:
The input is now robust, and I need the exact same output. How do I accomplish that??
In the past, I have done this kind of thing using a BSP.
Sorry to be so vague, but its not a a trivial problem!
Basically you convert your triangle mesh into the BSP representation, add your clipping plane to the BSP, and then convert it back into triangles.
As code11 said already you have too few data to solve this, the points are not enough.
Instead of clipping edges to produce new points you should clip entire triangles, which would give you new edges. This way, instead of a bunch of points you'd have a bunch of connected edges.
In your example with holes, with this single modification you'd get a 3 polygons - which is almost what you need. Then you will need to compute only the correct triangulation.
Look for CSG term or Constructive Solid Geometry.
EDIT:
If the generic CSG is too slow for you and you have clipped edges already then I'd suggest to try an 'Ear Clipping' algorithm.
Here's some description with support for holes:
https://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
You may try also a 'Sweep Line' approach:
http://sites-final.uclouvain.be/mema/Poly2Tri/
And similar question on SO, with many ideas:
Polygon Triangulation with Holes
I hope it helps.
Building off of what zwcloud said, your point representation is ambiguous. You simply don't have enough points to determine where any concavities/notches actually are.
However, if you can solve that by obtaining additional points (you need midpoints of segments I think), you just need to throw the points into a shrinkwrap algorithm. Then at least you will have a cap.
The holes are a bit more tricky. Perhaps you can get away with just looking at the excluded points from the output of the shrinkwrap calculation and trying to find additional shapes in that, heuristically favoring points located near the centroid of your newly created polygon.
Additional thought: If you can limit yourself to convex polygons with only one similarly convex hole, the problem will be much easier to solve.
I am stuck at this point. I am trying to find where two lines in graph intersects. I have 10 points for each spline, but they intersects between this points.
I am using c# graph. (System.Windows.Forms.DataVisualization.Charting.Chart chart2;)
Do you have an idea how to solve this?
Here is this situation. Points are measured manually so there is minimum posibility that it will intersetcs on this given points.
Refine the splines to the degree of precision you need and then intersect (straight) line pairs, as Matthew suggested. This can be done quite efficient if you chose the right data structure to store the line segments, so that it supports fast range queries (kd-tree perhaps?).
Doing it analytically is going to be really hard, I guess.
I found the solution, I used least squares theory and polynomial function to represent equation of curve and after that solve the equation. If anybody needs solution just write me.
I'm using slimdx in c#, and my problem is a follows:
I have a list of vertices that forms a polygon, in linestrip format, and I need to transform it to a trianglestrip that covers the polygon.
I started with a center-of-mass calculation, however it only covers convex ones, and I need a general solution.
The final result should look smth like this:
Does anyone happens to know any algorithms for the issue?
Thanks.
There's ear clipping algorithm that is quite nice for your use case, an example can be found here:
Ear clipping c#
I need to calculate triangles of a polygon. Polygon can contain holes. And Req an efficient way.
So I think I need Constrained Delaunay Triangulation.
I must do that in c#, only need calculation not drawing or something.
poly2tri seems good but idk its not working for me :S
Anyway I need help. How can I calculate that triangles?
(If your best offer is poly2tri, i can explain my problem on it)
Delaunay was not designed for this, use Ear Clipping instead.
I suppose my simple solution on github:gist (but it's rather old and probably not optimal).
I have a List of 2D points. What's an efficient way of iterating through the points in order to determine whether the list of points are in a straight line, or curved (and to what degree). I'd like to avoid simply getting slopes between smaller subsets. How would I go about doing this?
Thanks for any help
Edit: Thanks for the response. To clarify, I don't need it to be numerically accurate, but I'd like to determine if the user has created a curved shape with their mouse and, if so, how sharp the curve is. The values are not too important, as long as it's possible to determine the difference between a sharp curve and a slightly softer one.
If you simply want to know if all your points fit more or less on a curve of degree d, simply apply Lagrange interpolation on the endpoints and d-2 equally spaced points from inside your array. This will give you a polynomial of degree d.
Once you have your curve, simply iterate over the array and see how far away from the curve each point is. If they're farther than a threshold, your data doesn't fit your degree d polynomial.
Edit: I should mention that iterating through values of d is a finite process. Once d reaches the number of points you have, you'll get a perfect fit because of how Lagrange interpolation works.
To test if it's a straight line, compute the correlation coefficient. I'm sure that's covered on wikipedia.
To test if it's curved is more involved. You need to know what kind of curves you expect, and fit against those.
Here is a method to calculate angle: Calculate Angle between 2 points using C#
Simply calculate angle between each and every point in your list and create list of angles, then compare if angles list values are different. If they are not different then it means it's straight line, otherwise it's curve...
If it's a straight line then angle between all points has to be a same.
The question is really hazy here: "I'd like to avoid simply getting slopes between smaller substes"
You probably want interpolation a-la B-splines. They use two points and two extra control points if memory serves me. Implementations are ubiquitous since way back (at least 1980's). This should get you underway
Remember that you'll probably need to add control points to make the curve meet the endpoints. One trick to make sure those are reached is to simply duplicate the endpoints as extra controlpoints.
Cheers
Update Added link to codeproject
it would appear that what I remember from back in the 80's could have been Bezier curves - a predecessor of sorts.