![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
horkesley
Joined: 20 Feb 2007 Posts: 48 Location: Essex UK
|
Imagine a rectangle |
Posted: Tue Mar 25, 2008 12:32 pm |
|
|
Hi,
Imagine a rectangle, size not important, but in the order of 30,40 metres.
From each corner I want to create an arc numerically (not on a screen), a list of x,y coordinates forming an arc.
I can use x=r*cos theta and y=r*sin theta to produce a list of x,y data, where r=radius.
How can I place each arc in the corner of the rectangle?
Any ideas would be of interest.
Regards, _________________ Horkesley Electronics Limited |
|
![](templates/subSilver/images/spacer.gif) |
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Tue Mar 25, 2008 2:12 pm |
|
|
You didn't state explicitly what you are looking to do but this might be of help.
Well x=rcos theta y=r sin theta has the assumption of a center at 0,0 in Cartesian coordinates. Now what you need to decide is where you need the center for your arc to accomplish your goal. This choice of the center makes for a transform
x'=dx+rcos theta y'=dy+rsin theta. where the new center is (dx,dy). Often if you set the left bottom corner of your rectangle to have (0,0) as its coordinates and align the sides with the axis the calculation is simplified.
Now I hope you aren't planning on a crop circle hoax. Crop circles are involute curves formed by having a string fixed in someway (like wrapped around a fixed barrel) and tracing a curve by keeping it taut as it unwinds. If ET is making these circles involute must be the only curve they know of. |
|
![](templates/subSilver/images/spacer.gif) |
horkesley
Joined: 20 Feb 2007 Posts: 48 Location: Essex UK
|
circle |
Posted: Tue Mar 25, 2008 3:00 pm |
|
|
Hi,
Within the rectangle a 'mobile' knows it distance from each corner.
I can cast an arc from each corner and look for an overlap to establish the position of the mobile within the rectangle.
Three or four overlaps will create an area where the mobile is.
This is an RF system and much checking is required due to multipath etc.
A lot of the work is completed but generating arcs and looking for a 'window' is yet to be completed.
Regards, _________________ Horkesley Electronics Limited |
|
![](templates/subSilver/images/spacer.gif) |
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Wed Mar 26, 2008 2:17 am |
|
|
The solution involves an area in which the precise position of your mobile is located. The area is shaped by the arcs subtending from the corners. The issue will be notating this area efficiently using the PIC. If the arcs overlap thats one thing if they don't overlap its another, if some do and others don't its another also.You could pixelate the rectangle and notate the area as the list of pixels within the area. I'd look at a finite difference approach. Look at the circle algorithms for drawing a circle on an LCD screen. Using Breshenhams circle algorithm centered on one corner select in all the pixels within the arc and give them an attribute of one. Move to the next corner all pixels within this arc and also within the first get an attribute of two otherwise an attribute of one. Move to the next corner same thing with attribute of one for no overlaps two for two overlaps 3 for three overlaps. On to the last corner. Think of it as coloring an lcd screen where the color deepens depending on the overlaps. Pixels with a count of 4 are your best position values 3 next best. If you could estimate the error on your radius then I'd use the error as a brush width and deepen the color of the overlapping brush strokes. The nice thing about finite differences is that you won't need the cos sine float notation at all everything will be integer arithmetic with few multiplications so it will be fast and give every chance of keeping up with rapid position changes of your mobile should they occur. I know you object to a screen approach but the sine and cosine functions are infinitely smooth mathematically this means it is impossible to represent them in a digital device without in effect destroying the smoothness by truncating them at a finite number of bits of storage. This is no different than pixelating your rectangle to accommodate storage. Suppose you pixelate to sq meters then you rectangle is 30 by 40 1200 pixels. At 1 sq cm you have 12 million so your choice of precision will be critical to your storage notation. The notation could be the start and end points and the radius of each arc ( 3 numbers) with the notation fed into a difference routine that would compute the pixel space. The space is stored as 4 sets of 3 numbers and computed when needed rather than kept as a list of pixels. |
|
![](templates/subSilver/images/spacer.gif) |
horkesley
Joined: 20 Feb 2007 Posts: 48 Location: Essex UK
|
Imagine a rectangle |
Posted: Sat Mar 29, 2008 5:37 am |
|
|
Hi Douglas
Thanks for your comments.
Your ideas are more or less the way I am thinking. I visualized a spead sheet sort of approach with the cells having attributes.
The sells not only have the 1,2,3 attributes that you suggest to indicate arcs over lapping, but various other details are also attached to cells.
In terms of resolution I only need to achieve about 100cm accuracy in the cell.
Thanks for your comments. _________________ Horkesley Electronics Limited |
|
![](templates/subSilver/images/spacer.gif) |
horkesley
Joined: 20 Feb 2007 Posts: 48 Location: Essex UK
|
Bresenham |
Posted: Sun Apr 13, 2008 1:35 pm |
|
|
Hi,
I have been trying to use Bresenham algorithim to plot an arc.
I can't control the increment size as the radius figure controls the number of calculations.
I want to calculate an x and y coordinate for every degree of arc, for 90 degrees with a max radius of 50 m, this should give the resolution I require.
I have searched the web for ides but have not been able to resolve this.
Any ideas anyone? _________________ Horkesley Electronics Limited |
|
![](templates/subSilver/images/spacer.gif) |
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Mon Apr 14, 2008 11:14 am |
|
|
The radius issue is wrapped up in the granularity you choose for your rectangle. Think of this as pixelating the rectangle. For long 16bit numbers your radius pixels can be in the 10k range. Your worst case would be a radius equal to the diagonal of the rectangle. Now the difference mathematics for a circle takes into account the 8 fold symmetry so it stays in the N to NE sector and proceeds with south and southeast steps. The code below was modified by me to allow for an aspect ratio . LCD pixels aren't always square Ex 5x7 hence the aspect ration. The pixelation below was 240 so a long int was needed since any small multiplication would lead to wrap around if 8 bits were used.
Code: | void circle(long x_ctr,long y_ctr,long radius,long aspect_num,long aspect_denom,int pen_size,int set)
{
long x,y,r,x1,y1;
signed long delta;
// y axis is shrunk to reflect the aspect ratio
// this uses bresenham's algorithm
// theory
// 0=x^2+y^2-r^2 is true circle centered at 0,0
// error is x^2+y^2-r^2
// looking at north to north east octant
// pixels are * 0
// 0
// algorithm chooses pixel due east or south east
// * has the coord (x,y) both 0 pixels have an x coord of x+1
// mid pt has coord of (x+1,y+1/2)
// error is (x+1)^2+(y+1/2)^2 -r^2
// error >0 draw south east ( x+1,y-1) pixel else draw east pixel (x+1,y)
// now we can compute the error in advance for the next iteration
// change in error from (x+1,y-1/2) to (x+2,y-1/2) is 2x+3
// (x+1,y-1/2) to (x+2,y-3/2) 2x+3 -2y+2
// Note: delta is the error in the code below
// if delta is <0 then we decrement y
r=239;
if (radius<239) r=radius; // max radius is 239 pixels
for (r=radius-pen_size;r<=radius;r++)
{
x=0;
y=r;
// assume last step was to south east pixel from (0,r) or 2*0-2*r+5
delta=(long)5-(long)2*(long)r;
loop:
y1=(long)y*aspect_num/aspect_denom; /// aspect ratio
x1=(long)x*aspect_num/aspect_denom; /// aspect ratio
plot(x_ctr+x,y_ctr+y1,set);
plot(x_ctr+x,y_ctr-y1,set);
plot(x_ctr-x,y_ctr+y1,set);
plot(x_ctr-x,y_ctr-y1,set);
plot(x_ctr+y,y_ctr+x1,set);
plot(x_ctr+y,y_ctr-x1,set);
plot(x_ctr-y,y_ctr+x1,set);
plot(x_ctr-y,y_ctr-x1,set);
if (delta<0) delta=delta+(long)2*(long)x+(long)3;
else {delta=delta+(long)2*((long)x-(long)y)+(long)5;y=y-1;}
x=x+1;
if (x<=y) goto loop;
}
}
clear_screen(char c)
{
int i,j;
for (j=0;j<240;j++) for (i=0;i<80;i++)
{
write_addr(i,j,0,c); // top
write_addr(i,j,1,c); // botom
}
return;
} |
|
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|