working on shapes/Cyl
git-svn-id: svn://anubis/fart/trunk@131 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
561098001a
commit
d8648b0770
@ -16,6 +16,7 @@ Cyl::Cyl(double bottom_radius, double top_radius, double height)
|
|||||||
m_height = fabs(height);
|
m_height = fabs(height);
|
||||||
if (m_height == 0.0)
|
if (m_height == 0.0)
|
||||||
m_height = 1.0;
|
m_height = 1.0;
|
||||||
|
m_slope = (m_top_radius - m_bottom_radius) / m_height; /* rise over run */
|
||||||
}
|
}
|
||||||
|
|
||||||
Shape::IntersectList Cyl::intersect(const Ray & ray)
|
Shape::IntersectList Cyl::intersect(const Ray & ray)
|
||||||
@ -28,9 +29,33 @@ Shape::IntersectList Cyl::intersect(const Ray & ray)
|
|||||||
* x = R0x + tRdx
|
* x = R0x + tRdx
|
||||||
* y = R0y + tRdy
|
* y = R0y + tRdy
|
||||||
* z = R0z + tRdz
|
* z = R0z + tRdz
|
||||||
* Side equation: x^2 + y^2 =
|
* Side equation: x^2 + y^2 = (m*z + b)^2
|
||||||
* Combined:
|
* Combined: (R0x+t*Rdx)^2 + (R0y+t*Rdy)^2 = (m*(R0z+t*Rdz) + b)^2
|
||||||
|
* Expanded: (R0x*R0x + (t*t)*Rdx*Rdx + 2*R0x*t*Rdx)
|
||||||
|
* + (R0y*R0y + (t*t)*Rdy*Rdy + 2*R0y*t*Rdy)
|
||||||
|
* = ((m*R0z+m*t*Rdz)^2 + b*b + 2*m*(R0z+t*Rdz)*b)
|
||||||
|
* = ((m*R0z*m*R0z + m*m*t*t*Rdz*Rdz + 2*m*R0z*m*t*Rdz)
|
||||||
|
* + b*b + 2*m*R0z*b + 2*m*t*Rdz*b)
|
||||||
|
* Quadratic form: (t*t)(Rdx*Rdx + Rdy*Rdy - m*m*Rdz*Rdz)
|
||||||
|
* + (t)(2*R0x*Rdx + 2*R0y*Rdy - 2*m*R0z*m*Rdz - 2*m*Rdz*b)
|
||||||
|
* + (R0x*R0x + R0y*R0y - m*m*R0z*R0z - b*b - 2*m*R0z*b)
|
||||||
|
* = 0
|
||||||
*/
|
*/
|
||||||
|
double Rdx = ray_inv.getDirection()[0];
|
||||||
|
double Rdy = ray_inv.getDirection()[1];
|
||||||
|
double Rdz = ray_inv.getDirection()[2];
|
||||||
|
double R0x = ray_inv.getOrigin()[0];
|
||||||
|
double R0y = ray_inv.getOrigin()[1];
|
||||||
|
double R0z = ray_inv.getOrigin()[2];
|
||||||
|
double m = m_m;
|
||||||
|
double m2 = m*m;
|
||||||
|
QuadraticSolver solver(Rdx * Rdx + Rdy * Rdy - m2 * Rdz * Rdz,
|
||||||
|
2.0 * (R0x*Rdx + R0y*Rdy - m2*R0z*Rdz - m*Rdz*m_b),
|
||||||
|
R0x*R0x + R0y*R0y
|
||||||
|
- m2*R0z*R0z - m_b*m_b - 2*m*R0z*m_b
|
||||||
|
);
|
||||||
|
|
||||||
|
Solver::Results results = solver.solve();
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ class Cyl : public Shape
|
|||||||
double m_top_radius;
|
double m_top_radius;
|
||||||
double m_top_radius_2;
|
double m_top_radius_2;
|
||||||
double m_height;
|
double m_height;
|
||||||
|
double m_slope;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user