' P545 - Embedded & Real-Time Systems'
What do we have here ? - This page serves as a toolkit that can be referred to solve some of the problems faced while working on the P545-ERTS cart.
* Find additional points between 2 points -
Given two points P1 and P2 with coordinates (x1,y1) and (x2,y2), additional points between P1 and P2 can be generated by using the parametric equation of a line.
Parametric equation of a line
x(t) = x1 + t(x2-x1)
y(t) = y1 + t(y2-y1)
where t varies from 0 to 1
Example - For 10 additional points between P1 and P2, change t from 0 to 1 in increments of 1/10=0.1 and get x and y coordinates of the 10 points using the parametric equations cited above.
* Find orientation of a point with respect to another point -
Given three points P1,P2 and P3 with coordinates (x1,y1), (x2,y2) and (x3,y3). How to determine whether point P3 is on the left or right of P2 when seen from P1 ?
Image1 - Point P3 is on the left of P2 when observed from point P1
Image2 - Point P3 is on the right of P2 when observed from point P1
Signed area of triangle using vector points can be used to determine the orientation. Consider P1, P2 and P3 as points in vector space lines joining P1 to P2, P2 to P3 and P3 to P1 (not shown in either of the images) as vectors. Image1 shows a triangle whose vector sides are oriented in counter clockwise direction whereas Image2 shows a triangle whose vector sides are oriented in clockwise direction.
Consider the triangle shown in Image3. v is a vector from P1 to P2 and n is a vector normal to v. Area of the triangle = 1/2 * base * height
= 1/2 * h * v = 1/2 * (vector n)/v * (vector P3 - vector P2) * v
= 1/2 * (x1(y2-y3) - x2(y1-y3) + x3(y1-y2))
If the area is positive then the point P3 is to the left of P2 when viewed from P1. If the area is negative then the point P3 is to the right of P2 when viewed from P1.
* Check if a point is inside a polygon or not -
Consider the polygon shown in Image4. It has vertices a1,a2,a3,a4,a5. The following set of steps should help in ascertaining whether point P lies inside the polygon or outside.
Refer to Image 4 and compute the vector area of the triangle formed by edge a1->a2 and the red vectors connecting a2 to P and P to a1. Refer to Image 5 and compute the vector area of the triangle formed by edge a2->a3 and the red vectors connecting a3 to P and P to a2. Similarly, compute the vector area of the each of the possible triangles having one side as the side of the polygon and the other two connecting P to that side.
For a point to be inside a polygon, each of the triangles need to have positive area. Even if one of the triangles have a negative area then the point P stands out of the polygon.
Attachments
- Image1.jpg (4.2 kB) -
Image1
, added by arkautuc on 11/02/08 20:08:02. - Image2.jpg (4.1 kB) -
Image2
, added by arkautuc on 11/02/08 20:10:35. - Image3.jpg (7.4 kB) -
Image3
, added by arkautuc on 11/02/08 21:42:38. - Image4.jpg (7.0 kB) -
Point in a polygon - part a
, added by arkautuc on 11/15/08 03:09:15. - Image5.jpg (7.1 kB) -
Point in a polygon - part b
, added by arkautuc on 11/15/08 03:10:09.





