Calculating Elliptical Orbit in OpenGL? - c#

As everyone knows, satellites around the earth don't go in a perfect circle. They are more an elliptical orbit.
I'm trying to represent this using OpenGL to draw an orbit around the earth. Currently, I draw a dashed-line composed of 360 markers which makes a series of dashes around the globe in a nice perfect circle.
If I have the Orbital inclination, Perigee and Apogee what would be the way to calculate this circle? I'm trying to find a formula or white paper or something to get me in the right direction....

What this is crazy, of course they are perfect orbits. No but seriously sounds more like a need Physics formua. Try..
http://scienceworld.wolfram.com/physics/Orbit.html
or
http://physics.info/orbital-mechanics-1/

Don't have really any experience here, but if you plan to actually track satellites you will want to use the Keplerian elements ( http://en.wikipedia.org/wiki/Orbital_elements#Keplerian_elements , http://en.wikipedia.org/wiki/Orbital_elements#Orbit_prediction) which get published for satellites. Note that real satellites have perturbation in their orbits so the Keplerian elements for a satellite are regularly updated. If you just need something that "looks" like satellite orbits then the idealized ellipses form the other answer will be fine.

Related

How do I create a 2D Circle out of squares (tiles)?

So basically what I'm trying to do is generate a circle completely out of square tiles in Unity and I am trying to think about the best way mathematically to generate it.
In the end, I want it to look something like:
https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTHh7I_BURo5qMI73YLZVG6PO4WeFtbT--QL_9qOJovpNaWemar
In this image, the tiles are more rectangular and not all sides are equal, but it gets the point across.
Does anyone know of any mathematical formulas or anything that could be helpful in doing this? I don't necessarily need straight answers (unless you have them :D), but anything to help me along would be appreciated!
Thanks!
Take the starting point (center) and start drawing your first square in the starting direction. Now turn the direction with the Golden ratio: 1.618...
Keep turning this much for every consecutive square you are drawing, every time increasing the distance from the center a little bit.
Apparently sunflowers also grow following this pattern according to this video!

XNA 2D Transformation

I have actually the following map (isometric projection), and I can move/zoom/rotate without problem with matrix transformations (SpriteBatch): picture.
And I wanted to know if it was possible (if so, how), to get the following result, without referring to 3D: picture.
All suggestions are welcome. Thank you in advance. :)
Its going to be a huge pain in the ass, especially but I think it is at least possible if you don't change the viewing angle.
Some ideas:
Make each tile its own little image unit.
The more far back the tile is from the camera, lower its layer priority when you draw it so that it gets blocked by tiles in front of it. Also you will have to figure out an algorithm that correctly sizes the tiles based on their distance. This algorithm will have to be more and more precise the closer you want to get the tiles, but there should be some mathematical/geometric formula that can do it automatically.
You quite literally CANNOT rotate the camera at all, unless you want to have separate sprites for every single angle for every single tile.

isometric tile engine

I am making an RPG game using an isometric tile engine that I found here:
http://xnaresources.com/default.asp?page=TUTORIALS
However after completing the tutorial I found myself wanting to do some things with the camera that I am not sure how to do.
Firstly I would like to zoom the camera in more so that it is displaying a 1 to 1 pixel ratio.
Secondly, would it be possible to make this game 2.5d in the way that when the camera moves, the sprite trees and things alike, move properly. By this I mean that the bottom of the sprite is planted while the top moves against the background, making a very 3d like experience. This effect can best be seen in games like diablo 2.
Here is the source code off their website:
http://www.xnaresources.com/downloads/tileengineseries9.zip
Any help would be great, Thanks
Games like Diablo or Sims 1, 2, SimCity 1-3, X-Com 1,2 etc. were actually just 2D games. The 2.5D effect requires that tiles further away are exactly the same size as tiles nearby. Your rotation around these games are restricted to 90 degrees.
How they draw is basically painters algorithm. Drawing what is furthest away first and overdrawing things that are nearer. Diablo is actually pretty simple, it didn't introduce layers or height differences as far as I remember. Just a flat map. So you draw the floor tiles first (in this case back to front isn't too necessary since they are all on the same elevation.) Then drawing back to front the walls, characters effects etc.
Everything in these games were rendered to bitmaps and rendered as bitmaps. Even though their source may have been a 3D textured model.
If you want to add perspective or free rotation then you need everything to be a 3D model. Your rendering will be simpler because depth or render order isn't as critical as you would use z-buffering to solve your issues. The only main issue is to properly render transparent bits in the right order or else you may end up with some odd results. However even if your rendering is simpler, your animation or in memory storage is a bit more difficult. You need to animate 3D models instead of just having an array of bitmaps to do the animation. Selection of items on the screen requires a little more work since position and size of the elements are no longer consistent or easily predictable.
So it depends on which features you want that will dictate which sort of solution you can use. Either way has it's plusses and minuses.

