Question

Lofted polygon radius causing overlap in parallel transport.

Asked by: Dr_Spankenstein

I am generating the main points on which my CatmullRom spline is based as follows:

            waypoint_Current += new Vector3(Game1.Random.Next(-8, 8), Game1.Random.Next(-5, 25), -Game1.Random.Next(5, 15));

If I have a lofted polygon created from a parallel transport frame that follows the spline then the tube created overlaps itself as shown on the picture attached.  This gets worse as I increase the radius of the tube/lofted polygon.

How do I combat this?

I had a thought that it might be necessary to generate random points that have a distance between them that is longer than the radius of the tube but then I wasn't sure how to ensure that the interpolated spline points would be far enough apart to prevent the overlap from happening.

Can anyone help?

Thank you.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-11-06 at 14:04:50ID24879459
Tags

Radius 3D Lofted Parallel Transport Frame Rendering Programming Maths

Topics

3D Game Programming

,

Graphics & Game Programming

,

Math & Science

Participating Experts
2
Points
500
Comments
49

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Zipcode Distance, and Radius formulas
    I have a database of zipcodes with lat and lon and store db with zipcodes and want to write CF code to do the following. 1) calculate distance between 2 zip codes in miles. 2) given a zipcode, find all the other zips within a radius of x miles. The user will provide their...
  2. radius
    What is the radius Is it use to check the to control data transfer
  3. Radius Search
    I need assistance with implementing a radius search on a website. I have a sql database containging stores and their addresses what I am trying to do is when a user goes to our site all i want them to have to imput is their zip code and the distance they want to search by wh...
  4. search radius with MYSQL
    Hello everyone, I have a list of properties in a MYSQL table. My website users will be searching this properties table a number of ways(address, city, state, zip, etc.....). I want them to be able to also select a SEARCH RADIUS for example: within 10 miles, 25 miles, 50 m...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: ikeworkPosted on 2009-11-07 at 01:40:34ID: 25765604

Hi Dr_Spankenstein,

Can you render the important part in wireframe, its easier to see then.

ike

 

by: programmer78Posted on 2009-11-07 at 01:46:24ID: 25765619

