HomeWildfire Games

Add Vector3D crossproduct and Vector2D perpendicular function.

Description

Add Vector3D crossproduct and Vector2D perpendicular function.
Describe geometric features of the two cross- and dot-product functions.

Event Timeline

Some comments to a 2 years old friend as I was cleaning my stuffs ;-)
I don't understand the purpose of the comments.
We can just say that it returns the dot or the cross product, it's simpler ;-)

/ps/trunk/binaries/data/mods/public/globalscripts/vector.js
95

I didn't, don't and won't care about that, but Returns for consistency. (I know you like those things :p)
'the' is false.
And as the code do more, speaking of rotation (and orientation) could be +++.

106

Among many other things

114

The second "the" is false.
For consistency with the previous one, ...

115

I don't understand the comment

Some comments to a 2 years old friend as I was cleaning my stuffs ;-)

I'm getting(got) old. :S

Thanks for your feedback.

We can just say that it returns the dot or the cross product, it's simpler ;-)

Without the geometric interpretation, I wasn't able to understand some operations, for example this one (which is a yet to be committed follow up of the commit of this commit, i.e. rP20429).
While I had lots of linear algebra at school and university, I never saw a one-line computation of the distance of a point from a line in 2D space (used by the rivers map):

/**
 * Returns the distance of a point from a line.
 * @param {Vector2D} - lineStart, lineEnd, point
 * @param {boolean} absolute - If true, the function returns a non-negative number of the magnitude.
 *   Otherwise the sign denotes the direction.
 */
function distanceOfPointFromLine(lineStart, lineEnd, point, absolute = true)
{
	// Since the cross product is the area of the parallelogram with the vectors for sides and
	// one of the two vectors having length one, that area equals the distance between the points.
	let distance = Vector2D.sub(lineStart, lineEnd).normalize().cross(Vector2D.sub(point, lineEnd));
	return absolute ? Math.abs(distance) : distance;
}

(So I intended to retain these findings, including the intermediate ones.)

I'll look into clarifying the comments further on next occasion.

/ps/trunk/binaries/data/mods/public/globalscripts/vector.js
95

Yeah well. (Speaking of consistency, also the two cross product parallelogram comments differ in phrasing).
Sure, there are two and I didn't describe the orientation.
The idea was to use the geometric definition of perpendicular, https://en.wikipedia.org/wiki/Perpendicular.
In particular I wanted to use the special word we have for the 90° angle while we don't have special words for the other angles.
I guess mostly a clarification could be added stating which of the two orthogonal vectors is returned.

115

I squashed two sentences into one possibly awkward one:

  1. The returned number is the length of said 3D vector.
  2. The returned number is the area of a parallelogram where each side of the parallelogram is described by one of the two vectors.
280

(I did notice the article here but not above)