Skip to content
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

The result of swept_volume if align_rotations_with_velocity is True AND The Swept Path is a Spiral #136

Open
XYZ-Lenari opened this issue Jul 9, 2024 · 1 comment

Comments

@XYZ-Lenari
Copy link

When the grinding wheel swept along the helix, I set the align_rotations_with_velocity to True and False respectively, and the result of True is a bit strange. Following is my code:

import polyscope

from test.context import gpytoolbox
from test.context import numpy as np
from test.context import unittest
from gpytoolbox import read_mesh
from gpytoolbox.copyleft import swept_volume
from gpytoolbox.copyleft import mesh_boolean
from gpytoolbox.copyleft import do_meshes_intersect

import polyscope as ps
ps.init()

# Read sample mesh
v, f = gpytoolbox.read_mesh("D:/pycharmpro/gpytoolbox/test/unit_tests_data/wheel.obj")
ps.register_surface_mesh("Wheel",v,f)

# Translation vectors to make Catmull-Rom spline
def generate_spiral_translations(radius, start_y, end_y, num_steps, pitch):
    """
    Generate translation vectors along a helical path around the y-axis,
    with specified start and end y-coordinates.

    Parameters:
    radius (float): Radius of the helix in the xz-plane.
    start_y (float): Starting y-coordinate of the helix.
    end_y (float): Ending y-coordinate of the helix.
    num_steps (int): Number of steps along the helix.
    pitch (float): Vertical distance (height) for one full rotation around the y-axis.

    Returns:
    translations (np.ndarray): Array of translation vectors (x, y, z).
    """
    # Calculate the height per step
    total_height = end_y - start_y
    h_step = total_height / num_steps

    # Initialize an empty array to store the translations
    translations = np.zeros((num_steps, 3))

    # Generate the translations
    for i in range(num_steps):
        # Calculate the angle for the current step
        # Use pitch to determine the angle per step, considering the full height of the helix
        theta = 2 * np.pi * i / (num_steps * pitch)

        # Calculate the x and z coordinates based on the angle and radius
        x = radius * np.cos(theta)
        z = radius * np.sin(theta)
        y = start_y + i * h_step  # Adjust y based on start_y and step height

        # Store the translation vector
        translations[i] = [x, y, z]

    return translations

# Example usage
radius = 0.025
start_y = -0.07
end_y = 0.07
num_steps = 50
pitch = 0.2  # Controls the number of rotations over the height

translations = generate_spiral_translations(radius, start_y, end_y, num_steps, pitch)

# Call swept volume function
u1,g1 = swept_volume(v,f,rotations=None,translations=translations,eps=0.001,verbose=True,align_rotations_with_velocity=True)
ps.register_surface_mesh("Swept_Volume1",u1,g1)

u2,g2 = swept_volume(v,f,rotations=None,translations=translations,eps=0.001,verbose=True,align_rotations_with_velocity=False)
ps.register_surface_mesh("Swept_Volume2",u2,g2)
ps.show()

The result:

align_rotations_with_velocity=True
align_rotations_with_velocity_T

align_rotations_with_velocity=False
align_rotations_with_velocity_F

It looks like one side is normal, and the other side is wrong. I don't know if it's due to my helix generation function. You can try to set a sweep with a path as a spiral and see if a similar problem occurs?
align_rotations_with_velocity

@sgsellan
Copy link
Owner

sgsellan commented Jul 9, 2024

Hi! This is an interesting result: it definitely seems like a bug in the code that orients the shape with its velocity vector. I will take a look once I have a minute. Please try to use it with align_rotations_with_velocity=False for now

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

No branches or pull requests

2 participants