Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

North and South, and all that.

Discussion in 'Programming (In-game)' started by Acolyte, Apr 24, 2017.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. Acolyte Apprentice Engineer

    Messages:
    109
    Hi

    I want to script a compass. Apparently I can get the gravity vector using some method of a RC block called GetNaturalGravity() unless its been borked. But I don't know how to get the axial centreline of the planet except by dropping waypoints at the poles and copy/pasting the vectors.

    Is there a better way ? or is it planetary survey time ??
     
  2. Ronin1973 Master Engineer

    Messages:
    4,797

    Look for compasses in the workshop. You can reverse engineer a mod by simply unzipping the mod file. You can then look (please don't steal code) at how others have tackled the problem of finding "North" orientation on a planet.
     
  3. Inflex Developer Staff

    Messages:
    397
    Make it simple. Take for example most (+,+,+) position of planet North, (-,-,-) South and the rest is given
     
  4. Martin R Wolfe Trainee Engineer

    Messages:
    81
    I can't remember the actual function but it is possible to find the centre of the planet using a method of the RC block. Then using a solar tracer routine you can get the path of the sun. This would give north and south due to the sun rising in the east and the plane of the equator. So from this the north and south pole coordinates can be calculated and if you want a full planetary GPS system the location of the observatory can be the zero meridian.
     
  5. Sinbad Senior Engineer

    Messages:
    2,788
    @Pennywise and i have both made compass scripts. I think @Whiplash141 has one too. Check the workshop. I for one dont mind folks using large chunks of my scripts, mostly cause mine are mostly just proof of concepts that need further refinment.
     
    • Like Like x 1
  6. plaYer2k Master Engineer

    Messages:
    3,160
    It is also important to note that there are different orientations, geodetic and magnetic.

    Though as SE doesnt have magnet fields, rotating planets with shifting axis and much more, the common way was to determine the suns rotation axis and use that as north/south reference with a planets given center.

    As for the approach - yes i like to talk about such things even though there exists a "solution" already, even if it is just for the purpose of leaning or more hopefully to get a different approach to current ones - you actually only need the gravity vector or better the normal towards the current planet - as you could have overlapping planets with gravity fields - the sun rotation axis and your current world matrix (position + orientation).

    With the normal vector facing towards the planets center and your position you essentially got a plane as seen in the illustration below.

    The vector towards north and negated towards south are useful for your north/south orientation. The vector towards the planets center is used for a cross-product to produce a local east/west vector.
    That gives you the North/South and East/West on the plane of your current position on the planet. With that information you should be able to build your own compass.

    [​IMG]

    As for the planets position you can use
    Code:
    bool IMyShipController.TryGetPlanetPosition(out Vector3D position);
    
    If you however want to use the natural gravity vector, which i personally wouldnt recommend for the potential of overlapping gravity fields from close planets, then you can use
    Code:
    Vector3D IMyShipController.GetNaturalGravity();
    
    For the cross-product you do
    Code:
    // Both vectors have to be normalized
    Vector3D North;
    Vector3D TowardsPlanet;
    Vector3D East = Vector3D.Cross(TowardsPlanet, North);
    
    EditNote: You may also cross the new TowardsPlanet and -East (West) again to get the local North on the plane too. I forgot to mention that.

    Now that of course leaves us with the question of what the "North" axis, or better said the suns rotation axis, actually is and how to get it.
    There are several different ways of doing that, either manually or automatically.

    All ways i can think of that are ingame revolve around measuring multiple, at least two with large enough angular change, sun direction vectors and then use the cross product again for the axis around which they move. That is however assuming that your measures are accurate as well as that the sun doesnt "wobble around", which if afaik doesnt right now but i could be outdated.

    Compute sun direction
    An automatic way would be to have a fixed grid with solar panels that are assumed to be free of any obfuscation in all outward directions where you thus got 6 solar panels.
    Using that you could compute a potential sun vector with some clever math for the current effectiveness of the solar panel per direction. The one i did over a year ago was fairly accurate iirc so it should work unless suns rotate as fast as once per five minutes.

    Align towards sun direction
    Having simple auto-aligning setups or have a manually controlled grid, either a ship or a rotor-gimbal based camera, to track the sun youself and set directions could be used too to fetch sun vectors and then generate a rotation axis.

    Hardcode it
    You could of course also just hardcode the rotation axis from the default setting as iirc @Whiplash141 did. That however limits you to this one world setting.

    Cheat a bit
    You can of course also hardcode but "investigate a bit" in terms of getting the skybox that runs on the world you play in and get the rotation axis from there.
    Just keep in mind that skyboxes have a default sun direction and the axis is actually computed internally.


    The most practical approach might be to assume a default rotation axis and then have a method to take a Vector3D as input to use new rotation axis.
    Combine that with subsystems to gather a feasible rotation axis and you should have a good setup.


    I hope those are "pointers" enough without restricting some independent thoughts too much.
     
    Last edited: Apr 25, 2017
  7. Acolyte Apprentice Engineer

    Messages:
    109
    In addition to a compass I happen to be trying to build a clock, to act as part of a time coordinator in a mining base. I don't know how far I will get, my previous maps get bogged down in simspeed and my inability to decipher the SE OO model.

    My clock design is to use solar panels to track sun intensity and determine the turning point, and call that point high noon. Since I have the default 2 hour day in my survival game, I can use this to see if a timer based clock is fast or slow and adjust it accordingly, and automatically.

    I have already placed the clock, with quite a few solar panels facing up, in a place near my base that is not occluded by other buildings, but mountains still occlude a bit, so the actual exposed track of the sun will be less than 180 degrees, and I will be trying to determine this angle by timing when the sunlight on the panels switches between something and nothing at sunrise and sunset.

    If I record the actual power of the solar panels at high noon then this should also help me work out the latitude of the clock. With this information I should be able to work out the plane that shares the planet centre and the clock location, then adjust it to get the equatorial plane.

    I can then take the normal of the equatorial plane and assume its the planetary axis.

    Just for kicks I'll then fly up to the poles to see if there is an "artistic" inclination built into the planets design (I'm on the Earth-like planet), and figure out which one I actually want to use for navigation.

    The end result will be a few numbers, it will be fun to post them on the forum to see how they compare with what others get by different methods.

    I don't know when I will be doing this though (I'll start next week I suspect), as I am a bit distracted away from SE right now.

    But thx for the tips all.
     
  8. Whiplash141 Junior Engineer

    Messages:
    958
    I hard code my absolute north vector to correspond with the vanilla sun rotation axis as defined in game files. Most modded skyboxes that I use work with this method so it is certainly not limited. Also, since there is no easy, quick, and foolproof way to fetch a modded sun rotation axis within a program, I don't like guesstimating in my codes. :p

    This is my script that you can look at for guidance.

    Also here is my math with some pretty colors :):
    Legend
    Blue - Absolute North (Note: I chose this axis to correspond with the vanilla sun rotation axis. This vector will not change.)
    Red - Gravity Vector (from your current position)
    Green - Relative East (from your current position)
    Orange - Relative North (from your current position)

    Vector Stuff
    Red CROSS Blue = Green
    Green CROSS Red = Orange

    Mathy Stuff
    To get the bearing angle, project your forward heading onto Green then project heading onto Orange.
    Make a triangle using these projections and measure the angle clockwise out of 360 degrees off the relative north vector :D

    [​IMG]
     
    Last edited: Apr 25, 2017
Thread Status:
This last post in this thread was made more than 31 days old.