Lecture Notes: Scalars, Vectors, Dot Product, and Space Transformation
Scalars and Number Line
- Scalars: One-dimensional vectors (numbers) on the number line (0, 1, 2, 3... -1, -2âŚ) extending to positive/negative infinity.
- Importance: Understanding the foundation for multidimensional concepts.
Two-Dimensional Vectors
- Number Line Extension: From one-dimensional number line to two dimensions with x and y axes.
- Vectors: Fundamental in space transformation, velocities, positions, orientations, etc.
Dot Product
- Definition: Operation between two vectors, resulting in a scalar.
- Projection: Dot product involves the projection of one vector onto another, which holds if at least one vector is normalized.
- Significance: Used to calculate distance, velocity, orientations; Dot(A, B) == Dot(B, A).
- Geometric Interpretation: Gives scalar length along projection axis; important for vectors to be normalized.
- Application: Useful in deriving many other mathematical formulas.
- Signed Distance: Concept where projection could be negative based on vector orientation.
Example Calculations
- Given A and B (vectors), Dot Product = Projection of B onto A axis, requiring normalization for true distance.
- Normalization Impact: Ensures the geometric meaning is accurate.
Assignments and Practical Usage
- Assignment 1: Create a radial trigger to check if a point is within a certain radius in space.
- Assignment 2: Develop a look trigger to activate when an object is within the player's field of view.
Radial Trigger Implementation
- Setup: Use Unity's editor and gizmos to visualize and debug radius.
- Visualization: Use functions like
Handles.DrawWireDisc to draw the radius in the editor.
- Checking Inside/Outside Radius: Calculate distance between object and radius to determine if it's inside or not. Visual cues (colors) indicate state.
- Efficiency Tips: Use
OnDrawGizmosSelected to limit gizmo rendering for performance.
Look Trigger Implementation
- Goal: Trigger an action when looking directly at an object within a specified threshold.
- Setup: Define look direction using playerâs transform (e.g., x-axis for 2D, z-axis for 3D).
- Calculation: Use dot product to determine if the player's view direction is within the required preciseness of the object.
- Threshold: Adjust based on desired preciseness; visualization shown using gizmo colors.
- Applications: Useful for gameplay mechanics like interactive objects, AI behavior (e.g., enemiesâ field of view).
Local and World Space
- Concept: Coordinate systems attached to objects. World space is the global reference frame; local space is relative and dependent on object transforms.
- Transformations: Always consider the space a coordinate/vectors belong to avoid errors.
- Basis Vectors: Vectors (right, up, forward) defining local space orientation.
- Assignment 3: Write functions transforming coordinates between local and world space.
Transforming Between Spaces
- Local to World: Use basis vectors, multiply by local coordinates, add world position (formula and practical coding example provided).
- World to Local: Subtract world position, project onto basis vectors using dot product.
Matrices
- Matrix Representation: 4x4 matrices encode rotation, position, and scale.
- Components: Top-left 3x3 portion represents orientation, 4th column represents position, bottom row is usually fixed (0,0,0,1).
- Transformations: Multiplying matrices with vectors transforms coordinates between spaces.
- Matrix Inverses: Used for transforming in the opposite direction.
- Practical Use: Unity functions like
transform.TransformPoint and transform.InverseTransformPoint handle these transformations.
Cross Product
- Definition: Operation returning a vector perpendicular to the input vectors.
- Usage: Calculating normals, aligning objects, determining orientation (tangents and bitangents for surfaces).
- Important Properties: Order of vectors matters, follows left-hand (Unity) or right-hand rule (general physics/math).
- Applications: Placement on surfaces (e.g., placing objects with correct orientation on uneven terrain), defining surface normals in mesh data.
Visualization Techniques
- Gizmos and Handles: Useful tools for drawing and debugging in Unity Editor.
- Adjustable Drawing: Colors, thickness, anti-aliasing options available to enhance legibility.
- Practical Tips: Use
Handles.DrawLine, Handles.DrawPolyLine, and color coding for clear visual feedback.
Note: Always verify space (local/global) for vectors when performing transformations to avoid logical errors.
Additional Concepts
- Signed Distances: Useful in scenarios where direction impacts distance interpretation.
- Handling Edge Cases: Handling parallel vectors or zero-length vectors in dot and cross products.
- Practical Coding Implications: Efficiency in using Unity built-in functions versus custom implementations.
Future Topics
- Upcoming: Trigonometry, space transformations in more detail, matrices in broader contexts.
Questions and feedback are highly encouraged to clarify concepts and address specific needs.