# Generating geometry from points and vectors

This topic is 4869 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi there. To start with I will admit that maths and physics are not my strongest point, however I do have some basic knowledge of vector maths. I'm currently writing a 3D program where I need to generate the vertices for several triangles to make a cuboid. The data I have to generate from this is a list of points and vectors. For example, I have 3 points:
position: (xyz)  |  vector: (xyz)
-----------------------------------------
0,0,0            | 1,0,0
2,0,0            | 0,1,0
2,2,0            | 0,1,0

Here is the graphical representation:
Y
^      ^
|      |
|      0
|      ^
|      |
|      |
|0---->0
+-------------------X
\Z

From these 3 points and directions, I am attempting to work out 4 vertices, to make a 3D 6 sided shape. I won't worry about the process of generating individual triangles from these 4 vertices as I can probably cope with that. In my program so far I have a special case for the first and last points, where all the vertices must be the same distance from the point (0.5f), but on the middle points (only one specified for this example for simplicity) they will always be at right angles, so the vertices need to be on a plane of 45 degree:

^
|
. 0 .
^
|
.    . |
0--->0
.        .

What I am having problems with is generating the plane mathematically and then knowing the co-ordinates in 3D of the vertices. I may be able to do it using pure program logic, but it would be inefficient if there's a mathematical route to go. Sorry if its hard to know what I want. But if you were to imagine that last diagram mirrored on the X axis, then the plane of the verticis on the right would be different:

.       .
0-->0
.   . |
|
\/
. 0 .
|
|
\/

Since the actual points I will be generating will be 3D I am only concerned about generating the 4 vertices around the current point, as I will have access to the previous point/vert data. All the vertices need to be 0.5 units away from the point. Any ideas on how to go about doing this, or just general pointing in the right direction? I've tried a few things involving the dot product and stuff, but I was just scribbling on paper and not really knowing what I am doing. Any help in this problem will be appreciated and rating++ :) If you need anything explained further please ask and i will do my best. Thanks Jason

##### Share on other sites
to be honest, I don't understand your drawings. What are the points supposed to be representing? Are they vertices of the cuboid? If yes, which ones? And the vectors? Are they edges? Diagonals of the faces? Please explain...

edit:
I drew a jpeg on the fly to paste in the reply... didn't know it had to be hosted in the net somewhere for it work...

##### Share on other sites
Ok i've drawn out the first and second ascii drawings in paint, hopefully it will be a little clearer:

Basically the Green round dots are the points in space that I have, with the dark red arrows being direction vectors from those points aiming at the next point.

The red square points are the points I wish to calculate, more specifically its the way they are angled when the shape changes direction (the 45 degree bit).

Is that clearer?

Jason

##### Share on other sites
Ok obviously that didn't help lol.

Let me try and put it another way. I want to find out a plane that the vertices should lie on, then how to calculate the vertices from the 2 positions and direction vectors that I have.

Is there anything I can do to help clear this up, or anything roughly in the sort of area of reference you guys could direct me to? I sat down for a night trying to work it out but like I said maths isn't my strongest point in this world.

Thanks to anyone who takes the time to read this anyway..

Jason

##### Share on other sites
Given two vectors:

1. take the cross product to get a vector perpendicular to the vectors
2. add them together to get a vector in the direction of the sum of the vectors
3. take the cross product of the vectors from steps 1 and 2, I believe this vector and its opposite are in the directions you wish to place the two points
4. normalize the vector from step 3, multiply it by the distance you want the derived points to be from the path, and add and subtract it from the original point to get the derived points

Note that this method may generate points that do not necessarily form simple polygons, since if these vectors leave the plane the path will be twisting.

##### Share on other sites
Oh, and also normalize them before adding them together in step two.

##### Share on other sites
After a bit of thought, here's an even simpler method: normalize the vectors, then subtract one from the other. This gives you one of the directions (unnormalized though), and negate it to get the other direction. But this method won't work for the case where both vectors are in the same direction (and the previous method won't work for the case where both vectors are in opposite directions).

##### Share on other sites
Quote:
 Original post by Anonymous PosterAfter a bit of thought, here's an even simpler method: normalize the vectors, then subtract one from the other. This gives you one of the directions (unnormalized though), and negate it to get the other direction. But this method won't work for the case where both vectors are in the same direction (and the previous method won't work for the case where both vectors are in opposite directions).

Thanks for your help there, pretty simple after all that. Your last method should be fine as the vectors should never be the same or opposite direction from one another.

Thanks again, I'd rate you, but your Anonymous :-)

Jason

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 14
• 11
• 29
• 15
• 41
• ### Forum Statistics

• Total Topics
634838
• Total Posts
3019568
×