• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
tKircher

Angle between two 3D points

7 posts in this topic

As the title suggests, i'm trying to find a way to extrapolate the pitch, yaw, and roll between two 3D points. I know how to do this in 2D (atan2 etc), but i'm striking out trying to find a way to do this at all in 3d, let alone in an efficient way. Any help's appreciated.
0

Share this post


Link to post
Share on other sites
Computing the pitch, yaw, and roll 'between two 3D points' doesn't really make any sense. Could you perhaps clarify what it is you're trying to do?
-1

Share this post


Link to post
Share on other sites
a dot b = |a||b|cos(theta), where theta is the angle between the two vectors.

So, to compute theta we need (forgive the bad ascii art):


( a dot b )
theta = acos(---------)
( |a||b| )



a dot b is just the 3d dot product, nice and efficient :). |a| is the magnitude of the vector a.
0

Share this post


Link to post
Share on other sites
Ok well, my routine isn't working, and since all the other calculations are taken line-for-line from code that everyone reports as working, i assume it's this.

All i'm doing is taking the dot product of the two points (taking the x, y, z of each point as vectors and dotting those), then using sin, cos, and tan on the dot to get the three values i'm after. I figured an implicit magnitude of 1 would simplify the equation (divide by 1 is sorta redundant)

However, it doesn't seem to be working. The angles aren't correct, it -always- returns 90 degrees when using the arc-tan/cos/sin, and when using normal cos/tan/sin, it constantly returns a 57.29 degree. This isn't correct, as the angle between the two points is, in fact, exactly 180 degrees.


Quote:
Computing the pitch, yaw, and roll 'between two 3D points' doesn't really make any sense. Could you perhaps clarify what it is you're trying to do?


Well, how about this. I have two points. I want to know the angles that point from one point to the other one. Or, another way of thinking, if i have an entity at one point who isn't rotated at all, how many degrees would such an entity have to rotate to be facing -exactly- at that second point.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by tKircher
Ok well, my routine isn't working, and since all the other calculations are taken line-for-line from code that everyone reports as working, i assume it's this.

All i'm doing is taking the dot product of the two points (taking the x, y, z of each point as vectors and dotting those), then using sin, cos, and tan on the dot to get the three values i'm after. I figured an implicit magnitude of 1 would simplify the equation (divide by 1 is sorta redundant)

However, it doesn't seem to be working. The angles aren't correct, it -always- returns 90 degrees when using the arc-tan/cos/sin, and when using normal cos/tan/sin, it constantly returns a 57.29 degree. This isn't correct, as the angle between the two points is, in fact, exactly 180 degrees.
Sounds like you might be missing a degrees/radians conversion somewhere. (That's just a guess though - maybe you could post the code where you perform these calculations.)
Quote:
Well, how about this. I have two points. I want to know the angles that point from one point to the other one. Or, another way of thinking, if i have an entity at one point who isn't rotated at all, how many degrees would such an entity have to rotate to be facing -exactly- at that second point.
Ok, to rotate an entity to aim at a target, you only need to compute two angles. What you're looking for is a cartesian-to-spherical coordinate conversion, which, given the target position, will return two angles (pitch and yaw, azimuth and elevation - whatever you want to call them).

Unfortunately it can be kind of tricky to get the conversion right, due to the various differing conventions that are used. Note that there are other options as well that don't involve angles or trig - if this is for billboarding, for example, you can usually construct a suitable orientation directly using only vector math. Finally, if this is for AI, and if you want the entity to turn gradually toward the target rather than snapping to it, it would probably be better to transform the target point into the local space of the entity and then apply pitch and yaw deltas based on the local-space position of the target.

So what, ultimately, are you trying to do? With a little more info, we can probably steer you toward a suitable solution.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by tKircher
All i'm doing is taking the dot product of the two points (taking the x, y, z of each point as vectors and dotting those), then using sin, cos, and tan on the dot to get the three values i'm after. I figured an implicit magnitude of 1 would simplify the equation (divide by 1 is sorta redundant)

Well, there are a few problems here :).

First, the formula does not generalize to plug in sin/cos/tan/asin/atan, it only works with acos. Second, unless you are using normalized vectors, dividing by the magnitude is actually very important.

The most serious problem, is I misread your question (went off the title of the post, not the content ;)). The formula I gave you will certainly compute the angle between two vectors. However, that's all it will do.

jyk's post has some good ideas on how to accomplish this.
0

Share this post


Link to post
Share on other sites
As far as i know u can't calculate an angle between two points ... U can calculate an angle between two vectors (or lines)... I calculate an angle between one static line and a ray pointing from a model that i can drag with mouse...

Here's how i do it:

//calculations for angle between ray and point
//edgingPoints are the edging points of a model
lineHorizontal.X = (edgingPoints[4].X + 0.5f) - edgingPoints[4].X;
lineHorizontal.Y = (edgingPoints[4].Y) - (edgingPoints[4].Y);
lineHorizontal.Z = (edgingPoints[4].Z) - (edgingPoints[4].Z);

lineRay.X = rayEnd.X - intersectionPointOnModel.X;
lineRay.Y = rayEnd.Y - intersectionPointOnModel.Y;
lineRay.Z = rayEnd.Z - intersectionPointOnModel.Z;


double dot1Horizontal = lineHorizontal.X * lineRay.X + lineHorizontal.Z * lineRay.Z;
double dot2Horizontal = lineHorizontal.X * lineHorizontal.X + lineHorizontal.Z * lineHorizontal.Z;
double dot3Horizontal = lineRay.X * lineRay.X + lineRay.Z * lineRay.Z;

double angleCosHorizontal = dot1Horizontal / (Math.Sqrt(dot2Horizontal) * Math.Sqrt(dot3Horizontal));

//conversion from radians to degrees:
horizontalAngle = Math.Acos(angleCosHorizontal) * (180 / Math.PI));

Hope it helps with your problem...
0

Share this post


Link to post
Share on other sites
Quote:
First, the formula does not generalize to plug in sin/cos/tan/asin/atan, it only works with acos. Second, unless you are using normalized vectors, dividing by the magnitude is actually very important.


That's all i had to do, as soon as i normalized them the whole thing worked, acos/asin of the dot finally return the correct values!


Thanks for all the help!
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0