# CGameProgrammer

Member

4264

640 Good

• Rank
Contributor

## Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

2. ## Vectorizing a 1-bit raster image of polygon(s)

Update: I had implemented the length-based solution but found that it did not work perfectly; it seemed to eliminate curve definition too much or it allowed unnecessary pixels to remain. I came up with a different technique: for each pixel, I find the longest chain of pixels following it that are near the line drawn from the first pixel to the last of the chain. Then I remove all the pixels between the start and end. This nicely handles all sloped lines and can precisely determine the corner pixels.   I'll post code and sample images later. The code is really sloppy right now but I'll try to clean it up a bit first.
3. ## Anybody left from the 2003 crowd?

I've been here since 1999 but barely post anymore...
4. ## Vectorizing a 1-bit raster image of polygon(s)

Actually I was thinking more about your original idea and I think it would be the solution after all. I was thinking that vertices would be eliminated if the length error of their absence is within a certain margin, but the actual solution (and what I believe you were trying to say) is to only remove the single least useful vertex after evaluating all of them, and then repeat, until the error from removing any remaining vertex is above the threshold. As the least useful vertices are removed, the error from removing the remaining ones becomes much larger and so they would not be erroneously removed.   Last night I wrote the code to complete step #2 (creating the ordered lists of points for each polygon) so today I will write the simplification algorithm and let you know how it goes.
5. ## Vectorizing a 1-bit raster image of polygon(s)

Your idea may have some merit Krypt0n. I'm not positive that calculating length is the right way to determine error; I worry it may either cut vital corners if it's too aggressive or fail to remove enough points on curves if it's not aggressive enough. Or both. But I can try it and see.
6. ## Vectorizing a 1-bit raster image of polygon(s)

I appreciate you trying to help but you keep suggesting inappropriate alternatives instead of the solution to the question I asked. In this case the polygon is added to Google Maps as a list of coordinates so it can be properly vector-drawn; adding it as a raster image would look much worse as I mentioned in the original post. If it wasn't obvious, and maybe it wasn't, the answer I really need is the solution to step #3 in the original post: reducing an ordered list of points along the edges to just the corners (except for curves).
7. ## Vectorizing a 1-bit raster image of polygon(s)

No, that would not work because I am not rendering a triangular mesh; the output must be the list of points that define the polygon's border.
8. ## Vectorizing a 1-bit raster image of polygon(s)

I know it's very easy to test if something is within the original simple polygons; my problem is rendering them. There is no way to directly render the original polygons that would look correct. Now it is trivial to render the raster polygons with a border; I'd just draw a circle (diameter = border thickness) at each edge pixel. The problem with that is of course it'll look blurry when stretched and pixellated when shrunk. I'd be rendering them on a map so the user would zoom a lot.   Also since we're dealing with pixels, they are not on a straight line due to interpolation. For example: X  XX    X     XX
9. ## Vectorizing a 1-bit raster image of polygon(s)

I have a one-bit image (each pixel is either black or white) of a polygon or polygons - the edges of the image are always black. I would like to convert this to a set of one or more polygon vectors, where each vector is simply an ordered list of points (one list per polygon) describing the corners or approximating curves.   Attached is an example input image with red dots overlayed to show what the output points should be. It should be two lists of points of course. The threshold for placing points around a curve is arbitrary and not important.   The input polygons will never have holes.   Speed is irrelevant; this is not being done at realtime and is just precomputed.   The actual scenario, if you're wondering, is that I have airspace regions defined as simple polygonal regions (one list of coordinates per polygon) which are either unioned or subtracted. The sample image illustrates an example of this (not actual airspace, just a simple test). I started with a hexagon, then subtracted from it a quadrilateral (which splits the hexagon in two), then I added (unioned) a circle. Trying to directly generate vector polygons from these input polygon vectors would be maddening; I figure it's simpler to render them as raster polygons temporarily (additive is drawn in white, subtractive in black) and then convert that.   Step one, edge detection, becomes trivial obviously; it's any white pixel adjacent to a black pixel.   Step two is to create huge unsimplified ordered lists of edge points. My plan is to create a bucket of all edge pixels, then (sloppy pseudocode): point = bucket.pop()   isDone = false   while !isDone {     isDone = true       for all edge pixels in bucket     {         if this edge pixel is adjacent to point         {             append edge pixel to polygon points             point = edge pixel             isDone = false break;         }     } } Then if there is anything remaining in the bucket, repeat the process for the next new polygon.   The third and final step, and one that I definitely can't seem to figure out, is to simplify these lists of every edge into just the ones that mark the corners (or that approximate to some threshold the curves).   Can anyone help?
10. ## Get points of a 3d triangle relative to its own plane in 2d

It's easiest to arbitrarily declare one of the triangle's sides as being parallel to the X or Y axis. So if you have a triangle and say its first side is 4 units long. You can just start by saying its two endpoints are at {0,0} and at {4,0}. Then you just have to calculate the position of the remaining point. You know the lengths of the other two sides; it's exactly same in 3D as in 2D since the triangle lies along a plane, and you can easily find equations online for finding the point given that you know all lengths (and all angles, as a result).

12. ## Create a sphere that intersects another at right angles

Wait, I think I can utilize what quasar3d noted about there being a right triangle from the earth's center, the red sphere's center, and a tangent point. I was thinking I only knew one side (earth's radius) and one angle (90 at the tangent) but of course I can calculate the angle at the Earth's center, and then that would be enough information to invoke Pythagorean. And I already know that angle since it's trivial to calculate given the radius of the intersection circle along the Earth's surface; you just divide by the Earth's radius and that gives you radians.
13. ## Create a sphere that intersects another at right angles

Speed matters and getting the intersection of two 3D vectors constrained to some arbitrary plane does not seem like the correct solution. There must be a more direct way.
14. ## Create a sphere that intersects another at right angles

I still can't come up with a solution. Remember that are an infinite number of points where the two spheres intersect because this is 3D. How do I find the 3D cartesian center and radius of the red sphere given its center axis (relative to the blue sphere's center) and the radius of the intersection circle?
15. ## Create a sphere that intersects another at right angles

I need to find the center and radius of a 3D cartesian sphere that intersects another sphere at right angles. Illustration: [attachment=5946:Circles.png] Knowns: * Center of the blue sphere, which is centered at the origin in fact (0,0,0) * Radius of the blue sphere * Axis along which the center of the red sphere lies (also intersection point of the axis with the blue sphere) * Distance between the two red dots Basically the blue sphere is Earth and I need to generate a cartesian sphere representing a circle on the surface of the Earth. I've done this already except that my circles are centered on the Earth's surface (red dot) which means they don't intersect the ground at right angles like the red circle roughly does. This causes certain math routines to fail. So I need to find the center/radius of the red circle drawn in the illustration. I know that, on a 2D picture, if you draw tangents of the blue circle where the red circle intersects it, the intersection of those two tangents marks the center of the red circle. Still don't know how to correlate this with the above 3D inputs to find what I need. Can anyone help?