image-rs / imageproc

Image processing operations
MIT License
758 stars 150 forks source link

Support drawing oblique ellipse #409

Open J-F-Liu opened 4 years ago

J-F-Liu commented 4 years ago

For an ellipse with center (u, v), semi-axis (a, b), angle θ, the circum points can be calculated from parametric equation and 2D rotation:

x = a cost cosθ - b sint sinθ + u
y = a cost sinθ + b sint cosθ + v
t ∈ [0, 2π)

To draw elliptic arc, set t ∈ [start_angle, end_angle].

RReverser commented 3 years ago

I was going to raise an issue for supporting angle on ellipse - is this the same feature request or something different?

J-F-Liu commented 3 years ago

I think it's the same feature.

RReverser commented 3 years ago

Thinking about this more - the same would probably apply to e.g. rectangles.

I wonder if a better solution would be to allow to wrap Canvas into a cheap newtype combined with Projection (https://docs.rs/imageproc/0.22.0/imageproc/geometric_transformations/struct.Projection.html) so that any drawings onto such wrapper would be automatically translated before drawn onto the inner canvas (actual image).