Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I'm not sure if this is the right place to ask this question, if not I apologize.
I have two variables of type double, let's say with the following values:
C#
double azimuth = 93.7221;
double altitude = 14.3398;

I know how to locate the point manually, with pencil and paper. I draw a circle on the paper, and from North I rotate clockwise 93º (azimuth angle) and from this point I go towards the center of the circle up to 14º (altitude angle).
But I have no idea how to turn these two angles into a single x,y point.

What I have tried:

I've been searching math and astronomy websites for over a week to see if I can find any equations, but without success.
Posted
Updated 19-Oct-21 2:35am

Just write the same logic that you used for pencil and paper in C#. ;-)

Perhaps, you can use the APIs from OpenStreetMap? I'm afraid you would need to write the logic yourself — if this is not already available in one of the Physics/Astronomy SDKs for the .NET.

Here are some SDKs that I guess would help (just for inspiration, though):
MKMapView Class (MapKit) | Microsoft Docs[^]
Touch and Go - Exploring Spherical Coordinates on Windows Phone | Microsoft Docs[^]
delphi - How do I calculate the Azimuth (angle to north) between two WGS84 coordinates - Stack Overflow[^] (Read this; how they did it in the language, and then reverse engineer it.)
 
Share this answer
 
Comments
Lazie Wouters 19-Oct-21 8:37am    
Thank you very much Afzaal, I started reading and I'm finding a lot of interesting stuff. In the meantime BillWoodruff posted another solution which I managed to implement. But I will continue reading the material you indicated because I saw that there are many things there that I can take advantage of.
This should get you started; "altitude angle to point" and final point is left for you to calculate.

Assuming a circle of radius #radius where rotation is clockwise: i.e., North == #0, East == #90; South == #180, West == #270, with its center 0,0, and bounding-box top left at -#radius, -#radius:

from code i use now:
// using System Drawing
public static readonly double Pi = Math.PI;
public static readonly double RadFactor = Pi / 180.0;
public static readonly double DegFactor = 180.0 / Pi;

public static double DegreeToRadSin(double degree)
{
    return Math.Sin(RadFactor * degree);
}

public static double DegreeToRadCos(double degree)
{
    return Math.Cos(RadFactor * degree);
}

public static PointF DblXYToPointF(double dx, double dy)
{
    return new PointF((float) dx, (float) dy);
}
The location of the azimuth point on the circumference is given by:
C#
int radius = 100;
double degrees = 93.7221d;
PointF p = DblXYToPointF(DegreeToRadSin(degrees) * radius, DegreeToRadCos(degrees) * radius);

// result: X: 99.99206 Y: -1.26026893
 
Share this answer
 
v5
Comments
Lazie Wouters 19-Oct-21 8:35am    
I think I got it now, using your code.
I compared the result with what is being shown on the Suncalc website (https://www.suncalc.org/#/-29.2314,-51.3377,18/2021.10.19/09:03/1/3) and the final coordinates x and y seem to be indicating the exact position.

So I did it like this (see the solution I published), using your code and adding the remaining code to calculate the remaining points:
BillWoodruff 19-Oct-21 8:48am    
great !
C#
int radius = 100;
double azimuthDegrees = double.Parse(args[1], CultureInfo.InvariantCulture);
PointF p1 = DblXYToPointF(DegreeToRadSin(azimuthDegrees) * radius, DegreeToRadCos(azimuthDegrees) * radius);

double altitudeDegrees = double.Parse(args[2], CultureInfo.InvariantCulture);
PointF p2 = DblXYToPointF(DegreeToRadSin(altitudeDegrees) * radius, DegreeToRadCos(altitudeDegrees) * radius);
            
PointF p3 = new PointF();
p3.X = p2.Y;
p3.Y = p1.Y;

MessageBox.Show("p1 + "\n " + p2 + "\n " + p3);


Output:
p1: {X=95,09093, Y=30,94699}
p2: {X=73,58713, Y=67,71214)
p3: {X=67,71214, Y=30,94699} This is the final x,y location, in this case the position of the sun right now here at my latitude, longitude and time. As I said before, I compared it with what is being shown on the SunCalc website and the result obtained is very consistent with the information there.

Thank you BillWoodruff
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900