As far as I understand, you use spline for generating the axis of the body. I would advise you to restrict the curvature of the spline. So in this case you will face overlapping but it will not be so dramatic. (In other words, imagine, that your spline was not a spline but a corner - infinite curvature in the vertex and zero curvature in other points, in this case other points generate cylinder, whereas vertex generates fracture, where overlapping occurres. So the less curvature - the less overlapping. The less diameter of the pipe - the less overlapping.
I think the curvature of the spline is connected to diameter of pipe with the following equation:
1/C >= R; C - curvature of the spline, R - radius of the pipe.

to calculate C you have to take the second derivative of the spline parametrized by length. (See also http://en.wikipedia.org/wiki/Curvature ).

 

by: ikeworkPosted on 2009-11-07 at 04:05:07ID: 25765945

Another problem might be, that the quaternion you get from the spline, is not on the same hemisphere of the hyper-sphere as the quaternion of the previous frame.
You can easily check that, by taking the 4d-dot-product of the quaternion, it must be >= 0, if it is not, they dont lie in the same hemisphere.

How do you specify the spline control points? Do you use quaternions to define the spline-control-points-orientation? Make sure that following quats lie in the same hemisphere then, be checking their dot-product.

 

by: Dr_SpankensteinPosted on 2009-11-07 at 04:14:17ID: 25765971

I've attached is a wireframe version of what is going on.

The spline points are generated from the random waypoints using the code attached.

Waypoints are generated very simply as follows:

        private void GenerateWaypoint(ref Vector3 waypoint_Current)
        {          
            waypoint_Current += new Vector3(Game1.Random.Next(-8, 8), Game1.Random.Next(-5, 25), -Game1.Random.Next(5, 15));
        }

I guess that in this case the waypoints are not acceptable for the spline control points.  They have no orientation assigned to them but I am not sure how I would do that if that is how I should proceed?

        private void GenerateSplinePoints(List<Vector3> waypoints, int index_Start, int index_End)
        {
            // Camera will always start at first point on interpolated path (points_Interpolated)
            // Camera forward = (next interpolated path point - current interpolated path point)
 
            // Interpolated path (along spline)
            for (int i = index_Start; i < index_End - 2; i++)
            {
                // NB index starts from 0            
                spline_Point_List.AddRange(Interpolate(waypoints[i - 1], waypoints[i], waypoints[i + 1], waypoints[i + 2]));
            }
        }
 
        /// <summary>
        /// Returns a list of points on a spline between v2 and v3 (the first point being v2)
        /// </summary>
        /// <param name="v1">Previous point</param>
        /// <param name="v2">First point on spline</param>
        /// <param name="v3"></param>
        /// <param name="v4"></param>
        /// <param name="detail">Number of points on the spline</param>
        /// <returns></returns>
        private Vector3[] Interpolate(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4)
        {
            // List size will equal number of points on spline
            Vector3[] list = new Vector3[spline_Point_Detail];
       
            for (int i = 0; i < spline_Point_Detail; i++)
            {
                Vector3 point_New = Vector3.CatmullRom(v1, v2, v3, v4, i / (float)spline_Point_Detail);
                list[i] = point_New;
 
                if (i > 0)
                {
                    // Create a segment for collision detection from this point and the previous point
                    segment_List.Add(new CD_Segment(list[i - 1], list[i]));
                }
            }
 
            // Add the final segment from v3 as it is not inclusive
            segment_List.Add(new CD_Segment(list[spline_Point_Detail - 1], v3));
 
            return list;
        }

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:

Select allOpen in new window

 

by: ikeworkPosted on 2009-11-07 at 04:18:46ID: 25765988

Can you show the code in CD_Segment

 

by: Dr_SpankensteinPosted on 2009-11-07 at 04:37:42ID: 25766053

Sure.  The segment is just there to define the center of the lofted polygon.  It can be used for collision detection against the the radius of the tube.

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
 
namespace Cthonian
{
    public class CD_Segment
    {
        public Vector3 A;
        public Vector3 B;
 
        public CD_Segment(Vector3 a, Vector3 b)
        {
            A = a;
            B = b;
        }
 
        /// <summary>
        /// Given segment ab and a point, compute closest point on ab (Page 128)
        /// </summary>
        /// <param name="point">Point to find closest point on segment to</param>
        /// <returns></returns>
        public Vector3 ClosestPtPointSegment(Vector3 point)
        {
            Vector3 ab = B - A;
 
            // Project c onto ab, computing parameterised position d(t) = a + t * (b - a)
            float t = Vector3.Dot(point - A, ab) / Vector3.Dot(ab, ab);
 
            // If outside segment, clamp t (and therefore d) to the closest endpoint
            // - If used with a ray t only needs to be clamped when it is negative
            // - If used with a line t never needs to be clamped
            MathHelper.Clamp(t, 0.0f, 1.0f);
 
            // Compute projected position from the clamped t (closest point on ab)
            return A + t * ab;
        }
 
        /// <summary>
        /// Returns the squared distance between a point and the segment
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        public float SquareDistanceToPoint(Vector3 point)
        {
            Vector3 ab = B - A;
            Vector3 ac = point - A;
            Vector3 bc = point - B;
            
            float e = Vector3.Dot(ac, ab);
 
            // Handle cases where c projects outside ab 
            if (e <= 0.0f)
            {
                // A is closest to point
                return Vector3.Dot(ac, ac);
            }
 
            float f = Vector3.Dot(ab, ab);
 
            if (e >= f)
            {
                // B is closest to point
                return Vector3.Dot(bc, bc);
            }
 
            // Handle cases where c projects onto ab
            return Vector3.Dot(ac, ac) - e * e / f;
        }
    }
}

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:

Select allOpen in new window

 

by: ikeworkPosted on 2009-11-07 at 04:48:25ID: 25766088

I dont quite understand where in the code you calulate the orientation at a waypoint. Can you explain that please?

 

by: ikeworkPosted on 2009-11-07 at 04:51:57ID: 25766109

Anyway, if you look at the wireframe-rendering, you can see quite good what happens, You see 3 sements. The end of the 1st segment and the beginning of the 3rd segment are not easy to connect. The 2nd segment must make a big turn to connect them. That probably explains it. You need to choose waypoints, that are easier to connect.

 

by: Dr_SpankensteinPosted on 2009-11-07 at 05:14:37ID: 25766195

Thanks ike.

Right now I am not calculating the orientation at the waypoint, just its position.   I've got no hope of getting a decent waypoint for the spline using my naff method where the position is just picked at random.

Could you please recommend a method that would pick better waypoints that are easier to connect?

 

by: ikeworkPosted on 2009-11-07 at 05:42:35ID: 25766287

Can you explain a bit, what the spline is used for?
Do the points have to be distributed randomly, or should there be any sort of order?
Why do they have to be random, cant you defined sone points hardcoded?

 

by: Dr_SpankensteinPosted on 2009-11-07 at 06:31:48ID: 25766435

The waypoints start from (0,0,0) and then move in the +ve Z direction but with random x and y values.

The waypoints are used to generate the spline

The spline is used to create a tube from frames on each interpolated spline point.  It defines the center of the tube at all times no matter what the orientation.

I would need to create waypoints at different random locations that would not allow the tube to overlap as shown in the wireframe picture.
 
The random waypoints could follow a rule of being a certain length apart but I would need a way of making sure that the next waypoint generated would not allow the tube to overlap itself.

 

by: programmer78Posted on 2009-11-07 at 07:13:55ID: 25766548

So your problem is to interpolte some waypoints with a spline. This spline should be "enough good" for rendering the tube without overlappings, right?

This task in some cases may not to have a solution. If your waypoints trajectory curved enough, it is possible, that there is no spline which satisfy both waypoints and curvature conditions simultaneously. In this case may be useful to build pipe as you build, but then remove overlapped fragments. The pipe will be not smooth in this case, but geometrically it will be as possible close to the initial trajectory.

By the way, using some kinds of splines, you can achieve maximum smoothness of the curve. I don't remember exactly what kind, but you can find it easily. Nevertheless, the main restriction concerns the pipe radius and spline curvature.

  • figure1.JPG
    • 35 KB

    2d projection of this problem. It should became clear :)

    2d projection of this problem. It should became clear :)
 

