CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Distance between points

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Kimi



Joined: 30 Jan 2005
Posts: 23
Location: Argentina

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

Distance between points
PostPosted: Wed Feb 23, 2005 11:19 am     Reply with quote

Hello

I have 3 points with 3 coordinates each one (X,Y,Z). This coordinates are float points number.
Suppose P1, P2, and P3. I need to calculate the ortogonal distance (the shortest distance) between P3 and a line generated by the point P1 and P2.
Any idea of how I can do this this PIC C?


Thanks!
Kimi
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Feb 23, 2005 5:26 pm     Reply with quote

The same way you would with a C program running on a PC. It will just be a bit slower.
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Wed Feb 23, 2005 9:08 pm     Reply with quote

I guess it's in the math so here goes
The points p1 p2 p3 are always coplanar so they form a simple triangle in 2 dimensions

Let the lengths a=distance p1 to p2 b=distance p2 to p3 and c distance p1 to p3

Your triangle now has sides a, b, and c.
Now Calculate S, where S = (a+b+c)/2
So the the area of your Triangle is SQRT(s*(s-a)(s-b)(s-c))

Let x be the length of the orthoganal line between p1 p2 to the point p3
then x represents the height of your triangle p1 p2 p3 so it's area is (height times base)/2
you're almost done

So a.x/2=sqrt(s*(s-a)(s-b)(s-c)) and now you can solve for x the distance you wanted.
Note:
to get the distance d ( p1 to p2) and you have p1 is(x1,y1.z1) and p2 is(x2,y2,z2)
you have d=SQRT( (x1-x2)^2 +(y1-y2)^2+(z1-z2)^2)

Now I'm a fan of the CORDIC which can be thought of as binary angles
the angles are those with tangents of 1 1/2 1/4 1/8 and so on
any angle can be expressed as a sum of these fundamental binary angles
Then by shifting the points representing an object can be rotated in space in this way the plane formed by p1 p2 p3 is rotated into the XY plane by rotational geometry changes and the calculation is reduced to shifts adds and subtractions.
You have cartesians and floats so expect a lot of number crunching on the PIC as it computes the above



Hope I'm not doing your homework assignment for you.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Feb 23, 2005 9:38 pm     Reply with quote

Douglas Kennedy wrote:
Hope I'm not doing your homework assignment for you.


Thus my short response Very Happy
Kimi



Joined: 30 Jan 2005
Posts: 23
Location: Argentina

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

PostPosted: Thu Feb 24, 2005 5:02 am     Reply with quote

Wouw! Yesterday I was trying to find a relationship between sides of the trieangle, but never take in consideration the Area. Thanks very much!
I will test it today!

Thanks!!!
Kimi
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group