View Full Version : Normal and Vector of a line

Andrew Davey

04-23-2004, 07:22 AM

Hi,

Am quite new to openGL and have tried my best to steer clear of any "complicated" maths. But i think i am going to have to dive in, so to speak.

My first question is basically what is a vector and a normal??

My program generates a tree and uses 3d lines. I would like to do some collision detection between the branches. But cant work out how to do it. I think i should do some vector maths but unsure.

Can some one please shed some light on this.

So just to round up my questions are:

Whats a vector and normal

How do i work out vector of a 3d line

What can i do with this (in ref collision)

Cheers, very much appreciated if someone could help

brcain

04-23-2004, 08:30 AM

Originally posted by Andrew Davey:

Whats a vector and normal

How do i work out vector of a 3d line

You can find definitions for stuff like this easily by doing Google search (e.g. normal vector).

An n-dimensional vector (non-mathematical) is an ordered list of n real numbers that map to some n-dimensional space.

A normal vector is a vector that is perpendicular to a plane ... computed by taking the cross product of two non-coincident vectors in the plane.

Not sure what you meant by last question.

Andrew Davey

04-23-2004, 09:17 AM

basically iu have a line, just straight forward 3d line from a to b. Was wondering how to create a vector of that line and then a normal.

And what i can do with them.

Ideally aimed towards collision detectioon between two of the lines.

Better explanation?

brcain

04-23-2004, 09:48 AM

// 3D vector from a to b

vectorAB.x = b.x - a.x;

vectorAB.y = b.y - a.y;

vectorAB.z = b.z - a.z;

A normal vector is a perpendicular vector to a plane. It requires at least 3 points to determine a plane. Assuming you had a third point, c.

// 3D vector from a to c

vectorAC.x = c.x - a.x;

vectorAC.y = c.y - a.y;

vectorAC.z = c.z - a.z;

// Normal vector for plane containing points a, b, and c. Remember to normalize to magnitude of 1.

normalPlaneABC = crossProduct(vectorAB, vectorAC);

mag = magnitude(normalPlaneABC);

normalPlaneABC.x /= mag;

normalPlaneABC.y /= mag;

normalPlaneABC.z /= mag;

One normally doesn't think of two lines as intersecting in 3D (okay for 2D though).

If you mean collision ... that usually implies some sort of interaction between two planes or surfaces.

"My first question is basically what is a vector and a normal?"

One of the best sources for these kind of questions is the flipcode's geometry primer. First part talks about vectors, second one is about lines ( and a lot of other things ):

http://www.flipcode.com/geometry/

Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.