by: programmer78Posted on 2009-11-07 at 07:23:43ID: 25766571

This problem is similar to the problem of curving wire. If wire is thin enough - you can reel it as you want easily, but imagine thick coaxial 75 Ohm TV-antenna cable: you cannot reel it to your palm without tearing. Tearing - is equivalent of overlapping.

 

by: ikeworkPosted on 2009-11-07 at 07:44:17ID: 25766642

>> The waypoints start from (0,0,0) and then move in the +ve Z direction but with random x and y values.
>> need a way of making sure that the next waypoint generated would not allow the tube to overlap itself.

So you increase Z by a given value for each point? Or is that random too?

 

by: ikeworkPosted on 2009-11-07 at 07:45:07ID: 25766648

Can you post the original assignment text? Thats gonna be easier.

 

by: Dr_SpankensteinPosted on 2009-11-07 at 07:57:15ID: 25766728

Thank you for the pictures that helped me understand :)

I've attached my code for getting the curvature of the CatmullRom spline.  Can you tell me if you see any errors in there?

Assuming it is correct:

If the constant uniform radius of the tube is less than the reciprocal of the number returned by the method then the waypoints are acceptable.

The problem is that I could be regenerating waypoints indefinitely until the equation (R < 1/C) is satisfied.

Can anyone suggest a sensible way of random waypoint generation to minimize the (R > 1/C) problem?

Thank you.

 

by: Dr_SpankensteinPosted on 2009-11-07 at 08:02:12ID: 25766753

ike, this is not an assignment, it is something I am tackling in my spare time so there is no original text, sorry.

However to make things easier we could assume the following:

1) z is always going to increase from one waypoint to the next; the tube will never go back on itself
2) The length from one waypoint to another would remain constant

 

by: ikeworkPosted on 2009-11-07 at 08:10:16ID: 25766782

Ok, then just take hardcoded points, no need to generate them randomly. This way you can much easier make sure, that they dont overlap.

 

by: ikeworkPosted on 2009-11-07 at 08:15:19ID: 25766802

Anyway, if you want to make it random and 1) and 2) is assumed, just generate 2 random angles, around y-axis and z-axis. where {0 degrees, 0 degrees} points towards the z-axis. Make sure the angles are not bigger than +/- 45 degrees. add a vector with the length of assumption (2) and the random angles to the last position, there you go.

 

by: programmer78Posted on 2009-11-07 at 09:18:20ID: 25767125

> Can anyone suggest a sensible way of random waypoint generation to minimize the (R > 1/C) problem?

