Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

XEN

Hi! How do I phigure out range between 2 objects?....

This topic is 6148 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi hello! Im new here. What I wantd to know was the phoremula phor how to get the distance between 2 objects. What I mean is, I want to create 2 phunctions that will return the distance between 2 objects. The phirst phunction named range2d() would phigure out the range in 2dimension (x,y), and would take the x y vectors of 2 objects. The second phunction would phigure out the range in 3dimension (x y z) would take the x y z vectors of 2 objects. So, anyone care to help the newbie? Edited by - XEN on December 16, 2001 1:05:38 AM

Share this post


Link to post
Share on other sites
Advertisement
well phrist you should phigure out how to spell correctly...
just an ph-y-i...
your "f" key is located between the ''d'' and ''g'' on your keyboard.



-eldee
;another space monkey;

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Mayb you should''ve explained it in idiot terms? Sorry, I really don''t know that much about math. So I should do something like this:



int range2d(int x1, y1, x2, y2)



{




int distance = ((x1 - x2)^2 + (y1 - y2)^2)^3;



return distnance;


}



Right?

Share this post


Link to post
Share on other sites
No, that''s not correct (close though ). The carrot (''^'') is for exclusive or in C/C++. Here''s a Range2D function (I''m sure you can figure out 3D from this):
  
#include <math.h>

int Range2D(int AX, int AY, int BX, int BY) {
int DeltaX = AX - BX;
int DeltaY = AY - BY;

return (int)sqrt((DeltaX * DeltaX) + (DeltaY * DeltaY));
}

However, you may want to use floats instead of integers.

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i noticed that mostly only very simple questions get answered here.
the question was about the distance between two objects
if points are the only things that are considered to be objects
they the subject would be fine but it''s not

Share this post


Link to post
Share on other sites
Answers to complex questions usually require a multi-post dialog, since people on the forums don''t necessarily have time to hash out a full answer all at once.

I''ll partially address the issue of finding out the distance between two arbitrary objects. It is a minimization problem to find the two points on the objects that represent the closest distance between the objects. Its a constrained problem because the dot product of the normals at those two points has to be negative (so the range is found between parts of the objects that face each other).

A brute force way to do this for polyhedra is to just walk through all possible pairs of vertices or faces between the objects. Too slow too slow. Next step would probably be to do checks between partitions of the objects, such as using OBB trees to narrow the search down to one or two triangles on each object.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!