How to calculate mid point vertices? - geometry

I have a set of vertices to draw a circle, but I want to draw a high-res circle by drawing twice the number of vertices, I cant just increase the number of vertices what I need is to calculate the mid points from the supplied vertices, if that makes sense
So from that image how can I calculate the points A, B, C, ... given the points V0, V1, V2, ... and the center point of the circle ?
Please note that I cant just calculate the mid-points by rotating the vertices they need to be calculated using their position
Thanks

The center of the circle can be determined by making a perpendicular line to two neighboring "sides", and intersecting them.
If there are an even number of vertices, just pick two which are opposite to each other, and "avarage them" - calculate the midpoint.
Then, you can just rotate all the vertices to either way by 180°/No.vertices around this center, so you get the ones you are looking for. Of course, you should keep the existing ones too.

Related

Build a geographical map from triangle points based on distance

I have 5 {x,y} points randomly placed on a grid
Each of the points do not know the {x,y} coordinates of the other points
Each of the points do know the distance of each of the other points from their {x,y} position
Each of the points exchanges this distance information with every other point
So every point knows every distance of every other point
Using this distance information every point can calculate (by finding the angles) triangles for every other point using itself as a reference point
Example, point 1 can calculate the following triangles:
1-2-3,
1-2-4,
1-2-5,
1-3-4,
1-3-5,
1-4-5,
and using the distance data recieved from the other points it can also calculate
2-3-4,
2-3-5,
2-4-5,
3-4-5
I would like to build a map of the location of every other point relative to a single point
How should I go about doing this? I am asuming it would be some kind of triangulation algorithm but these mainly seem to compute the location of a point from three other points, not the other way around where the other points {x,y} coordinates are discovered based on only the distance information.
I have tried plotting the two possible triangles for every 3 triangle points and then rotating them on a fixed known point to try and align them, but I think this avenue will end up with too many possibilities and errors
Ultimately I would like every point to end up with {x,y} coordinates of every other point relative to itself
You know the distance from one point to every other, dij. Thus, point 2 lies in a circumference of center point 1 and radius = d12. Point 3 lies in a circumference of center point 1 and R=d13 and it also lies in another circumference of center point 2 and R=d23.
See this picture:
I've set point 2 in X-axis for simplicity.
As you see, point 3 is on the intersection of two cicrcumferences centered at P1 and P2. There is a second intersection, P3a. Let's choose the one that is upwards and continue.
For P4 we can use three circumferences, centered at P1, P2 and P3. Again we get two solutions.
The same process can be done with the rest of points. For Pn you have n-1 circumferences.
I'm sure you can find the maths for circle-circle intersection.
Some remarks must be observed:
1) The construction is simpler if you first sort the points by distance to P1.
2) Not all distances generate a solution. For example, increase d13 an there's no intersection between the two circumferences for P3. Or increase d14 and now the three circumferences don't intersect in just the two expected points 4 and 4a.
3) This fact can be overworked by considering the average of intersections and the distance from each solution to this average. You can set a tolerance in these distances and tell if the average is a solution or else some dij is wrong. Since two solutions are possible, you must consider two averages.
4) The two possible triangulations are symmetric, over X-axis in the case I've drawn.
The real solution is obtained by a rotation around P1. To calculate the angle of rotation you need the {x,y} coordinates of another point.

Determining a bounding polygon surrounding specific points

I've been trying to figure out how to determine a bounding polygon around a specific set of points (set A) from another set of points (set B) such that the polygon only contains points in set A. For simplicity, we can assume the polygon will be convex, set A will only include 2 points, and a solution will exist from the given data.
For example, given:
these points, I want to create a polygon around the blue points from the red points like this. This could be done by finding the next point with the greatest angle while not cutting through the blue points, but I don't want the result to be too minimal like this.
Any suggestions or algorithms for solving this problem?
Seems that if you calculate triangulation over all (red and blue) points, then triangles containing blue vertices, form the first approximation of needed region. This approximation usually would be concave, so one need to cut off "ears".
If result looks too small, it is possible to add the third vertices of outer border triangles if they don't violate convexity.

Finding the Dimension of OBJ objects

