Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I have a complicated problem and it involves an understanding of Maths I'm not confident with.

Some slight context may help. I'm building a 3D train simulator for children and it will run in the browser using WebGL. I'm trying to create a network of points to place the track assets (see image) and provide reference for the train to move along.

To help explain my problem I have created a visual representation as I am a designer who can script and not really a programmer or a mathematician: enter image description here

Basically, I have 3 shapes (Figs. A, B & C) and although they have width, can be represented as a straight line for A and curves (B & C). Curves B & C are derived (bend modified) from A so are all the same length (l) which is 112. The curves (B & C) each have a radius (r) of 285.5 and the (a) angle they were bent at was 22.5°.

Each shape (A, B & C) has a registration point (start point) illustrated by the centre of the green boxes attached to each of them.

What I am trying to do is create a network of "track" starting at 0, 0 (using standard Cartesian coordinates).

My problem is where to place the next element after a curve. If it were straight track then there is no problem as I can use the length as a constant offset along the y axis but that would be boring so I need to add curves.

Fig. D. demonstrates an example of a possible track layout but please understand that I am not looking for a static answer (based on where everything is positioned in the image), I need a formula that can be applied no matter how I configure the track.

Using Fig. D. I tried to work out where to place the second curved element after the first one. I used the formula for plotting a point of the circumference of a circle given its centre coordinates and radius (Fig. E.).

I had point 1 as that was simply a case of setting the length (y position) of the straight line. I could easily work out the centre of the circle because that's just the offset y position, the offset of the radius (r) (x position) and the angle (a) which is always 22.5° (which, incidentally, was converted to Radians as per formula requirements).

After passing the values through the formula I didn't get the correct result because the formula assumed I was working anti-clockwise starting at 3 o'clock so I had to deduct 180 from (a) and convert that to Radians to get the expected result.

That did work and if I wanted to create a 180° track curve I could use the same centre point and simply deducted 22.5° from the angle each time. Great. But I want a more dynamic track layout like in Figs. D & E.

So, how would I go about working point 5 in Fig. E. because that represents the centre point for that curve segment? I simply have no idea.

Also, as a bonus question, is this the correct way to be doing this or am I over-complicating things?

This problem is the only issue stopping me from building my game and, as you can appreciate, it is a bit of a biggie so I thank anyone for their contribution in advance.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Answer provided on Stack Overflow:

http://stackoverflow.com/questions/14359823/how-to-calculate-a-point-on-a-circle-knowing-the-radius-and-center-point#comment19968567_14359823

Turns out I was over complicating matters and should have been using simpler trigonometric functions.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.