Home
Categories
Coilguns
AVR Projects
Gumstix Projects
PIC Projects
Tutorials
The Forum
Contact Me

If you like this
site please

page counter

OLED 3-D Triangle

6/18/08
/*is there is no vertical lines then you can calculate things normally*/
if (Poly_2D[poly_num][0][0]!=Poly_2D[poly_num][1][0]&&
Poly_2D[poly_num][0][0]!=Poly_2D[poly_num][2][0]&&
Poly_2D[poly_num][1][0]!=Poly_2D[poly_num][2][0])
{
This section checks to make sure that none of the sides are vertical by checking the X values.
slopetb=Poly_2D[poly_num][topt][1]-Poly_2D[poly_num][bott][1]; //slope=y1-y2/x1-x2
slopetb/=Poly_2D[poly_num][topt][0]-Poly_2D[poly_num][bott][0];
//spit into two lines for greater accuracy
Here we calculate the slope of the longest side using the formula slope=y1-y2/x1-x2 (sometimes writen as slope=y2-y1/x2-x1, but it does not matter as the only thing that matters is x1 and y1 are from the same point and so are x2 and y2). It was split into two lines to keep the compiler for lossing any accuracy.
yinttb=Poly_2D[poly_num][topt][1]-(slopetb*Poly_2D[poly_num][topt][0]);
//Y intersept = y-(m*x)
We use the formula y=mx+b later so we need to know the y intercept (b).
slopes1=Poly_2D[poly_num][topt][1]-Poly_2D[poly_num][side][1];
slopes1/=Poly_2D[poly_num][topt][0]-Poly_2D[poly_num][side][0];

yints1=Poly_2D[poly_num][topt][1]-(slopes1*Poly_2D[poly_num][topt][0]);
This is the same stuff as above except it calculates the slope and y intercept of the line from the top point to the middle point.
for (ypt=Poly_2D[poly_num][topt][1]; //from top point to middle point
ypt>=Poly_2D[poly_num][side][1];
ypt--)
{
horz_lines[line_ct][0]=(ypt-yinttb)/slopetb;
horz_lines[line_ct][1]=(ypt-yints1)/slopes1;
horz_lines[line_ct][2]=ypt;
line_ct++;
}
Here the program goes through the top half of the triangle and finds all the horizontal lines using y=mx+b to find the X values by plugging in all the Y values.
slopes1=Poly_2D[poly_num][side][1]-Poly_2D[poly_num][bott][1];
slopes1/=Poly_2D[poly_num][side][0]-Poly_2D[poly_num][bott][0];
//calculate the slope for the bottom side
yints1=Poly_2D[poly_num][side][1]-(slopes1*Poly_2D[poly_num][side][0]);
Now we calculate the slope of the last line using the same method.
for (ypt=Poly_2D[poly_num][side][1];
ypt>=Poly_2D[poly_num][bott][1];
ypt--)
{
horz_lines[line_ct][0]=(ypt-yinttb)/slopetb;
horz_lines[line_ct][1]=(ypt-yints1)/slopes1;
horz_lines[line_ct][2]=ypt;
line_ct++;
}
Again we calculate the end points of the horizontal lines, but for the bottom half of the triangle.