Result:
Assignment contents:
Analysis:
The only detail that needs special attention is that the vectors use homogeneous coordinates: w = 0 represents a direction vector, and w = 1 represents a point. As long as you handle the arithmetic rules between points and direction vectors correctly, everything will be fine. That mainly means you should separate cases and apply the correct semantics for each operation.
For example:
-
Addition
-
Point + Direction = Point
(translate a point by a direction) -
Direction + Direction = Direction
(vector addition) -
Point + Point = Undefined / Not Allowed
(adding two positions usually has no geometric meaning)
-
-
Subtraction
-
Point − Point = Direction
(direction from the second point to the first point) -
Point − Direction = Point
(move the point backward along the direction) -
Direction − Direction = Direction
(vector difference) -
Direction − Point = Undefined / Not Allowed
(subtracting a position from a direction is not meaningful)
-
-
Scalar multiplication
-
Direction × Scalar = Direction
(scale direction magnitude) -
Point × Scalar = Typically Not Allowed
(scaling a point is not a standard affine operation unless you explicitly define an origin-based scaling rule; most pipelines treat this as undefined)
-
-
Dot product
-
Only defined for Direction · Direction → float
-
If a point is involved, you should either reject it or explicitly interpret it as a direction from the origin (but that changes meaning, so rejecting is usually cleaner for assignments).
-
-
Cross product
-
Only defined for Direction × Direction → Direction
-
Point involvement should be rejected.
-
-
Unitize (~)
-
Only defined for Direction → Direction
-
Unitizing a point should be rejected.
-
-
Angle between
-
Only defined for Direction vs Direction → float (degrees)
-
If either is zero-length, no valid solution.
没有评论:
发表评论