# Positioning Cylinders

## Recommended Posts

Hi

I'm totally new to Babylon, but have to complete a project

I'd be really grateful for anyones help on here

I have a sphere, made to look like the earth

I have a coordinate system, that positions bars around the Earth's surface according to a lat/long

now what I do, is take the Earth as the first sphere, create a sphere on its surface where say London is

Then join them by a cylinder

Learnt that from a topic on here

Then make the length of the cylinder too long, so it sticks out from the earths surface

its to represent something, so say London has 50% smog, New York 10%, Delhi 100%

and you can visualise different things around the world

anyways, it now seems we need 4 bars to protrude at each location

I have one cylinder in place, I need to position 4 thinner cylinders at the end of the larger cylinder

to form a kind of mini bar chart at each location

but I'm completely stumped about how to do this

I can do one, its centered on the larger cylinder on the same axis at the same angle

I want to shift each of them off center of the larger cylinder

any help would be much appreciated!

Many thanks

(I dont know if this is hard or easy)

##### Share on other sites

sorry WOPR, thankyou

here is PG - http://babylonjs-playground.com/#R7ZMI#1

Currently cylinder1a, cylinder2a, cylinder3a, cylinder4a are all at same point vend

I'd like to move them across the end of the larger cylinder

I'd like to be able to nudge them across that plane so they form a line

I don't know what arrangement I want, so I'd like to be able to control position and sizes

make sense?

Many thanks

##### Share on other sites

http://babylonjs-playground.com/#R7ZMI#2

I just simplified the PG so that we can focus on your geometry problem (and that my old laptop could run at a decent framerate)

So can you tell us a bit more, because I don't understand what you try to achieve.

I can see that you've got 4 red cylinders in the code and 1 transparent one.

How do you want your 4 cylinders to be located and orientated ?

##### Share on other sites

Thanks Jerome

ok, so the 4 red cylinders (thats all I care about)

lie on the end cap of the larger transparent cylinder

all centered on its end, overlapping each other

I want to basically move them round on that end cap

My original idea is to have them in a line, like a mini bar chart

but that may change, so I just need to be able to reposition them on that end cap

nudge them to the left or right so they form a line of columns

##### Share on other sites

let's redefine a little : you want the 4 red cylinders side by side, in a same plane, like panpipes

and you want this line of columns based on a tangent to the big sphere ?

EXACTLY!

##### Share on other sites

http://babylonjs-playground.com/#R7ZMI#3

I just computed a cross vector Y^vend what is a tangent vector to the sphere (orthogonal to both vend and Y world axis)

Then I normalized it

(line 41)

Then I just added this tangent vector, scaled to + or - your cylinder radius, to each red cylinder position.

Is this what you wanted ?

##### Share on other sites

It's perfect Jerome! Thankyou

May I ask one quick question?

If I wanted to nudge them along the other axis? (so right now they go left to right)

If I wanted them to go top to bottom? (just so I know)

How would I do that?

##### Share on other sites

for the other way (right to left), just change the values in the scale factor (-0.4, -0.2, etc)

for top to bottom, I guess you could change the y value of the pivot matrix from -dis/2 ot +dis/2

http://babylonjs-playground.com/#R7ZMI#4

##### Share on other sites

Thanks Jerome

but thats not what I meant

by top to bottom, I just mean right now they go "across" the tangent to the Earth

Like in Equal Latitude, I mean lined up in equal Longitude

Not "into" the Earth, but ALWAYS sticking out

make sense?

##### Share on other sites

Hi guys (Jerome?)

It's been changed now, I have to make the below?

Any help?

I really appreciate all your help so far Jerome

Thanks

##### Share on other sites

http://babylonjs-playground.com/#R7ZMI#5

just computed another tangent vector tan2, orthogonal to the first tangent tan and to the radius vend

So I have now 3 orthogonal axis at the surface of the sphere : vend, tan, tan2.

I just have to position the cylinders where I want in the plane (tan, tan2)

##### Share on other sites

Hi Jerome

I just implemented what you did here-

http://babylonjs-playground.com/#R7ZMI#6

and it works perfectly

but when I put it into the real site here-

http://www.nomanic.biz/babylon/

They are not perfect squares

any ideas?

Thanks

##### Share on other sites

http://babylonjs-playground.com/#R7ZMI#7

I just visualized the (tan, tan2) vectors on the point vend so you can understand how the squares were quickly set in this example.

You can of course set them differently according to your needs.

Just consider (tan, vend, tan2) as you would consider (X, O, Z) on the plane xOz

##### Share on other sites

Definitely impressive:)

meuh non

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.