Betwixt two places lies what?

The place to discuss creating, porting and modifying Celestia's source code.
Topic author
Janus
Posts: 537
Joined: 13.08.2016
With us: 8 years 6 months

Betwixt two places lies what?

Post #1by Janus » 09.03.2019, 05:31

Had a bad morning, nearly had a falling out with a customer.
A tale of two char sets, another Utf vs Unicode deathmatch, and no one told me I was the ref.
So after sorting all that out, I needed a break.
In light of recent discussions in the restart thread, I decided to have some fun to get my mind off of things.

The result is thus.
Here is a customized Celestia commit 5429.
I have added a command to celx, it returns the distance between two things in LY.

Code: Select all

local dist
local target1 = "Sol"
local target2 = "Wolf 359"

dist = celestia:betwixt(target1, target2)

celestia:print(target1 .. " " .. target2 .. " dist is:" .. dist, 10)
wait(5)


I coded it thinking of stars, but it works on all sorts of things.
For instance, set target1 & target2 to earth and mars, get a reading between them, then advance the date via script one day, and read it again.
You can watch the distance between them change over time from above the ecliptic to help you visualize the movement of the planets, with the numbers every one happily bandies about in discussions changing over "time".

I have done no real testing, so caveat tinker, it may give weird results, or even crash if given garbage strings.
All I can hope is it amuses someone.

Length or distance conversions can be found at : Celx Vector guide

Janus.

EDIT: Look further for later versions. Now has three commands added as of the #8 benear posting.
Last edited by Janus on 17.03.2019, 20:06, edited 1 time in total.

Avatar
Lafuente_Astronomy
Moderator
Posts: 726
Joined: 04.08.2018
Age: 26
With us: 6 years 6 months
Location: Cebu City, Cebu Province, Philippines
Contact:

Post #2by Lafuente_Astronomy » 09.03.2019, 06:16

Well, I downloaded it already, but I'm still confused as to how to set up Target1 and Target2. Can you show me how to do it?

Thanks in advance
Official Administrator of the Celestia Discord Server.
Invite: https://discordapp.com/invite/WEWDcJh
If you don't have a Discord account, register here: https://discordapp.com/register
Have a blessed day.

Topic author
Janus
Posts: 537
Joined: 13.08.2016
With us: 8 years 6 months

Post #3by Janus » 09.03.2019, 06:31

Save the code above in the first post to a celx script file, then run it.
I have it as betwixtdemo.celx in the scripts directory.

When run, it says Sol Wolf 359 Dist is: 7.7???? for about ten seconds.
Distance is in light years.
Accepts any valid pair of text identifiers, provides distance between in lightyears.
Thought it sounded like fun.


Janus.

Avatar
Lafuente_Astronomy
Moderator
Posts: 726
Joined: 04.08.2018
Age: 26
With us: 6 years 6 months
Location: Cebu City, Cebu Province, Philippines
Contact:

Post #4by Lafuente_Astronomy » 09.03.2019, 08:14

Well, I did it. It really works! Though if only there's a way to measure the distance of 2 different objects without having to change the script. Like, it can be made a feature if one wants to compare distances from one star or other celestial object to another instead of its distance to the Sun.

Added after 1 minute 24 seconds:
And another thing: Is it possible for you to make a fork combining most, if not all of the different qualities you made in previous forks or not?
Official Administrator of the Celestia Discord Server.
Invite: https://discordapp.com/invite/WEWDcJh
If you don't have a Discord account, register here: https://discordapp.com/register
Have a blessed day.

Topic author
Janus
Posts: 537
Joined: 13.08.2016
With us: 8 years 6 months

Post #5by Janus » 09.03.2019, 16:12

Putting everything in a single fork, no, or at least not yet.
Half or so of my stuff requires reconfiguration of either databases, or internal structures of celestia itself.
Even doing this little bit I had to play with eigen and deprecated functions.

This is also just me messing around.
I am not an astronomer, or a mathematician, or a rocket scientist.
What I do is take things apart to see how they work, adding what I need at the moment when I put them back together.

Like right now I am working on celestia:betwixdex which will give the index of the nearest stellar neighbor.
If enough people like them, then those in charge of the project are welcome to add the code if they like.
If not, they stay my toys for satisfying my curiosities.

I started this because I was going to make a cute little script to search the stardb, but the string handling is much slower than I remember it being.
Thus I am turning to a more dedicated function.
I just hope someone finds a use for this stuff.


Janus.

Added after 1 hour 43 minutes:
Okay, here is some more fun.

