#### Archived

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

# 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.

## 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 on other sites
This is elementary math. Given Ax, Ay, Bx, and By with A and B as two points you can do this:
Distance = sqrt((Ax - Bx)2 + (Ay - By)2)

Given the additional data of Az and Bz you do do this:
Distance = sqrt((Ax - Bx)2 + (Ay - By)2 + (Az - Bz)2)

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

##### Share on other sites
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 on other sites
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 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 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!]

Thankx!

##### Share on other sites
you spelt phloat wrong

Beer - the love catalyst
kiddies cant spell these days... it''s the phall of western civilization...

--- krez (krezisback@aol.com)

##### Share on other sites
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 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.

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 103
• 11
• ### Forum Statistics

• Total Topics
632977
• Total Posts
3009673
• ### Who's Online (See full list)

There are no registered users currently online

×