Android Question Drawing equilateral triangle with latitude and longitude points

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Just in case somebody has worked this out already and saving some time:

Have a single line, based on two lat/lng coordinates on a geographical map.
Now I want to draw an equilateral triangle at one end of this line that points in the same direction as that line, so the bottom of that triangle
will be at 90 degrees in relation to that line.
So, the question is how do I calculate the 3 lat/lng coordinates of that triangle, based on the 2 lat/lng coordinates of that line?
For now the size of the triangle doesn't matter, I am sure I can work that out, once I have the principal calculation of this.

Thanks for any advice.

RBS
 

TILogistic

Expert
Licensed User
Longtime User
Convert longitude to distance adjusted to latitude
Calculate the angle clockwise from 3 o'clock (positive)
Adjust so that 0 degrees is 12 o'clock and is positive clockwise
This returns the angle in degrees between 0 and 360, measured clockwise from north (12 o'clock).

Now I understand what you're doing.

👍👍
 
Upvote 0

emexes

Expert
Licensed User
Longtime User
that code works perfect indeed, using that now.

Job done!

But I'm still wondering what, other than desire to exercise your computer's trigonometric functions, might be the reason that you went with angular math to plot the triangles using lat,lon rather than simple arithmetic with the screen x,y coordinates (after converting the line end coordinates to x,y) ?

Also could be worthwhile testing them around the prime meridian and anti-meridian and the equator, before your users do. Or maybe restrict the triangle edge length to maximum eg 1 degree or 100 km.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Job done!

But I'm still wondering what, other than desire to exercise your computer's trigonometric functions, might be the reason that you went with angular math to plot the triangles using lat,lon rather than simple arithmetic with the screen x,y coordinates (after converting the line end coordinates to x,y) ?

Also could be worthwhile testing them around the prime meridian and anti-meridian and the equator, before your users do. Or maybe restrict the triangle edge length to maximum eg 1 degree or 100 km.
I have a list (or ResultSet) of lat/lng values. I can convert them to X and Y values, but that would be more complex.
I am adding a triangle (arrow) bitmap to a lat/lng line, just to show the direction of a journey or a route. I get the bitmap (B4XBitmap) by converting a Typeface.FONTAWESOME character to a bitmap:

B4X:
Public Sub TextToB4XBitmap(strText As String, tf As Typeface, fFontSize As Float, iFontColour As Int, bDrawCircle As Boolean) As B4XBitmap
    
    Dim p As B4XView = xui.CreatePanel("")
    Dim iPanelWidth As Int
    Dim cvs1 As B4XCanvas
    Dim fnt As B4XFont
    Dim tTD As tTextDimensions
    
    Select Case tf
        Case tf.DEFAULT
            fnt = xui.CreateFont(tf.DEFAULT, fFontSize)
        Case tf.FONTAWESOME
            fnt = xui.CreateFontAwesome(fFontSize)
        Case tf.MATERIALICONS
            fnt = xui.CreateMaterialIcons(fFontSize)
    End Select
    
    tTD = GetTextDimensionsSingleLine(strText, Null, fFontSize, tf, Null)
    iPanelWidth = Max(tTD.fHeight, tTD.fWidth)
        
    p.SetLayoutAnimated(0, 0, 0, iPanelWidth, iPanelWidth)

    cvs1.Initialize(p)
    cvs1.DrawText(strText, cvs1.TargetRect.CenterX, cvs1.TargetRect.CenterY + tTD.fHeight / 2, fnt, iFontColour, "CENTER")
    
    If bDrawCircle Then
        cvs1.DrawCircle(cvs1.TargetRect.CenterX, cvs1.TargetRect.CenterY, iPanelWidth / 2, Colors.Black, False, 2)
    End If
    
    Dim b As B4XBitmap = cvs1.CreateBitmap
    cvs1.Release
    
    Return b
    
End Sub

The size is set by fFontSize and there is no problem with that.

> Also could be worthwhile testing them around the prime meridian and anti-meridian and the equator, before your users do.

Not done that yet and from some previous exchanges with you we know that those areas possibly could be a nightmare to deal with!

RBS
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
I think you're looking for this:
1754287967014.png
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I think you're looking for this:
View attachment 165794
I am using this for adding directions (playing a sound file) to a route. This is for walking and biking routes, especially biking as it will be more tricky to look at
the phone then while walking. It is not really for car journeys (as in your image) as I am sure a car satnav will do a better job, although you could.
Attached image will give you an idea.

RBS
 

Attachments

  • Add directions to route.png
    Add directions to route.png
    280.7 KB · Views: 35
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Hi RB , can you share the project?
This only a small part of a much larger project, which is a medical app for GP's.
I developed the map part a bit further than necessary, just for personal use.
I might at one stage make a separate app for the map part.
The map uses OSM data.

RBS
 
Upvote 0

roberto64

Active Member
Licensed User
Longtime User
Ok, if you want even a small project, you can publish with OSM data, we don't mind. Best regards
 
Upvote 0
Top