Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8339621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:55:53+00:00 2026-06-09T04:55:53+00:00

Ok, I know this sounds really daft to be asking here, but it is

  • 0

Ok, I know this sounds really daft to be asking here, but it is programming related.

I’m working on a game, and I’m thinking of implementing a system that allows users to triangulate their 3D coordinates to locate something (eg for a task).
I also want to be able to let the user make the coordinates of the points they are using for triangulation have user-determined coordinates (so the location’s coordinate is relative, probably by setting up a beacon or something).

I have a method in place for calculating the distance between the points, so essentially I can calculate the lengths of the sides of the triangle/pyramid as well as all but the coordinate I am after.
It has been a long time since I have done any trigonometry and I am rusty with the sin, cos and tan functions, I have a feeling they are required but have no clue how to implement them.

Can anyone give me a demonstration as to how I would go about doing this in a mathematical/programatical way?

extra info:
My function returns the exact distance between the two points, so say you set two points to 0,0,0 and 4,4,0 respectively, and those points are set to scale(the game world is divided into a very large 3d grid, with each ‘block’ area being represented by a 3d coordinate) then it would give back a value at around 5.6.

The key point about it varying is that the user can set the points, so say they set a point to read 0,0,0, the actual location could be something like 52, 85, 93. However, providing they then count the blocks and set their other points correctly (eg, set a point 4,4,0 at the real point 56, 89, 93) then the final result will return the relative position (eg the object they are trying to locate is at real point 152, 185, 93, it will return the relative value 100,100,0). I need to be able to calculate it knowing every point but the one it’s trying to locate, as well as the distances between all points.

Also, please don’t ask why I can’t just calculate it by using the real coordinates, I’m hoping to show the equation up on screen as it calculates the result.7

Example:
Here is a diagram
Example Diagram

Imagine these are points in my game on a flat plain.
I want to know the point f.
I know the values of points d and e, and the sides A,B and C.

Using only the data I know, I need to find out how to do this.

Answered Edit:

After many days of working on this, Sean Kenny has provided me with his time, patience and intellect, and thus I have now got a working implementation of a triangulation method.

I hope to place the different language equivalents of the code as I test them so that future coders may use this code and not have the same problem I have had.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:55:55+00:00Added an answer on June 9, 2026 at 4:55 am

    I spent a bit of time working on a solution but I think the implementer, i.e you, should know what it’s doing, so any errors encountered can be tackled later on. As such, I’ll give my answer in the form of strong hints.

    First off, we have a vector from d to e which we can work out: if we consider the coordinates as position vectors rather than absolute coordinates, how can we determine what the vector pointing from d to e is? Think about how you would determine the displacement you had moved if you only knew where you started and where you ended up? Displacement is a straight line, point A to B, no deviation, not: I had to walk around that house so I walked further. A straight line. If you started at the point (0,0) it would be easy.

    Secondly, the cosine rule. Do you know what it is? If not, read up on it. How can we rearrange the form given in the link to find the angle d between vectors DE and DF? Remember you need the angle, not a function of the angle (cos is a function remember).

    Next we can use a vector ‘trick’ called the scalar product. Notice there is a cos function in there. Now, you may be thinking, we’ve just found the angle, why are we doing it again?

    Define DQ = [1,0]. DQ is a vector of length 1, a unit vector, along the x-axis. Which other vector do we know? Do we know of two position vectors?

    Once we have two vectors (I hope you worked out the other one) we can use the scalar product to find the angle; again, just the angle, not a function of it.

    Now, hopefully, we have 2 angles. Could we take one from the other to get yet another angle to our desired coordinate DF? The choice of using a unit vector earlier was not arbitrary.

    The scalar product, after some cancelling, gives us this : cos(theta) = x / r
    Where x is the x ordinate for F and r is the length of side A.

    The end result being:

    theta = arccos( xe / B ) - arccos( ( (A^2) + (B^2) - (C^2) ) / ( 2*A*B ) ) 
    

    Where theta is the angle formed between a unit vector along the line y = 0 where the origin is at point d.

    With this information we can find the x and y coordinates of point f relative to d. How?
    Again, with the scalar product. The rest is fairly easy, so I’ll give it to you.

    x = r.cos(theta)
    
    y = r.sin(theta)
    

    From basic trigonometry.

    I wouldn’t advise trying to code this into one value.

    Instead, try this:

    //pseudo code
    dx = 0
    dy = 0  //initialise coordinates somehow
    ex = ex
    ey = ey
    A = A
    B = B
    C = C
    
    cosd = ex / B
    cosfi = ((A^2) + (B^2) - (C^2)) / ( 2*A*B)
    d = acos(cosd)      //acos is a method in java.math 
    fi = acos(cosfi)   //you will have to find an equivalent in your chosen language
                      //look for a method of inverse cos
    theta = fi - d
    
    x = A cos(theta)
    y = A sin(theta)
    

    Initialise all variables as those which can take decimals. e.g float or double in Java.

    Imgur

    The green along the x-axis represents the x ordinate of f, and the purple the y ordinate.

    The blue angle is the one we are trying to find because, hopefully you can see, we can then use simple trig to work out x and y, given that we know the length of the hypotenuse.
    This yellow line up to 1 is the unit vector for which scalar products are taken, this runs along the x-axis.

    We need to find the black and red angles so we can deduce the blue angle by simple subtraction.

    Hope this helps. Extensions can be made to 3D, all the vector functions work basically the same for 3D.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i know this sounds really common and so trivial but , am having a
I know this sounds like a stupid question, but I really don't see the
I know this sounds really silly but what character encoding should I use for
I know this sounds like a really obvious question, but it's proving harder to
This sounds like a trivia question but I really need to know. If you
I know this might sound really ridiculas but all of a sudden when I
I know this sounds like a homework assignment, but it isn't. Lately I've been
I know this sounds somewhat counterintuitive, but let me explain what I am trying
I know this sounds like a dumb question but I need to ask this.
Do browser vendors optimize against jQuery? I know this sounds absurd anti-standard, but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.