When the splines were invented, they represented the wooden ruler which was binded to waypoints. I.e. normally splines gives you almost minimal curvature. You can use square polinomial splines for example. Even in case of you get not minimal curvature, it will be almost minimal (accurate to members, which --> 0).

Concerning your calculations: I cannot verify them since I don't work with 3d gfx (and don't work with graphix at all, I am Linux programmer), but I see that it seems, your spline-approximation takes 4 vectors, so this means it doesn't use square polinomial splines, probably it uses cubic polinomial splines or something other... I would advise you to debug spline-approximation algo in 2d space (it is easier to plot results), you may just put zero instead of one of co-ordinates and use your 3d-classes for 2d-calculations. Then plot curves in the 2d screen.

 

by: ikeworkPosted on 2009-11-07 at 09:22:36ID: 25767144

>> not bigger than +/- 45 degrees

read: not bigger than +/- 90 degrees

 

by: Dr_SpankensteinPosted on 2009-11-07 at 10:13:15ID: 25767332

>>Anyway, if you want to make it random and 1) and 2) is assumed, just generate 2 random angles, >>around y-axis and z-axis. where {0 degrees, 0 degrees} points towards the z-axis. Make sure the >>angles are not bigger than +/- 45 degrees. add a vector with the length of assumption (2) and the >>random angles to the last position, there you go.

Sorry to be a pain but can you give me a short coded example?

I can understand that I can use a number between -45/+45 to generate the angle in degrees.  Would the z-axis remain constant each time (0,1,0) and how would I rotate around it?

I'm not sure how I can create a Vector3 from knowing its length

I can work it out the other way around using:
distance_Squared = (Vector3.x * Vector3.x) + (Vector3.x * Vector3.x) + (Vector3.x * Vector3.x)

or does this work if I work out the vector between the next waypoint - the current waypoint (v):
distance_Squared = Vector3.Dot(v, v);

Or do I just use the a set length (scalar) and multiply that by the direction I want to travel in the create the position of the next waypoint?

Thank you for your patience.

 

by: ikeworkPosted on 2009-11-07 at 10:29:17ID: 25767420

>> Thank you for your patience.

you're very welcome :)

>> Would the z-axis remain constant each time (0,1,0)

It remains constant, its the world-z-axis, but its {0,0,1}

Take the z-axis and scale it with the constant from your assumption (2).
That means you multiply each component of the vector by this constant.
If you want the distance between each waypoint being 10.0, then multiply the z-axis by 10

{0, 0, 10} = {0*10, 0*10, 1*10}

then rotate that vector by the random angles. Add the result to your previous waypoint, then you have the new waypoint.

 

by: Dr_SpankensteinPosted on 2009-11-07 at 12:13:27ID: 25767829

I'm with you now for the distance part, I was thinking of finding the rotation first before moving!  

>> Would the z-axis remain constant each time (0,1,0)
Sorry I did mean 0,0,1 (world z) not 0,1,0, (world y) was a typo.

By rotating the vector, do you mean the same as transforming it, in which case can you tell me if the code I've attached below is what you had in mind?

Thanks ike.

            // Add minimum distance based on radius
            Vector3 v = waypoint_Current + new Vector3(0, 0, 10);
 
            // Choose a random x and y angle between -45 degrees and +45 degrees
            float random_Angle_X = Game1.Random.NextFloat(-0.7853982f, 0.7853982f); // ±45 degrees in radians
            float random_Angle_Y = Game1.Random.NextFloat(-0.7853982f, 0.7853982f); // ±45 degrees in radians
 
            // Rotate v around x and y axes by random amount
            v = Vector3.Transform(v, Matrix.CreateFromYawPitchRoll(random_Angle_Y, random_Angle_X, 0));
 
            waypoint_Current = v;

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:

Select allOpen in new window

 

by: Dr_SpankensteinPosted on 2009-11-07 at 16:22:26ID: 25768782

Ok my code doesn't work correctly as the tube can bend back on itself and reverse direction from -ve to +ve z axis.

The code contains an error, it should be: Vector3 v = waypoint_Current + new Vector3(0,0,-10).  

Also, the tube still overlaps slightly in some areas so I have definitely done something incorrect!

Any ideas on where I might have gone wrong ike?

Thanks

 

by: Dr_SpankensteinPosted on 2009-11-07 at 16:28:19ID: 25768803

I've attached a picture of what I was trying to describe.

 

by: programmer78Posted on 2009-11-07 at 16:48:03ID: 25768857

