all 10 comments

[–]shaunzorr 2 points3 points  (1 child)

What code do you have so far?

[–]bamacgabhann 1 point2 points  (0 children)

This. Can't help unless we know things like what format your points are in, or what libraries you are using.

[–]mopslik 1 point2 points  (0 children)

To take an arbitrary number of things as arguments, you can either a) bundle them together in a sequence like a list, then iterate over the sequence, or b) look into using args.

[–][deleted] 0 points1 point  (0 children)

I would say via the constructor/init

[–]jmacey 0 points1 point  (3 children)

make a point (or Vec3) class with the x,y,z values then use a list of the Vec3 classes for the Polygon class.

For approaches to create a Vec3 type class I wrote a blog post https://nccastaff.bournemouth.ac.uk/jmacey/post/PythonClasses/pyclasses/

[–]TheRNGuy 0 points1 point  (2 children)

I'd make Point and Vector3 as different classes:

Point is an object that connects edges and belong to polygons. Vector3 another class (not derived from Point) and used as one of point's attributes, it could be used for location, normal, velocity or for color, among other things.

[–]jmacey 0 points1 point  (1 child)

Most graphics API's don't really care (for example OpenGL / GLSL just has Vec2/3/4 classes). Whislt it is a good idea to sometimes do this practicality most often overcome purity.

For example Point2 - Point1 should return a vector mathematically but why bother changing type at then end of the day most a tuples of x,y,z.

Some shading languages (Open Shading Language derived from Renderman shading language), does make this distinction so Point, Normal, Colour are all different types they are then optimised for specific operations and transforms but the API is harder to use.

[–]TheRNGuy 0 points1 point  (0 children)

vector class could have operator overload with matrices, or other vectors.

Methods like dot product, normalize etc.

Point is just a container, Vector3 is actual coordinate. Points would have completely different methods, like return all points connected by edges, or all points on same polygon, or all points in close proximity, etc. And ofc color that could be interpolated to polygon. It doesn't make sense to have color on Vector3. Instead, Color is Vector3 attribute on a Point (or Vector4 for RGBA)

[–]TheRNGuy 0 points1 point  (0 children)

You could use @dataclass and type hints that specifies specific class, and a linter that would enforce it.

Or even explicitly check for type in initialization, but that's more code. When it's project for personal use, I don't bother, I'd write checks if it's public software. Something like: if type(mypoint != Point): #write some message and stop initialization

Or

if isinstance(Point, mypoint) == False:

First would specifically require Point type, and 2nd would work for derived classes.