Coder Social home page Coder Social logo

Comments (12)

RemDelaporteMathurin avatar RemDelaporteMathurin commented on September 20, 2024 2

@gonuke I think I've now understood what you wanted to do: extrude a 2D shape in the workplane normal direction but define the workplane from a normal vector.

Can you please confirm?

If so, I've managed to achieve this with minimal changes to the code.

In red below is the rotated_solid with extrusion direction (1, 1, 1).

image

Code:

import paramak
from cadquery import Plane


points = [
    (0, 0),
    (1, 0),
    (1, 1),
    (0, 1)
]

shape_1 = paramak.ExtrudeStraightShape(points=points, distance=1)

normal_vec = (1, 1, 1)

shape_2 = paramak.ExtrudeStraightShape(
    points=points, distance=1,
    workplane=Plane(origin=(0, 0, 0), xDir=(-1, 1, 0), normal=normal_vec),
    rotation_axis=[(0, 0, 0), normal_vec])

shape_1.export_stl('non_rotated.stl')
shape_2.export_stl('rotated.stl')

from paramak.

shimwell avatar shimwell commented on September 20, 2024 1

Hi @gonuke thanks for the suggestion. It makes a lot of sense and would be a nice upgrade.

This is not exactly what you asked for but perhaps of interest
sweep shapes allow a list of coordinates to specified and will sweep a cross section between the coordinates.
https://paramak.readthedocs.io/en/main/paramak.parametric_shapes.html#swept-shapes
If there are only two points in the path_points then it is effectively an extrude.

import paramak

test_shape = paramak.SweepStraightShape(
    points=[(-10, 10), (10, 10), (10, -10), (-10, -10)],
    path_points=[(50, 0), (50, 150)]
)

test_shape.show()

Screenshot from 2021-09-07 20-51-31

I'm going to dig into the CadQuery documentation a bit and see what can be done to enhance the extrude shapes and see if how to go about accepting a unit vector

from paramak.

RemDelaporteMathurin avatar RemDelaporteMathurin commented on September 20, 2024 1

This seems to do the job.

I shall integrate it asap in a new PR.

image

from paramak import ExtrudeMixedShape, Shape
from paramak.utils import calculate_wedge_cut
from cadquery import Vector, Solid


class ExtrudeMixedShapeBis(ExtrudeMixedShape):
    def __init__(self, extrusion_vector='ortho', **kwargs):
        super().__init__(**kwargs)
        self.extrusion_vector = extrusion_vector

    def create_solid(self):
        """Creates an extruded 3d solid using points connected with straight
        and spline edges.

           Returns:
              A CadQuery solid: A 3D solid volume
        """

        workplane = Shape.create_solid(self)

        if not self.extrude_both:
            extrusion_distance = -self.distance
        else:
            extrusion_distance = -self.distance / 2.0

        wire = workplane.close()
        self.wire = wire

        if type(self.extrusion_vector) is str and self.extrusion_vector == 'ortho':
            solid = wire.extrude(
                distance=extrusion_distance,
                both=self.extrude_both)
        else:
            wireSets = [list(wire.ctx.pendingWires)]
            solid = Solid.extrudeLinear(
                outerWire=wireSets[0][0],
                innerWires=[],
                vecNormal=self.extrusion_vector,
                taper=0
            )

        # filleting rectangular port cutter edges
        # must be done before azimuthal placement
        if hasattr(self, "add_fillet"):
            solid = self.add_fillet(solid)

        solid = self.rotate_solid(solid)
        cutting_wedge = calculate_wedge_cut(self)
        solid = self.perform_boolean_operations(solid, wedge_cut=cutting_wedge)
        self.solid = solid

        return solid


points = [
    (0, 0, "straight"),
    (1, 0, "straight"),
    (1, 1, "straight"),
    (0, 1, "straight"),
]

my_shape = ExtrudeMixedShapeBis(points=points, distance=1, extrusion_vector=Vector((1, 1, 1)))  # 
my_shape.export_stl('out.stl')

from paramak.

gonuke avatar gonuke commented on September 20, 2024

Will the working plane of the shape be rotated to be normal to this path?

from paramak.

shimwell avatar shimwell commented on September 20, 2024

Unfortunately not.

from paramak.

shimwell avatar shimwell commented on September 20, 2024

I think I would need to add some new args based on the cadquery vector class https://cadquery.readthedocs.io/en/latest/classreference.html#cadquery.Vector
I've used that before but it looks like the right direction to go in.

from paramak.

gonuke avatar gonuke commented on September 20, 2024

That may be one approach, but someone on my team was already doing some rotation math to work around thus by calculating the rotation operations to convert from one of those convenient forms to the rotation system already supported

from paramak.

shimwell avatar shimwell commented on September 20, 2024

Interesting, @RemDelaporteMathurin will be interested in that, he made a point rotation function and recently raised an issue requested rotation methods

from paramak.

RemDelaporteMathurin avatar RemDelaporteMathurin commented on September 20, 2024

@shimwell @gonuke this is indeed a feature that - i think - is not yet implemented in the Paramak.
Do we agree that this is the expected behaviour? (apologies, my drawing skills are obviously a bit rusty)
With v the unit vector of the extrusion?
image

I think this behaviour could be obtained with sweep shapes but that's maybe using a sledgehammer to beat a fly.

Cadquery natively provides a method to achieve this.

The class ExtrudeMixedShape (and in particular its create_solid method) would need to be extended a bit but that seem feasible to me.

from paramak.

RemDelaporteMathurin avatar RemDelaporteMathurin commented on September 20, 2024

As far as I can tell, the extruded shapes are all derived from Shape and extruded in a direction normal to the workplane and then rotated according to the definition of the rotation_axis and the azimuth_placement_angle.

Not exactly. The parametric shapes are either extruded or rotated. The first step is to give a bunch of points describing a 2D shape (eg the black square I draw above). This 2D shape is then extruded or rotated around a rotation axis (according to rotation_angle).

The azimuth_placemen_angle can be seen as the position of the 2D shape before rotating it.

from paramak.

zxo102 avatar zxo102 commented on September 20, 2024

@gonuke pytransform3d may help. Check pytransform3d's documentation. As mentioned in it's README.md, you can easily extract the relevant code for your purpose.

from paramak.

shimwell avatar shimwell commented on September 20, 2024

solved in PR #84

from paramak.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.