Could you please draw, what you want to get (just scratch, without 3d) 'cause I cannot understand...
It seems it's not difficult to think out en equation for necessary curve, but it is necessary to understand what you want (just  a few examples - if possible)

 

by: Dr_SpankensteinPosted on 2009-11-07 at 17:43:32ID: 25769007

The picture attached in 2D is facing (heading) towards X axis.

The waypoints would be random so any spline could be created and the location of each waypoint could change.

When generating each random waypoint, I would like to put in place a set of rules that prevents the tube from overlapping (R > 1/C) but without the need for generating the interpolated points and checking the curvature each time (as it would be too expensive).

I thought what ike had posted would do such a thing, but I think I may have misinterpreted what he suggested?

 

by: programmer78Posted on 2009-11-07 at 17:51:36ID: 25769025

Am I right? You want to build any random waypoints having some other random waypoints and you know, that you use splines for interpolation?

 

by: ikeworkPosted on 2009-11-08 at 01:33:40ID: 25769934

Rotate around x & z axes, not x and y.
Add waypoint_Current after you made the transformations with {0, 0, 10}

            // Add minimum distance based on radius
            Vector3 v = new Vector3(0, 0, 10);
 
            // Choose a random x and z angle
            float random_Angle_X = Game1.Random.NextFloat(+PI/2, -PI/2); // ±90 degrees in radians
            float random_Angle_Z = Game1.Random.NextFloat(-PI, PI); // 0..360 degrees in radians
 
            // Rotate v around x and z axes by random amount
            v = Vector3.Transform(v, Matrix.CreateFromYawPitchRoll(0, random_Angle_X, random_Angle_Z));
 
            waypoint_Current = waypoint_Current + v;
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:

Select allOpen in new window

 

by: Dr_SpankensteinPosted on 2009-11-08 at 03:27:16ID: 25770151

>>Am I right? You want to build any random waypoints having some other random waypoints and you >>know, that you use splines for interpolation?

Yes.

I want to build random waypoints starting from (0,0,0).
I'm using splines for interpolation and I'm creating frames at the interpolated points,

>>Rotate around x & z axes, not x and y.
>>Add waypoint_Current after you made the transformations with {0, 0, 10}

