Points and Vectors in 3D
Simen kjaeraas
simen.kjaras at gmail.com
Sun Mar 13 08:29:53 PDT 2011
On Sun, 13 Mar 2011 15:43:09 +0100, Simon <s.d.hammett at gmail.com> wrote:
> On 13/03/2011 14:11, Simen kjaeraas wrote:
>> Spacen Jasset <spacenjasset at yahoo.co.uk> wrote:
>>
>>> On 13/03/2011 00:06, Bekenn wrote:
>>>> On 3/12/2011 2:20 PM, Simon wrote:
>>>>> I've done lots of 3d over the years and used quite a lot of different
>>>>> libraries and I've come to prefer code that makes a distinction
>>>>> between
>>>>> points and vectors.
>>>>
>>>> Agreed. This has some nice benefits with operator overloading, as
>>>> well:
>>>>
>>>> vec v = ...;
>>>> pt p = ...;
>>>> auto p2 = p + v; // p2 is pt
>>>> auto p3 = p + p2; // error
>>>> auto v2 = v + v; // v2 is vec
>>>>
>>>> ...and with properties:
>>>>
>>>> p.x = 5; // p is pt, sets p._vals[0]
>>>> v.dx = 3; // v is vec, sets v._vals[0]
>>> Would you then go on to define things like a cross product as an
>>> operator overload?
>>
>> Can't see a fitting operator in D. Multiplication (*) is ambiguous at
>> best
>> and no other operator seems fitting.
>>
>
> Convention is to use ^ as cross product and * as dot product.
Really? I've never heard of it. Rather, everyone I've talked to about it
has said exactly what I did.
--
Simen
More information about the Digitalmars-d-learn
mailing list