Skip to content

intersection methods #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: develop
Choose a base branch
from

Conversation

aaronkreuz
Copy link
Contributor

Added new intersection methods, including test cases for all new methods.

// one point of the segment is inside the cylinder and one is outside -> intersection must exist
auto param = con_pos0 ? max(insec.value().start, insec.value().end) : min(insec.value().start, insec.value().end);
return segment<3, ScalarT>{segment_line.pos + segment_line.dir * param, con_pos0 ? s.pos0 : s.pos1};
float param = (dot(s.pos1 - s.pos0, segment_line[insec.value().start]) > 0) ? insec.value().start : insec.value().end;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

float -> auto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 -> ScalarT(0)

[[nodiscard]] constexpr hits<2, pos<3, ScalarT>> intersection_segment_boundary_impl(segment<3, ScalarT> const& s, B const& b)
{
// line extension of segment
auto const line = line3::from_points(s.pos0, s.pos1);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line3 -> line<3, ScalarT>

@@ -2919,7 +3275,7 @@ template <class ScalarT>
template <class ScalarT>
[[nodiscard]] constexpr bool intersects(box<2, ScalarT> const& box, sphere<2, ScalarT> const& sphere)
{
array<pos<2, ScalarT>, 4> vertices_box = vertices_of(box);
// array<pos<2, ScalarT>, 4> vertices_box = vertices_of(box);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused?

template <class ScalarT>
[[nodiscard]] constexpr optional<segment<3, ScalarT>> intersection(segment<3, ScalarT> const& segment, halfspace<3, ScalarT> const& halfspace)
{
bool cont_pos0 = contains(halfspace, segment.pos0);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if order of segment points is consistent with the output segment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also check for generic case

{
return intersects(c, t);
auto plane = tg::plane3(disk.normal, disk.center);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plane3

tg::pos<3, ScalarT> disk_center = project(sphere.center, plane);

// pythagoras
auto rad = sqrt(sphere.radius * sphere.radius - distance_sqr(sphere.center, disk_center));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove early out and check if sqrt argument is negative.

// vector orthogonal to cylinder axis and plane normal
vec<3, ScalarT> orth_vec1 = cross(cylinder.axis.dir, plane.normal);

if (length(orth_vec1) == 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if is_zero_vector(orth_vec1)

vec<3, ScalarT> orth_vec2 = cross(orth_vec1, plane.normal);

// second semi-axis
vec<3, ScalarT> semi_vec2 = cylinder.radius / (tg::sin(tg::angle_between(cylinder.axis.dir, plane.normal))) * normalize(orth_vec2);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

represent as cross product

template <class ScalarT>
[[nodiscard]] constexpr optional<segment<3, ScalarT>> intersection(disk<3, ScalarT> const& disk, plane<3, ScalarT> const& plane)
{
if (length(cross(disk.normal, plane.normal)) == 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check is zero

{ // b) xz-plane and disk with random orientation - intersection through origin
auto disk = tg::disk3(tg::pos3::zero, 1.f, tg::uniform<tg::dir3>(rng));

bool insec_exists = (disk.normal == plane_xz.normal) ? false : true;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants