Closed markusmoenig closed 6 months ago
Hi. You want to add/subtract/... vectors? You can do that. See https://github.com/basf/rormula
This Python library uses Exmex with a custom data type under the hood for calculating with vectors.
Actually I want to have formulas for dot / cross products and multiplications. Ok, I will take a look thanks.
I see. You could use Exmex and implement those as custom operators with a custom vector data type.
I will read myself into it. But is it possible to access individual vector elements (normal.x) or only the full vector ? (normal).
You can have operators transforming the vectors into scalars. For instance .
could be a binary operator. Then, normal.0
could be what I think you mean with normal.x
. If you want to name the first component with x
then you would need a unary operator and a syntax like get_x(v)
. The result of this and also of, e.g, the dot-product is a scalar. You could have your data type to be an enum
with vector and scalar variants or you could treat scalars as vectors with 1 element. In Rormula I did the former. The 1-element thing I have not tried myself. Now that I am thinking about it, if you want to create a new vector from scalars you probably can use ;
as a binary operator, e.g., like (v.1; v.0)
to swap the first to elements of a vector v
. The comma ,
has a special meaning during parsing so you cannot use this as your own operator.
I don't need to create vectors, just use them. But would be great if we could have an example how to implement vector math one day, I guess more people are interested in this.
Do you mean 3d-vectors? Or any type of dimension? And can you list all operations that you would need?
3D mostly (2D would be nice but could be derived easily I guess). +, -, *, /, dot, length.
and cross-product probably? I assume that you mean * and / component-wise.
I don't really need cross, but yes why not. Actually a clamp would be cool (also for f64, I don't think this is available right now).
Hi,
I love the performance and footprint! I guess basic vector math cannot be added via custom types right ?
Thanks