Point3D Line3D::intersect_coplanar(Line3D another) { Point3D line_a_origpt = orig_pt(); Vector3D line_a_versor = versor(); Point3D line_b_origpt = another.orig_pt(); Vector3D line_b_versor = another.versor(); // creates a triplet of coplanar, non-coincident points double delta_distance = 100.0; Vector3D displ_vector_a = line_a_versor.scale(delta_distance); Vector3D displ_vector_b = line_b_versor.scale(delta_distance); Point3D point_a = Point3D(line_a_origpt.x(), line_a_origpt.y(), line_a_origpt.z()); Point3D point_b = displ_vector_b.move_pt(point_a); Point3D point_c = displ_vector_a.move_pt(point_a); CartesianPlane colinear_plane = CartesianPlane(point_a, point_b, point_c); //code inspired to: http://geomalgorithms.com/a05-_intersect-1.html#intersect2D_2Segments() Vector3D w_vect = Vector3D( line_a_origpt, line_b_origpt ); Vector3D vers_a_perp = colinear_plane.perp_versor_in_plane(line_a_versor); double factor_numerator = - vers_a_perp.scalar_prod(w_vect); double factor_denominator = vers_a_perp.scalar_prod(line_b_versor); double factor_scaling = factor_numerator / factor_denominator; Point3D intersection_pt3d = line_b_versor.scale(factor_scaling).move_pt(line_b_origpt); return intersection_pt3d; };
Vec3 DiffuseMaterial::out_direction(Vec3 const &in, Vec3 const &norm, double &brdf, RGB &color, CRandomMersenne *rng) { // Generamos una nueva direccion. Sera una direccion aleatoria en la // semiesfera definida por la normal. brdf = 1.0f; color = radiance() * brdf; return versor(random_dir(norm, rng->Random(), rng->Random())); }
bool Line3D::isparallel(Line3D another) { Vector3D vers_a = versor(); Vector3D vers_b = another.versor(); if (vers_a.isodirection(vers_b)) { return true; } else { return false;}; };
bool Line3D::iscoincident(Line3D another) { if (not isparallel(another)) { return false; }; Point3D orig_pt_a = orig_pt(); Point3D orig_pt_b = another.orig_pt(); if (orig_pt_a.is_coincident(orig_pt_b)) { return true; } else { Vector3D test_line = Vector3D(orig_pt_a, orig_pt_b); if (test_line.isodirection(versor())) { return true;} else { return false;} } };
void Transform::rotate(double angle, const Vec3 &axis) { Matrix4x4 mtemp; Vec3 vtemp = versor(axis); double sin_a = sin(angle * (kpi/180.f)); double cos_a = cos(angle * (kpi/180.f)); if(sin_a < kmin_value) sin_a = 0.0f; if(cos_a < kmin_value) cos_a = 0.0f; mtemp.e[0][0] = cos_a + vtemp.x() * vtemp.x() * (1.0f - cos_a); mtemp.e[0][1] = vtemp.x() * vtemp.y() * (1.0f - cos_a) - vtemp.z() * sin_a; mtemp.e[0][2] = vtemp.x() * vtemp.z() * (1.0f - cos_a) + vtemp.y() * sin_a; mtemp.e[0][3] = 0.0f; mtemp.e[1][0] = vtemp.x() * vtemp.y() * (1.0f - cos_a) + vtemp.z() * sin_a; mtemp.e[1][1] = cos_a + vtemp.y() * vtemp.y() * (1.0f - cos_a); mtemp.e[1][2] = vtemp.y() * vtemp.z() * (1.0f - cos_a) - vtemp.x() * sin_a; mtemp.e[1][3] = 0.0f; mtemp.e[2][0] = vtemp.x() * vtemp.z() * (1.0f - cos_a) - vtemp.y() * sin_a; mtemp.e[2][1] = vtemp.x() * vtemp.z() * (1.0f - cos_a) + vtemp.x() * sin_a; mtemp.e[2][2] = cos_a + vtemp.z() * vtemp.z() * (1.0f - cos_a); mtemp.e[2][3] = 0.0f; mtemp.e[3][0] = 0.0f; mtemp.e[3][1] = 0.0f; mtemp.e[3][2] = 0.0f; mtemp.e[3][3] = 1.0f; mtx = mtemp * mtx; inv = mtx.get_inv(); }