Math - Displaying multiple objects in a single view using trigonometry

It might be that my math is rusty or I'm just stuck in my box after trying to solve this for so long, either way I need your help.
Background: I'm making a 2d-based game in C# using XNA. In that game I want a camera to be able to zoom in/out so that a certain part of objects always are in view. Needless to say, the objects move in two dimensions while the camera moves in three.
Situation: I'm currently using basic trigonometry to calculate which height the camera should be at for all objects to show. I also position the camera between those objects.
It looks something like this:
1.Loop through all objects to find the outer edges of our objects : farRight, farLeft, farUp, farDown.
2.When we know what the edges of what has to be shown are, calculate the center, also known as the camera position:
CenterX = farLeft + (farRight - farLeft) * 0.5f;
CenterY = farUp + (farDown - farUp) * 0.5f;
3.Loop through our edges to find the largest value compared to our camera position, thus the furthest distance from the center of screen.
4.Using the largest distance-value we can easily calculate the needed height to show all of those objects (points):
float T = 90f - Constants.CAMERA_FIELDOFVIEW * 0.5f;
float height = (float)Math.Tan(MathHelper.ToRadians(T)) * (length);
So far so good, the camera positions itself perfectly based on the calculations.
Problem:
a) My rendering target is 1280*720 with a Field of View of 45 degrees, so one always sees a bit more on the X-axis, 560 pixels more actually. This is not a problem per se but more one that on b)...
b) I want the camera to be a bit further out than it is, so that one sees a bit more on what is happening beyond the furthest point. Sure, this happens on the X-axis, but that is technically my flawed logic's result. I want to be able to see more on both the X- and Y-axis and to control this behavior.
Question
Uhm, so to clarify. I would like to have some input on a way to make the camera position itself, creating this state:
Objects won't get closer than say... 150 pixels to the edge of the X-axis and 100 pixels to the edge of the Y-axis. To do this the camera shall position itself along the Z-axis so that the field of view covers it all.
I don't need help with the coding, just the math and logic of calculating the height of my camera. As you probably can see, I have a hard time wrapping this inside my head and even harder time trying to explain it to you.
If anyone out there has been dealing with this or is just better than me at math, I'd appreciate whatever you have to say! :)
Don't you just need to add or subtract 150 or 100 pixels (depending on which edge you are looking at) to each distance measurement in your loop at step 3 and carry this larger value into length at step 4? Or am I missing something.
I can't explore this area further at the moment, but if anyone is having the same issue but is not satisfied by provided answer there is another possibility in XNA.
ViewPort.Unproject()
This nifty feature converts a screen space coordinate to a world space one.
ViewPort.Project()
Does the opposite thing, namely converting world space to screen space. Just thought that someone might want to go further than me. As much as my OCD hates to leave things not perfect, I can't be perfectioning this... yet.

Detect Rotation of a scanned image in C#

We want a c# solution to correct the scanned image because it is rotated. To solve this problem we must detect the rotation angle first and then rotate the image. This was our first thought for our problem. But then we thought image warping would be more accurate as I think it would make the scanned image like our template. Then we can process it as we know all the coordinates of our template... I searched for a free SDK or a free solution in c#. Helping me in this will be great as it is the last task in our work. Really, thanks for all.
We used the PrimeOCR product to do this. It's not free, but we couldn't find a free program that was comparable.
So, the hard part is to detect the angle of the page.
If you have full control over the template, the simplest way to do this is probably to come up with an easily-detectable symbol (e.g. a solid black circle) and stick 3 of them on the template. Then, detect them (just look for big blocks of pixels with high saturation, in the case of a solid black circle).
So, you'll then have 3 sets of coordinates. If you have a top circle, a left circle, and a right circle with all 3 circles at difference distances from one another, detecting which circle is the top circle should be pretty easy.
Then just call a rotation function. This part is easy and has been done before (e.g. http://www.switchonthecode.com/tutorials/csharp-tutorial-image-editing-rotate ).
Edit:
I suggested a circle because it's easier to find the center, but a rectangle should work, too.
To be more explicit about how to actually locate the rectangles/circles, take the average Brightness value of every a × a group of pixels. If that value is greater than b, then that a × a group of pixels is part of a rectangle. a and b are varables you'll want to come up with yourself.
Use flood-fill (or, more precisely, Connected Component Labeling) group the resulting pixels together. The end result should give you your rectangles.

Categories