HW2 · Vector geometry

Modern vector notation (the dot product, the cross product) was developed independently by Josiah Willard Gibbs and Oliver Heaviside in the 1880s, partly as a simpler rival to quaternions.Gibbs and Wilson, Vector Analysis, 1901; Heaviside, Electromagnetic Theory, 1893
Out Thursday October 15 · due Wednesday October 28, 11:59 PM on Canvas (extended from Wednesday October 21) · 25 points · Unity or WebGL · hub · schedule · syllabus · all homework
Read before this homework: Vectors §2 and §3, dot and cross · §5, lines · §6, planes and signed distance · Unity for This Course §7 · WebGL and three.js for This Course §7

What you build

The six exercises of the old vector labs as functions: march along a line, lay out a segment, build a plane, test which side of it a point is on, drop a shadow onto it, cut a segment with it and reflect the direction, and project a point onto a cylinder.

JavaScriptC#What it computes
marchStepMarchStepEX1: one frame of marching from p toward the line from → to at speed units per second.
lineFrameLineFrameEX1: the midpoint, unit direction and length of the segment p1 → p2.
planeFromPointPlaneFromPointEX2: the plane with normal direction m (any length) through q, as a unit normal n and D.
signedDistanceSignedDistanceEX3: n · p − D; positive on the normal's side.
shadowOnPlaneShadowOnPlaneEX4: p − (n · p − D) n.
linePlaneHitLinePlaneHitEX5: the point where the line through p1 and p2 crosses the plane; null (C#: false) when parallel.
reflectReflectEX5: d − 2 (d · n) n.
projectToCylinderProjectToCylinderEX6: the foot on the axis, pushed out to the radius; and whether the foot is within halfHeight of the center.

The numbers a correct build reproduces

Each row is one check, run on your functions with the published inputs below. The same table appears under the scene in the runner and in the Unity Console.

#CheckExpectedTolerancePoints
1EX1 marchStep: one step toward (4, 0, 3)(0.8, 0, 0.6)0.00110
2EX1 lineFrame: midpoint, direction, length((2.5, 2, 0), (0.6, 0.8, 0), 5)0.00110
3EX2 planeFromPoint: unit normal n and D((0.3333, 0.6667, 0.6667), 0.3333)0.00110
4EX3 signedDistance for P = (4, 1, 0) and P2 = (-1, 0, 0)(1.6667, -0.6667)0.00110
5EX4 shadowOnPlane of P(3.4444, -0.1111, -1.1111)0.00113
6EX5 linePlaneHit for the segment P to P2(0.4286, 0.2857, 0)0.00113
7EX5 reflect: the unit direction P to P2 reflected about n(-0.6755, 0.414, 0.6101)0.00113
8EX6 projectToCylinder: (1.2, 0.6, -0.9), point and inside((0.4, 0.6, -0.3), true)0.00111
9EX6 projectToCylinder: (0.9, 1.4, 0.4), point and inside((0.4569, 1.4, 0.2031), false)0.00110
The published inputs
{
 "march": {
  "p": [ 0, 0, 0 ],
  "from": [ 0, 0, 0 ],
  "to": [ 4, 0, 3 ],
  "speed": 2,
  "dt": 0.5
 },
 "line": {
  "p1": [ 1, 0, 0 ],
  "p2": [ 4, 4, 0 ]
 },
 "plane": {
  "m": [ 1, 2, 2 ],
  "q": [ 1, 0, 0 ]
 },
 "P": [ 4, 1, 0 ],
 "P2": [ -1, 0, 0 ],
 "cyl": {
  "c": [ 0, 0, 0 ],
  "axis": [ 0, 1, 0 ],
  "radius": 0.5,
  "halfHeight": 1,
  "inside": [ 1.2, 0.6, -0.9 ],
  "outside": [ 0.9, 1.4, 0.4 ]
 }
}

Implement and replace

Build each function from primitives (dot, cross, normalize, length, component access, + − × ÷, sqrt.) and use the engine's own helper, where one exists, only to check your result. These are off limits in your submission:

TrackOff limits
WebGL (JavaScript)Vector3.projectOnVector, projectOnPlane, reflect, angleTo; THREE.Plane and THREE.Ray.
Unity (C#)Vector3.Project, ProjectOnPlane, Reflect, Angle, MoveTowards, Lerp; the Plane struct.

Getting started

WebGL track.
  1. Get the homework starter repository (about 2 MB): git clone https://github.com/mgav-uwb/UWB-CSS-551-AU26-homework.git, or Code, then Download ZIP. It gains each homework the day it goes out; git pull fetches it.
  2. In its root folder run python3 -m http.server 8000 and open http://localhost:8000/homework/run.html?hw=hw02.
  3. Edit lib/skeletons/hw02.js, the only file you change, and reload: the Checks table under the scene compares your numbers with the ones below.

The unfilled skeleton runs on this site too, so you can see the page before you start. The setup, the blank page a file opened from disk gives, and how to read the Checks table are in WebGL and three.js for This Course.

Unity track.
  1. In Unity Hub, create a new project with the 3D (Built-In Render Pipeline) template in editor 6000.3.11f1.
  2. From the homework starter repository, copy the files in homework/hw02/unity/ into Assets/HW02/.
  3. Create an empty GameObject, add the Checks component (namespace CSS551.HW02), and press Play: the Console lists every check with your value and the expected one.
  4. Edit HW02.cs; the other files are given.

The Unity files compile against a stand-in for the UnityEngine API and pass their checks with the reference solution, but they are new this quarter and have not yet been opened in the Unity editor. If one does not compile in 6000.3.11f1, post the error on the Canvas board and use the WebGL track meanwhile.

Submitting and grading

Grading runs your functions twice: on the published inputs above and on a second set of inputs that is not published. A check earns its points only when your value is within its tolerance on both, so the numbers have to come from the math. The rubric score is the sum of the points earned, out of 100; it counts as 25 course points (the rubric score divided by 4). A submission that does not load or compile earns no check points. Name any collaborators and tools in the submission comment.

Late tokens. You have two for the quarter. Declare one in the submission comment to extend this homework by 48 hours without penalty. Without a token, late work is not accepted, and nothing is accepted after Friday, December 11.