I am having a Three OBJ file, Cone, Sphere and Cube. How can I find the dimension of these objects, so that I can use it in my collision detection class?
i.e How can I find Radius, Length of Cube and Radius and Height of cone? Or is there any better way for collision detection, I have hundreds of random particle in my game which may or may not collide with these objects.
Length of the cube would be the distance of two consecutive points in one face.
If by radius of a cube you mean its diagonal it would be sqrt{3} of its length.
For a sphere, you can find its center by averaging all the vertices.
Its radius would be the distance between any vertex and the center.
It works fine if the sphere is not high resolution.
Otherwise, you have to solve a system of equations to find the sphere that passes through four points. You can take a look at this:
https://www.quora.com/How-do-you-find-the-center-and-radius-of-a-sphere-given-any-four-arbitrary-points-x_1-y_1-z_1-x_2-y_2-z_2-x_3-y_3-z_3-x_4-y_4-z_4
For the cone: there is probably one vertex that is connected to all other vertices. This vertex is probably easy to find for you. Let's call that p.
Take three vertex other than p. Find the circle passing through those vertices. Call that c. The distance between p and c is the height. The distance between c and any vertex other than p would be the radius. To find the circle passing through three points, you again need to solve a system of equations with three unknowns. As the equation of a circle is (x-a)^2+(y-b)^2=r^2. You need to put the values of your three points in the equation and find a,b, and r. Note that this equation assumes that the circle is in 2D. To use it for 3D, you need to first find the plane passing through these three points. If you do not want to go through all these. you can again average all vertices except p and find the center of the circle. the radius would be the distance between the center and any point. I actually assumed that the circles and spheres in your input are uniformly sampled which is the case for most of the available Obj files for these shapes.

Drawing a circular, minor arc given the centre point and two other points

Does anyone know how to draw a circular, minor arc given the centre point and two other points that lie on the circle?
I want to draw the pixels directly to the screen, and preferably, not have to calculate the angles.
I am using SDL and C, but may be OK studying code given that uses a different language.
Thanks.
All points on a circle are equal distance to the centre.
Given you know two points on the circle you can calculate this distance.
Assuming you have cartesian coordinates, for every x or y value between the known points calculate the other value so that the point is equal distance to the centre and plot these points.
I think this is conceptually the easiest way, though not the most efficient.

Gaps Between Rectangles Connected at the Center

I'm experimenting with a vector based graphics style with objects represented as series of line segments with a given width(it would probably be easier to think of these as rectangles). The problem is that these segments are connected at the center and leave a gap (shown below). I've determined that the most efficient way to cover this gap is simply to cover it with a triangle, and since I'm working in OpenGL, all I need are the points of the two points that don't overlap with the other rectangle, the third point being the center point where the two line segments(rectangles) are connected. How can I determine which points I need to use for the triangle, given that I have all of the points from both rectangles?
EDIT: I will also accept alternative solutions, as long as they cover up that gap.
EDIT 2: Nevermind, I solved it. I'll post code once I have better Internet connection.
Maybe I'm misunderstanding the question... but if you zoom in on the top corner of your red pentagon, you get something like this, am I right?
where A and B are nodes on the rectangle for edge1 and C and D are nodes on the rectangle for edge2. You say you already know these coordinates. And from what you say, the edges meet at the centre, which is halfway between A and B, and also halfway between C and D. So call this point X, and you can calculate its coordinates easily I guess.
So all you need to do is draw the missing triangle AXC, right? So one way would be to determine that A and C are on the "outside" of the polygon (and therefore need filling) and B and D are on the "inside" and therefore don't. But it's probably easier to just draw both, as it doesn't hurt. So if you fill AXC and BXD, you'd get this:
The solution I found assumes that there are 3 basic cases:
First, the three unique center points for the two rectangle proceed upward (positive y direction) so the gap is either on the left or right of the connection. In my code, I had the corner points of the rectangle organized by their orientation to the left or right of the center point, so if the bottom rectangle's left point is below the top rectangle's left point, then the gap is between the left points of the two rectangles, otherwise the gap is between the right points.
Second, the three unique center points have a maximum at the center most of the center points, so the gap is on the top. The gap is then between the two points with the maximum y values.
Third, the three unique center points have a minimum at the center most of the center points, so the gap is on the bottom. The gap is then between the two points with the minimum y values.
[I'll post pictures of the example cases if it is requested]

Resources