## Vector Math - :)

The Partridge Family were neither partridges nor a family. Discuss.
krautersuppe
Posts: 80
Joined: September 14th, 2015, 10:58 pm
Location: Istanbul

### Re: Advance HW 3 question

albinopapa wrote: In number 5) (P1 - A0) = ||B||cos( theta ), in this case is theta the angle of vector B? I thought dot product is: ||A|| * ||B|| * cos( theta )?
Ok, so number 5) you say P1 - A0 ( which will result in a vector, = ||B||cos( theta ) which will result in a scalar?
There I use trigonometry of right triangle. Length of b is hypothenuse and length of P1-A0 is adjacent side of theta.
albinopapa wrote: In number 7) ||B||cos( theta ) = A dot B / ||A||, what is this voodoo?
Yes, it is definition of dot product, equation is the same if you take factor from one side and divide other side by that same factor. If 105 = 5 x 21 you can also write it as 105/21 = 5
When doing formula manipulations it is sometimes useful to read equations from both sides (a = b means also that b = a) and look for stuff than one can substitute from other equations.
Kraut

krautersuppe
Posts: 80
Joined: September 14th, 2015, 10:58 pm
Location: Istanbul

### Re: Advance HW 3 question

Can you rename this thread to vector math?

I will post some problems and solutions at my convieniece on this thread in future.

Maaan, i hope the previous sentence is not too farfetched and it turns out i have enough willpower to follow through on this :p
Kraut

krautersuppe
Posts: 80
Joined: September 14th, 2015, 10:58 pm
Location: Istanbul

### Re: Vector Math - :)

So, I started to follow through on this. I hope this will turn out useful.
vector_math.pdf
Special thanks to:
W.Rosenheinrich - the original author of the text.
Logos by Nick for his Inkscape tutorials.

Reports on any inaccuracies-be it language or mathematical-are gladly accepted.

More material coming soon.
Last edited by krautersuppe on December 29th, 2019, 1:53 am, edited 2 times in total.
Kraut

chili
Posts: 3894
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

### Re: Vector Math - :)

Hmm, looks good.

I'll put a link from the wiki pages of relevant tutorials to this so ppl can get some extra practice.
Chili

krautersuppe
Posts: 80
Joined: September 14th, 2015, 10:58 pm
Location: Istanbul

### Re: Vector Math - :)

More practice material:
Edit:all in one file now

Special thanks to:
W.Rosenheinrich - the original author of the text.

Reports on any inaccuracies will be gladly accepted.
P.S.
There are plenty more problems and solutions however I do not think that I am going to translate all of them. There are some containing calculation of angles and intersection points(between planes and lines), some concerning use of force components(statics) and some more complex problems about description of areas, surfaces and physics.
Edit: Never mind. That was just lazy me talking.
More material coming soon.
Kraut

krautersuppe
Posts: 80
Joined: September 14th, 2015, 10:58 pm
Location: Istanbul

### Re: Vector Math - :)

1 year and 2 months counts as soon I hope . Intermediate questions are out - everything in one file now . Theory is still missing, I will upload it after I am finished with advanced and super advanced questions.
Kraut

albinopapa
Posts: 3982
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

### Re: Vector Math - :)

I looked back through this thread and back through the stuff you have uploaded and I'm going to say it again.

While I'm sure your formulas are correct and it makes sense to you, I don't know if it is comprehensible to people like me ( in fact it is not comprehensible to me ).

One thing I have found interesting about those whom understand higher mathematics very well is the inability to explain it to those with less knowledge or understanding. What I mean by this is sometimes offering up way more knowledge in one go without understanding the previous material is overwhelming and is probably why people feel like idiots, at least that's how I feel right now.

Please, finish your material and upload as you planned, I'm sure others won't have such a difficult time with it as I have.

My original point on this thread was, I wasn't and still unable to visualize in my head or on paper the point/line intersection formulas chili used. For instance, if I draw a line and a ball separated from the line on a piece of paper, I can see visually that the closest point is going to be a straight line from the ball perpendicular to the line.

Now, how do I find this vector that goes from the ball to the line? I know that the dot product is used to cast a shadow ( project ) onto another line so the dot product is what I would use. Using the vector from p0 to ball center I can project that vector onto the line segment which gives me the closest point on the line the segment is on. If the distance of that point to p0 is less than the distance to p1, then the point is on the segment. Then I can check if the distance from the closest point that we just calculated to the center of the ball is less than the radius of the ball, then we have a collision otherwise we do not.

I am unsure if that makes things any clearer as to what I meant by being able to visualize or reason about the steps needed to find closest point and determining if there is a collision. The formula chili uses:

Code: Select all

``````const auto a = p0.y - p1.y;
const auto b = p1.x - p0.x;
const auto c = ( p0.x * p1.y ) - ( p0.y * p1.x );

return std::abs( a * r.x + b * r.y + c ) / std::sqrt( sq( a ) + sq( b ) );
``````
First off, I am not sure if 'a' = p0.y - p1.y is like that because the screen coordinates in the Y is flipped compared to the Cartesian Y coordinate or if it even matters.
Second, from what I can tell, 'a' is the height ( negated? ) and 'b' is the width if an imaginary triangle where p1-p0 is the hypotenuse.
Third, 'c' is the area of a quadrangle with p0 and p1 being opposite corners.
Fourth, std::sqrt( sq( a ) + sq( b ) ) gives the length of the hypotenuse ( ||p1-p0|| ).

So the only part I don't understand is the ( a * r.x + b * r.y + c ) or as I described:
( length of side A * r.x + length of side B * r.y + area of quadrangle )

This is the only part of the distance from point to line I can't visualize I suppose. It's apparently some factor of the length of the hypotenuse or ||p1-p0||, but how?

Let's see if giving concrete numbers to abstract variables helps:
p0 = ( 10, 100 )
p1 = ( 200, 10 )
r = ( 400, 400 )

First, side A
a = p1.y - p0.y = 10 - 100 = -90
b = p0.x - p1.x = 10 - 200 = -190
c = ( p0.x * p1.y ) - ( p0.y * p1.x ) = ( 10 * 10 ) - ( 100 * 200 ) = 100 - 20000 = -19900

X = ( a * r.x + b * r.y + c ) = ( -90 * 400 ) + ( -190 * 400 ) + 19900 = ( -36000 ) + ( -76000 ) + ( -19900 ) = -131900
L = sqrt( ( a * a ) + ( b * b ) ) = 210.238

d = |X| / L = 131900 / 210.238... = 627.384...

Am I right in assuming that the portion I'm not understanding is a simplification of a larger formula just like ( ax * by ) - ( ay * bx ) is a simplified version of the 3D cross product

cx = ( ay * bz ) - ( az * by ),
cy = ( az * bx ) - ( ax * bz ),
cz = ( ax * by ) - ( ay * bx )

Since a 2D vector would be extended to ( x, y, 0 ), the first two equations are always going to be 0 and not needed in 2D and the Z would just be the area of a parallelogram with A and B as opposite points, or if divided by 2 would be the area of a triangle where AB would be the hypotenuse.

I must have something wrong here, because if I use the ( ax + by + c ) = 0 formula and plug in p0.x and p0.y as the x and y, I get:
ax = -90 * 10 = -900
by = -190 * 100 = -19000
c = -19900
(-900 + ( -19000 ) + ( -19900 ) = -39800
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

krautersuppe
Posts: 80
Joined: September 14th, 2015, 10:58 pm
Location: Istanbul

### Re: Vector Math - :)

Answer to your question should be in material according to footnote nr. 29 on page 18. Problem is it was still to be written Anyhow here is the draft
distance_point_line.pdf