Points and Vectors in 3D

Simon s.d.hammett at gmail.com
Sun Mar 13 07:43:09 PDT 2011


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.

-- 
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk


More information about the Digitalmars-d-learn mailing list