Ike, the code attached still causes problems :(

            // Add minimum distance based on radius [Negative as -ve z goes into screen in XNA]
            Vector3 v = new Vector3(0, 0, -10);
 
            float PI = MathHelper.Pi;
 
            // Choose a random x and y angle between -45 degrees and +45 degrees
            float random_Angle_X = Game1.Random.NextFloat(-PI * 0.5f, PI * 0.5f);   // ±90 degrees in radians
            float random_Angle_Z = Game1.Random.NextFloat(-PI, PI);                 // ±360 degrees in radians
 
            // Rotate v around x and y axes by random amount
            v = Vector3.Transform(v, Matrix.CreateFromYawPitchRoll(0, random_Angle_X, random_Angle_Z));
           
            waypoint_Current += v;

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:

Select allOpen in new window

 

by: ikeworkPosted on 2009-11-08 at 03:57:05ID: 25770199

Can you print out your waypoints?
Make the angle around x smaller, take 45 degrees (PI/4)

 

by: Dr_SpankensteinPosted on 2009-11-08 at 04:31:33ID: 25770275

These are the waypoints using the larger x and causing overlap:

{X:0 Y:0 Z:0}
{X:0 Y:2.591181 Z:-9.658457}
{X:0 Y:-3.496181 Z:-17.59218}
{X:0 Y:4.802968 Z:-23.17109}
{X:1.490116E-07 Y:0.4844179 Z:-32.19051}
{X:1.490116E-07 Y:10.40155 Z:-33.47525}
{X:1.490116E-07 Y:0.4462681 Z:-34.41994}
{X:1.490116E-07 Y:6.951897 Z:-42.01446}
{X:4.470348E-07 Y:16.56192 Z:-44.77986}

±45 degrees doesn't share the same issues.  However, the spline now only goes in the -ve z and ±y directions.  

If I wanted it to weave from "left" to "right" can I create a random angle for y alongside random_Angle_X or does one axis angle have to remain at 0 using this method?

 

 

by: ikeworkPosted on 2009-11-08 at 04:54:01ID: 25770318

can you print the angles too?

 

by: ikeworkPosted on 2009-11-08 at 05:00:08ID: 25770333

Ah sure:

 Matrix.CreateFromYawPitchRoll

it must be first rotated around z first, then around x.
Check your library if there is one with _RollPitch_
If not, create 2 matrices, and rotate each of them seperated and them multiply them

 

by: ikeworkPosted on 2009-11-08 at 05:01:32ID: 25770336

Oops, no, forget the last comment, can you print the angles and the points together?

 

by: Dr_SpankensteinPosted on 2009-11-08 at 05:15:52ID: 25770365

Sure can,

Waypoint {X:-2.221869 Y:-1.638707 Z:-9.611344}
Angle X -0.1646131
Angle Y 0.2271807
Angle Z -1.053417

Waypoint {X:-2.981895 Y:-6.008025 Z:-18.57412}
Angle X -0.4521849
Angle Y 0.08459571
Angle Z -2.651513

Waypoint {X:2.333317 Y:-10.11693 Z:-25.98124}
Angle X -0.4234304
Angle Y -0.6224284
Angle Z -0.8233327

Waypoint {X:6.512625 Y:-13.93718 Z:-34.22376}
Angle X -0.3919869
Angle Y -0.469266
Angle Z -1.032223

Waypoint {X:9.623404 Y:-19.37234 Z:-42.02005}
Angle X -0.5746194
Angle Y -0.3796503
Angle Z -2.682592

Waypoint {X:10.86316 Y:-16.1304 Z:-51.39837}
Angle X 0.3301592
Angle Y -0.1314324
Angle Z 2.762748

Waypoint {X:5.066039 Y:-14.49616 Z:-59.38101}
Angle X 0.1641596
Angle Y 0.6281049
Angle Z -0.05984791

Waypoint {X:-1.113023 Y:-15.06612 Z:-67.22285}
Angle X -0.05702665
Angle Y 0.6673572
Angle Z -0.2779838

Waypoint {X:-4.168939 Y:-14.51966 Z:-76.72878}
Angle X 0.05467297
Angle Y 0.31104
Angle Z -0.1543787

Does that look ok to you?  I've attached the code that produces the above result.

            // Add minimum distance based on radius [Negative as -ve z goes into screen in XNA]
            Vector3 v = new Vector3(0, 0, -10);
 
            float PI = MathHelper.Pi;
 
            // Choose a random x and y angle between -45 degrees and +45 degrees
            float random_Angle_X = Game1.Random.NextFloat(-PI * 0.25f, PI * 0.25f); // ±45 degrees in radians
            float random_Angle_Y = Game1.Random.NextFloat(-PI * 0.25f, PI * 0.25f); // ±45 degrees in radians
            float random_Angle_Z = Game1.Random.NextFloat(-PI, PI);                 // ±360 degrees in radians
 
            // Rotate around z axis first
            Matrix transform = Matrix.CreateRotationZ(random_Angle_Z) * Matrix.CreateRotationX(random_Angle_X) * Matrix.CreateRotationY(random_Angle_Y);
 
            // Rotate v around x and y axes by random amount
            v = Vector3.Transform(v, transform);
           
            waypoint_Current += v;

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:

Select allOpen in new window

 

by: ikeworkPosted on 2009-11-08 at 05:53:56ID: 25770457

Dont use angle y, otherwise the spline can go backwards in Z
Post the waypoints and angles without Y-rotation.

 

by: Dr_SpankensteinPosted on 2009-11-08 at 06:28:08ID: 25770567

>> Dont use angle y, otherwise the spline can go backwards in Z

Using the code I posted, I am yet  encounter this problem?!  Could you please tell me how I could move left and right along x axis otherwise?

The waypoints and angles without Y-rotation are as follows:

Waypoint {X:0 Y:6.889179 Z:-7.248394}
Angle X 0.7599951
Angle Z 0.4378066

Waypoint {X:0 Y:10.88693 Z:-16.41452}
Angle X 0.4112718
Angle Z 0.1886871

Waypoint {X:0 Y:7.357797 Z:-25.77108}
Angle X -0.3606833
Angle Z -2.718297

Waypoint {X:0 Y:12.15866 Z:-34.5433}
Angle X 0.5007525
Angle Z 2.248204

Waypoint {X:0 Y:8.802938 Z:-43.96344}
Angle X -0.3422121
Angle Z -0.3956946

Waypoint {X:0 Y:14.30305 Z:-52.31502}
Angle X 0.5823773
Angle Z -1.499322

Waypoint {X:0 Y:18.27353 Z:-61.493}
Angle X 0.408298
Angle Z 2.5688

Waypoint {X:0 Y:15.89339 Z:-71.20561}
Angle X -0.2403199
Angle Z -2.731313

Waypoint {X:0 Y:10.97704 Z:-79.91362}
Angle X -0.5139669
Angle Z -1.708202  

Thank you.

 

by: ikeworkPosted on 2009-11-08 at 06:42:19ID: 25770607

>> Could you please tell me how I could move left and right along x axis otherwise?

By rotating first around x-axis, then around z-axis. This must change the x value as well. If X is 0.0, then there is something wrong with the rotation.
Looks like CreateFromYawPitchRoll rotation rolol(z) first, then Pitch. We can use the matrices directly, like you already did above.
Now the question is, if xna uses Pre- or Post-multiplication of matrices. So if this does not work:

Matrix transform = Matrix.CreateRotationZ(random_Angle_Z) * Matrix.CreateRotationX(random_Angle_X);

(X does not change), then swap the multiplication order, then it must work

            // Add minimum distance based on radius [Negative as -ve z goes into screen in XNA]
            Vector3 v = new Vector3(0, 0, -10);
 
            float PI = MathHelper.Pi;
 
            float random_Angle_X = Game1.Random.NextFloat(-PI * 0.25f, PI * 0.25f); // ±45 degrees in radians
            float random_Angle_Z = Game1.Random.NextFloat(-PI, PI);                 // ±360 degrees in radians
 
            Matrix transform = Matrix.CreateRotationZ(random_Angle_Z) * Matrix.CreateRotationX(random_Angle_X);
 
            v = Vector3.Transform(v, transform);
           
            waypoint_Current += v;

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:

Select allOpen in new window

 

by: Dr_SpankensteinPosted on 2009-11-08 at 07:42:08ID: 25770768

I see, so if XNA uses Pre Multiplication and I want to rotate around the z axis first before rotating around the x axis, I would do the following:

Matrix transform = Matrix.CreateRotationX(random_Angle_X) * Matrix.CreateRotationZ(random_Angle_Z);

Is that correct?

 

by: ikeworkPosted on 2009-11-08 at 07:52:56ID: 25770800

1 of both, cant recall excactly now. What about the points? It works?

 

by: ikeworkPosted on 2009-11-08 at 08:01:04ID: 25770821

DirectX is Pre: RotZ * RotX

OpenGL is post: RotX * RotZ

 

by: Dr_SpankensteinPosted on 2009-11-08 at 08:23:15ID: 25770887

XNA is Pre Multiplication also.

For example:

WorldMatrix = Scale * Rotate * Translate (Not T * R * S)

Just to clarify (last time I promise):

You want me to rotate around the X axis first then around the Z axis?  (Pre M = x * z)

 

by: ikeworkPosted on 2009-11-08 at 08:31:33ID: 25770916

>> You want me to rotate around the X axis first then around the Z axis?

Yepp. I dont use XNA, I dont know the conventions of it.

 

by: Dr_SpankensteinPosted on 2009-11-08 at 08:47:49ID: 25770960

No worries.

I still haven't figured out a tube radius (r) to minimum waypoint distance (d) ratio yet that works.

If:
r = d      causes overlapping
r * 2 = d causes overlapping
r * 3 = d causes overlapping
r * 4 = d causes overlapping
etc.

It seems that r * 10 = d is the first ratio that works but I am not sure as to why.  Any clues?

 

by: ikeworkPosted on 2009-11-08 at 10:15:29ID: 25771253

Because the bigger the radius, the higher is the possibility that it overlaps. Or the other way around: the smaller the distances, the higher the possibility that it overlaps.
We're getting much off-topic here.

 

by: ikeworkPosted on 2009-11-08 at 10:21:30ID: 25771275

If your question is, how to calculate that ratio, I must admit I have no idea. That is really a complicated topic, you should ask that in the math section, but I really dont think they will give you a formula how to calculate it. I would take a practical approach and try it first, there will hardly be any chance that you need to generate a random spline with tube in a program. For a wipe-out style game, you will use well defined points and store them in *race-tracks* rather than generate them randomly

 

by: Dr_SpankensteinPosted on 2009-11-08 at 11:45:39ID: 31651248

Thanks to both of you!

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...