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

## Recommended Posts

I am creating simple road system. It should do this: 1)Do line of road(adding points) 2)Get sides of road(from road points, vector) 3)Connect road sides and make a road. So my problem is with 2 part. I calculate angle of road point side with this: k1 = atan2((- t[i].x + t[i - 1].x), (- t[i].y + t[i - 1].y)); k2 = atan2(( t[i].x - t[i + 1].x), ( t[i].y - t[i + 1].y)); k1 = k1 * 180 / 3.14; k2 = k2 * 180 / 3.14; k = (k1 + k2) / 2; It calculates angle with point of next and previous points in radian, then converts to degrees and calculates average of them. But the problem is this: <br/> The rodes collides (3, 11 and 16 points). In those points just need to reverse vectors, but I dont know how to find those points, which need this. The calculations dont have any mistakes, but i this i need something more. Do I need to check collision or there is some easier way, or miskates? Any thoughts? Sorry for English, its not easy to talk about mathematic in not my born language :) [Edited by - DonceLT on June 22, 2009 3:53:53 AM]

##### Share on other sites
I would use vector math for this instead of angles.

Consider that each segment of the road has a normal vector. If I'm thinking about this correctly, the vector that you're looking for will be the normalized average of the normals of the two segments that meet at a given intersection. (A diagram would probably help make this more clear - drawing a couple of example cases might help clarify things.)

If you want to stick with angles, it shouldn't be too hard to determine when the angle needs to be negated. From looking at the image you posted, it seems you could simply check to see if a road edge crosses the hyperplane associated with the corresponding medial segment.

I'll also mention that the method you're using to build the road mesh may not always yield the best results, in that the width of the road sections will vary depending on the angles of the turns. Another approach would be to build lines parallel to the segments and displaced along the segment normals by a specific distance (the desired 'radius' of the road), and then intersect these lines to yield the corners where the road sections meet.

##### Share on other sites
Quote:

Thanks, i think i'll continue with angles. The size of road width of the road sections varies depending on angles, but can create very detail road with low angles, so this variation would be very small, and drawing 3d (already done with angles) its faster I think :)

##### Share on other sites
I also suggest that you use vectors. Unless you're targeting the Ti-83 or commodore, I think you're going to want some smooth roads.

Consider the road a spline, a vector of piecewise polynomials. This will give you nice smooth curved segments. The spline can be sampled at any frequency, if you sampled it at one sample per segment then it would come out with straight roads like you have.

You'll need a function which is capable of generating a coordinate system at any point along the spline. This 3d coordinate system would have a basis vector pointing along the road direction, perpindicular to the road (to the side) and one in the road normal direction, which is perpindicular to the previous two.

Where t is some value from 0 to 1 along the roadway.

So you'd iterate from 0 to 1 at some interval, say 0.01 to give you 100 samples. At each sample you create a coordinate space, then you project your geometry into this space. Imagine a triangle strip road that just goes straight. Now imagine we take that triangle strip and for each row of vertices we multiply them by a coordinate space generated at some point along the road. The triangle strip would then be projected onto the road path.

If you made the triangle strip more interesting, with much more triangles, you could have complex texture coordinates to have transitions between grass, gravel, cement, and different lane markings. Then project this uber strip onto the path.

Good luck!

I'll elaborate a little on what i mean by project.

Say we have a cross section of the road, it has three vertices, one along the left side of the road, one along the center, and one along the right side of the road.

Say we called that function, for the start of the road, t = 0:

This is how you'd project it into the coordinate space, for the most part we're only interested in the side direction and position of the road. Unless you wanna get fancy.
Vector sampleRoadShape[roadShapeSize];for (int i = 0; i < roadShapeSize ; ++i)   sampleRoadShape[i] = roadPos + roadSide * roadShape[i];

sampleRoadShape now contains the vertex locations for this sample along the path. If you have 100 of these samples, you can make a triangle strip between them to make the connected roadway.

Also, if you wanted to have the roadway slope down to the sides, like a wedge, you'd need to store a height component for each vertex in the road cross section, multiply this by the roadNormal, and add it to the sampleRoadShape for that vertex. Or you can store the roadShape as a Vectors and build a matrix with the 4 vectors that the sample function retrieves and then just use matrix multiplication to do the projection "all at once"

[Edited by - bzroom on June 22, 2009 12:28:43 PM]

##### Share on other sites
Quote:
 Original post by DonceLT k1 = atan2((- t[i].x + t[i - 1].x), (- t[i].y + t[i - 1].y)); k2 = atan2(( t[i].x - t[i + 1].x), ( t[i].y - t[i + 1].y)); k1 = k1 * 180 / 3.14; k2 = k2 * 180 / 3.14; k = (k1 + k2) / 2;It calculates angle with point of next and previous points in radian, then converts to degrees and calculates average of them.

Disregarding more advanced methods for a minute, why not just do this if you want to use angles?

k = atan2(( t[i - 1].x - t[i + 1].x), ( t[i - 1].y - t[i + 1].y));
k = k * 180 / 3.14;

The direction of the road at each point should be the direction from the previous point to the next point, which you can calculate directly rather than taking an average that'll get confused by the transition from 360 degrees to 0.

##### Share on other sites
Quote:
Original post by Fingers_
Quote:
 Original post by DonceLT k1 = atan2((- t[i].x + t[i - 1].x), (- t[i].y + t[i - 1].y)); k2 = atan2(( t[i].x - t[i + 1].x), ( t[i].y - t[i + 1].y)); k1 = k1 * 180 / 3.14; k2 = k2 * 180 / 3.14; k = (k1 + k2) / 2;It calculates angle with point of next and previous points in radian, then converts to degrees and calculates average of them.

Disregarding more advanced methods for a minute, why not just do this if you want to use angles?

k = atan2(( t[i - 1].x - t[i + 1].x), ( t[i - 1].y - t[i + 1].y));
k = k * 180 / 3.14;

The direction of the road at each point should be the direction from the previous point to the next point, which you can calculate directly rather than taking an average that'll get confused by the transition from 360 degrees to 0.

This helps with angles. And now then I had done with angles, i can begin with vectors, thanks guys !! :)

##### Share on other sites

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

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628736
• Total Posts
2984450

• 25
• 11
• 10
• 16
• 14