#### Archived

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

# distance percentage

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

## Recommended Posts

given 3 points, A B and N : we know that N lies upon a straight line between A and B. how do i calculate the percent-distance between A B that N lies (i.e., halfway is 50%)?

##### Share on other sites
If you know N lies on the line, calculate
v1 = B-A
v2 = N-A

if (v1.x != 0) percentage = v2.x/v1.x;
else if (v1.y != 0) percentage = v2.y/v1.y;
else percentage = v2.z/v1.z;

GA

##### Share on other sites
one thing I forgot:
Of course you must

percentage = 100*percentage;

if you want to have the % - value.

GA

##### Share on other sites
Given

A--N------B

The percentage would be (AN/AB)*100

-------------------
Revolver, aka Brian Smith
MIS Programmer Analyst
brian.smith@realpage.com
RealPage >> www.realpage.com

My views aren't even mine, much less my employers. =)

• 15
• 13
• 35
• 39
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!