I added another function, celestia:betwixdex() to the mix.
This one is specific to stars.
What it does is search the star database for the nearest stellar neighbor more than a lightyear away.
You can test it this way, save the following to stellarneighbor.celx in scripts.

Code: Select all

local target1 = celestia:getselection();
local target1name = target1:name();
local target1dex = celestia:betwixdex(target1name)
local neighbor = celestia:getstar(target1dex)
local neighborname = neighbor:name();
celestia:print("Nearest stellar neighbor is " .. neighborname, 10)
wait(5)


Go to something, then run the above script.
It will print out the nearest neighbor star.

Remember however, do not depend on these functions being present.
These are experiments done by me, they are not official builds, just based on 5429{Current at this time.}.
They are experimental, and I remind the world, I am not a C/C++ programmer, this is a test.
I am sure someone will find a glitch with what I did, on one or the other of the functions.


Janus.

EDIT: Look further on for later versions. Three commands added as of #8 benear posting.
Last edited by Janus on 17.03.2019, 20:07, edited 1 time in total.

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 5 months
Location: NY, USA

Post #6by selden » 09.03.2019, 19:30

I'm a little confused. My impression is that the "betwix" function is a specialized variant of the "distanceto" function. Is that right?
Selden

Topic author
Janus
Posts: 537
Joined: 13.08.2016
With us: 8 years 6 months

Post #7by Janus » 09.03.2019, 20:23

It functions basically the same.
It is just a fast way to find the nearest neighbor star to the current selection.
I am expanding it return a table of N closest neighbor stars.

They exist because I often find myself doing these sorts of things, and doing so from celx/lua is slow if you are doing very many at one time.
When plotting paths between stars, I often need to know how far between.
If this or that is a neighbor, or to get a list of neighbors.

These are just tools to save time.
Doing things by label is slow because of text handling.
There are no fast efficient or speedy ways of handling text, so I am making ways not to need to.


Janus.

Topic author
Janus
Posts: 537
Joined: 13.08.2016
With us: 8 years 6 months

Post #8by Janus » 15.03.2019, 16:25

Okay, here are my current final tweaks for this goof around time.
Work has returned, so I have to go do more of that so I can go do something I enjoy more later.

I have added three commands.
Names for all of these chosen to avoid existing names.
If kept, they can be renamed as relevant, but overlap during development is to be avoided.

betwixt : Distance between two named things.
betwixdex : Database index of nearest star to named thing.
benear : Table of database indexes of stars within a specified distance in LY of named thing.

I may be the only person on the forum who clicks on random stars then goes there and looks around.
If I am, then I am, however, if I am not, then others may like this.
The following script will tell you the nearest neighbor of a star.
Then list the stars within twice the distance of the closest neighbor.

Spoiler

Code: Select all

-- Janus
-- Demonstration of benear
-- returns table of stars within lightyears of selection

local target1 = celestia:getselection();
local target1name = target1:name();
target1:mark("Yellow", "triangle", 7)
local target2dex = celestia:betwixdex(target1name)
local target2 = celestia:getstar(target2dex)
local target2name = target2:name();
local dist = celestia:betwixt(target1name, target2name)
celestia:print("Nearest neighbor is:" .. target2name .. " @" .. dist .. " LY",5)
wait(5)

local lightyears = dist + dist + 1
local neighbors = celestia:benear(target1name, lightyears)
local neighborcount = #neighbors; -- should still be getn, note to self to fix this in lua source.
celestia:print("Neighbor count is " .. neighborcount, 5)
wait(5)

for loopcount = 1, neighborcount do

   local neighbor = celestia:getstar(neighbors[loopcount])
   neighbor:mark("Green", "square", 6)
   local neighborname = neighbor:name()
   neighbordist = celestia:betwixt(target1name, neighborname)
   celestia:print("Stellar neighbor is " .. neighborname .. " @" .. neighbordist .. " LY", 3)
   wait(2)
   end


If anyone is interested I can post the sourcecode for them.
I also warn any real C/C++ programmers that I am not a real C/C++ programmer, so my code will be messy.


Janus.

Avatar
Lafuente_Astronomy
Moderator
Posts: 726
Joined: 04.08.2018
Age: 26
With us: 6 years 6 months
Location: Cebu City, Cebu Province, Philippines
Contact:

Post #9by Lafuente_Astronomy » 15.03.2019, 22:02

Janus wrote:I may be the only person on the forum who clicks on random stars then goes there and looks around.

You're not alone Janus. I do that too.
Official Administrator of the Celestia Discord Server.
Invite: https://discordapp.com/invite/WEWDcJh
If you don't have a Discord account, register here: https://discordapp.com/register
Have a blessed day.


Return to “Development”