Community
3ds Max Modeling
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max modeling topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trajectory through 2 objects

17 REPLIES 17
SOLVED
Reply
Message 1 of 18
Anonymous
1459 Views, 17 Replies

Trajectory through 2 objects

Anonymous
Not applicable

Hello everyone,

 

I've tried to search the web but was unsuccessful in finding the right answer to the question that I have.

 

I want to determine the steps I need to perform to connect 2 objects (such as spheres) with a line/cylinder that will extend past both of them (such as per the picture below).

 

Untitled.png

 

Right now, I'm creating a long cylinder and placing the tip at the middle of one sphere, and manually aligning the rest of the cylinder to the second sphere, but as you can imagine - it's not accurate.

 

Any ways to do this properly?

 

Also, an option of extending/shortening the cylinder later would be great too, since I didn't find how to do that either

0 Likes

Trajectory through 2 objects

Hello everyone,

 

I've tried to search the web but was unsuccessful in finding the right answer to the question that I have.

 

I want to determine the steps I need to perform to connect 2 objects (such as spheres) with a line/cylinder that will extend past both of them (such as per the picture below).

 

Untitled.png

 

Right now, I'm creating a long cylinder and placing the tip at the middle of one sphere, and manually aligning the rest of the cylinder to the second sphere, but as you can imagine - it's not accurate.

 

Any ways to do this properly?

 

Also, an option of extending/shortening the cylinder later would be great too, since I didn't find how to do that either

17 REPLIES 17
Message 2 of 18
leeminardi
in reply to: Anonymous

leeminardi
Mentor
Mentor

The first question I would ask is "do you really need a cylinder between the two spheres"? Could you use a line with a renderable radial cross section like this?  It would look the same as having a cylinder.

rr1.JPG

If you really need a cylinder I would create a cylinder (using pivot snaps) located at one of the spheres and then use a look-at constraint (Animation, Constraints, LookAt Constraint), click the other sphere and then check the Z axis. You can eyeball the height of the cylinder or use Tools, Measure Distance to get an exact value.

rr2.JPG

lee.minardi
0 Likes

The first question I would ask is "do you really need a cylinder between the two spheres"? Could you use a line with a renderable radial cross section like this?  It would look the same as having a cylinder.

rr1.JPG

If you really need a cylinder I would create a cylinder (using pivot snaps) located at one of the spheres and then use a look-at constraint (Animation, Constraints, LookAt Constraint), click the other sphere and then check the Z axis. You can eyeball the height of the cylinder or use Tools, Measure Distance to get an exact value.

rr2.JPG

lee.minardi
Message 3 of 18
miledrizk
in reply to: Anonymous

miledrizk
Advisor
Advisor
Accepted solution

Hi,

 

You'll find attached a link to a video explaining how to do that using a small script,

 

The text file containing the script will be attached here too.

 

The script: https://drive.google.com/file/d/1qhiEj4pN85Ikf3VSigE-i9CqOgYeAUeW/view?usp=sharing

 

And the Video explaining all the steps: https://youtu.be/ZbHZUvKYzlc

------------------------------------------------------
miledrizk@gmail.com
3DS Max 2021, V-Ray 5.2
3DS Max user since 2003 (3DS Max 7)
V-Ray user since 2008 (V-Ray 1.47)
My YouTube Channel http//www.youtube.com/c/MiledRizk

Hi,

 

You'll find attached a link to a video explaining how to do that using a small script,

 

The text file containing the script will be attached here too.

 

The script: https://drive.google.com/file/d/1qhiEj4pN85Ikf3VSigE-i9CqOgYeAUeW/view?usp=sharing

 

And the Video explaining all the steps: https://youtu.be/ZbHZUvKYzlc

------------------------------------------------------
miledrizk@gmail.com
3DS Max 2021, V-Ray 5.2
3DS Max user since 2003 (3DS Max 7)
V-Ray user since 2008 (V-Ray 1.47)
My YouTube Channel http//www.youtube.com/c/MiledRizk
Message 4 of 18
leeminardi
in reply to: miledrizk

leeminardi
Mentor
Mentor

Here's a script that will creates a cylinder between two selected object.  The script has the radius of the cylinder set to 2 but that could easily be changed.

 

-- creates a cylinder of radius 2 between the centers of two selected objects.
-- L. Minardi 1/21/2018
if selection.count > 1 then
(
		for i in 1 to $.count do
	   (
	   p1 = $[1].pos
	   p2 = $[2].pos
	   )
	p3 = p2-p1
	plen = length(p3)
	p3u = p3/plen
	mycyl = cylinder radius:2 height:plen position:p1	-- <-- set radius as desired
	mycyl.transform = translate (matrixfromnormal p3u) p1
	redrawViews() 
)
else
	(messagebox "Please select 2 objects.")

 

I still think the best process is to create renderable lines between the spheres.  After creating the spline add a Spline IK Control modifier and add helper control objects and link them to the spheres.  This will let you move the spheres in 3D and the "cylinders" will follow.  Try moving the spheres in the attached Max file.

ss5.JPG

 

 

 

 

lee.minardi

Here's a script that will creates a cylinder between two selected object.  The script has the radius of the cylinder set to 2 but that could easily be changed.

 

-- creates a cylinder of radius 2 between the centers of two selected objects.
-- L. Minardi 1/21/2018
if selection.count > 1 then
(
		for i in 1 to $.count do
	   (
	   p1 = $[1].pos
	   p2 = $[2].pos
	   )
	p3 = p2-p1
	plen = length(p3)
	p3u = p3/plen
	mycyl = cylinder radius:2 height:plen position:p1	-- <-- set radius as desired
	mycyl.transform = translate (matrixfromnormal p3u) p1
	redrawViews() 
)
else
	(messagebox "Please select 2 objects.")

 

I still think the best process is to create renderable lines between the spheres.  After creating the spline add a Spline IK Control modifier and add helper control objects and link them to the spheres.  This will let you move the spheres in 3D and the "cylinders" will follow.  Try moving the spheres in the attached Max file.

ss5.JPG

 

 

 

 

lee.minardi
Message 5 of 18
miledrizk
in reply to: leeminardi

miledrizk
Advisor
Advisor

@leeminardi this is a good script,

 

I just noticed two problems in it:

 

1- the p1 and p2 are short lived variables since they are inside a for loop, so p3 = p2 - p1 will result in an error because p2 and p1

became undefined values for maxscript. As a result the script will not run.

 

2- Now fixing by just dropping the closing parenthesis after the redrawviews() function will fix it but will create another problem, because now,

that will create two cylinders instead of one, since we're looping twice. 

 

If we look carefully we don't need the for loop anyway.

the script can be simplified to:

 

if selection.count > 1 then
(
p1 = $[1].pos
p2 = $[2].pos
p3 = p2-p1
plen = length(p3)
p3u = p3/plen
mycyl = cylinder radius:2 height:plen position:p1 -- <-- set radius as desired
mycyl.transform = translate (matrixfromnormal p3u) p1
redrawViews()
)
else
(messagebox "Please select 2 objects.")

 

This time the script will work properly and will create one cylinder.

 

 

------------------------------------------------------
miledrizk@gmail.com
3DS Max 2021, V-Ray 5.2
3DS Max user since 2003 (3DS Max 7)
V-Ray user since 2008 (V-Ray 1.47)
My YouTube Channel http//www.youtube.com/c/MiledRizk
0 Likes

@leeminardi this is a good script,

 

I just noticed two problems in it:

 

1- the p1 and p2 are short lived variables since they are inside a for loop, so p3 = p2 - p1 will result in an error because p2 and p1

became undefined values for maxscript. As a result the script will not run.

 

2- Now fixing by just dropping the closing parenthesis after the redrawviews() function will fix it but will create another problem, because now,

that will create two cylinders instead of one, since we're looping twice. 

 

If we look carefully we don't need the for loop anyway.

the script can be simplified to:

 

if selection.count > 1 then
(
p1 = $[1].pos
p2 = $[2].pos
p3 = p2-p1
plen = length(p3)
p3u = p3/plen
mycyl = cylinder radius:2 height:plen position:p1 -- <-- set radius as desired
mycyl.transform = translate (matrixfromnormal p3u) p1
redrawViews()
)
else
(messagebox "Please select 2 objects.")

 

This time the script will work properly and will create one cylinder.

 

 

------------------------------------------------------
miledrizk@gmail.com
3DS Max 2021, V-Ray 5.2
3DS Max user since 2003 (3DS Max 7)
V-Ray user since 2008 (V-Ray 1.47)
My YouTube Channel http//www.youtube.com/c/MiledRizk
Message 6 of 18
leeminardi
in reply to: miledrizk

leeminardi
Mentor
Mentor

@miledrizk  Thank you for your comments.  It may be true that p1 and p2 are short lived but they live long enough to define the rest of the variables.  I tested my script several times and it works.

 

Did you actually try my script?

 

I tried the script with your edits and got the following error.

 

 

er1.JPG

 

I am very new to Maxscripts and was not sure of the best way to define two named variables that were object properties. I thought there should be a cleaner way than using the for loop that I have in my code. But again, it works!

 

Lee

lee.minardi
0 Likes

@miledrizk  Thank you for your comments.  It may be true that p1 and p2 are short lived but they live long enough to define the rest of the variables.  I tested my script several times and it works.

 

Did you actually try my script?

 

I tried the script with your edits and got the following error.

 

 

er1.JPG

 

I am very new to Maxscripts and was not sure of the best way to define two named variables that were object properties. I thought there should be a cleaner way than using the for loop that I have in my code. But again, it works!

 

Lee

lee.minardi
Message 7 of 18
miledrizk
in reply to: leeminardi

miledrizk
Advisor
Advisor

Hi,

 

yes i did try the script and it gave me this error message:error.PNG

which is normal because, to be able to maintain the life of those two variables you need to declare them before entering the for loop,

 

this way they become local variables in the if context not the for loop context,

 

If you like to keep your script the way it is it can be done simply by adding one line before the for loop which is: local p1, p2

 

works.PNG

Now it works

 

As for the modified script i made: it works also

works 2.PNG

 

 

 

 

------------------------------------------------------
miledrizk@gmail.com
3DS Max 2021, V-Ray 5.2
3DS Max user since 2003 (3DS Max 7)
V-Ray user since 2008 (V-Ray 1.47)
My YouTube Channel http//www.youtube.com/c/MiledRizk
0 Likes

Hi,

 

yes i did try the script and it gave me this error message:error.PNG

which is normal because, to be able to maintain the life of those two variables you need to declare them before entering the for loop,

 

this way they become local variables in the if context not the for loop context,

 

If you like to keep your script the way it is it can be done simply by adding one line before the for loop which is: local p1, p2

 

works.PNG

Now it works

 

As for the modified script i made: it works also

works 2.PNG

 

 

 

 

------------------------------------------------------
miledrizk@gmail.com
3DS Max 2021, V-Ray 5.2
3DS Max user since 2003 (3DS Max 7)
V-Ray user since 2008 (V-Ray 1.47)
My YouTube Channel http//www.youtube.com/c/MiledRizk
Message 8 of 18
leeminardi
in reply to: miledrizk

leeminardi
Mentor
Mentor

@miledrizk  I closed and reopened Max and was then able to successfully execute the version of my script with your edits.  I had trouble finding documentation of how to reference individual elements of selected objects.  The $[n] format is so simple but difficult to find.  Thank you for the tip.

 

Here then is the final code for the script for @Anonymous.

 

-- creates a cylinder of radius 2 between two selected objects.
-- edit the radius value in line 10 as required.
if selection.count > 1 then
(
p1 = $[1].pos
p2 = $[2].pos
p3 = p2-p1
plen = length(p3)
p3u = p3/plen
mycyl = cylinder radius:2 height:plen position:p1 -- <-- set radius as desired
mycyl.transform = translate (matrixfromnormal p3u) p1
redrawViews()
)
else
(messagebox "Please select 2 objects.")

 

lee.minardi

@miledrizk  I closed and reopened Max and was then able to successfully execute the version of my script with your edits.  I had trouble finding documentation of how to reference individual elements of selected objects.  The $[n] format is so simple but difficult to find.  Thank you for the tip.

 

Here then is the final code for the script for @Anonymous.

 

-- creates a cylinder of radius 2 between two selected objects.
-- edit the radius value in line 10 as required.
if selection.count > 1 then
(
p1 = $[1].pos
p2 = $[2].pos
p3 = p2-p1
plen = length(p3)
p3u = p3/plen
mycyl = cylinder radius:2 height:plen position:p1 -- <-- set radius as desired
mycyl.transform = translate (matrixfromnormal p3u) p1
redrawViews()
)
else
(messagebox "Please select 2 objects.")

 

lee.minardi
Message 9 of 18
Anonymous
in reply to: leeminardi

Anonymous
Not applicable

Thank you so much for help!

 

I now have another question.

 

When I connect the two spheres with a cylinder/line, and extend the line past the spheres, I would like to add a semi-transparent cone that would come out of one of the spheres and extend along the line that would show a +/- 5 degrees radius.

 

How do I go about that?

 

Bullet_Trajectory_Plugin_FARO_Scene.jpg

0 Likes

Thank you so much for help!

 

I now have another question.

 

When I connect the two spheres with a cylinder/line, and extend the line past the spheres, I would like to add a semi-transparent cone that would come out of one of the spheres and extend along the line that would show a +/- 5 degrees radius.

 

How do I go about that?

 

Bullet_Trajectory_Plugin_FARO_Scene.jpg

Message 10 of 18
miledrizk
in reply to: Anonymous

miledrizk
Advisor
Advisor

Hi,

 

I updated my original script,

 

I also made a Screencast to show you how to use it,

 

Please find attached the text file here: https://drive.google.com/file/d/16H-Vt9CYe_eyBjU5KSQyTMD3hDru1uoG/view?usp=sharing

 

 

 

------------------------------------------------------
miledrizk@gmail.com
3DS Max 2021, V-Ray 5.2
3DS Max user since 2003 (3DS Max 7)
V-Ray user since 2008 (V-Ray 1.47)
My YouTube Channel http//www.youtube.com/c/MiledRizk
0 Likes

Hi,

 

I updated my original script,

 

I also made a Screencast to show you how to use it,

 

Please find attached the text file here: https://drive.google.com/file/d/16H-Vt9CYe_eyBjU5KSQyTMD3hDru1uoG/view?usp=sharing

 

 

 

------------------------------------------------------
miledrizk@gmail.com
3DS Max 2021, V-Ray 5.2
3DS Max user since 2003 (3DS Max 7)
V-Ray user since 2008 (V-Ray 1.47)
My YouTube Channel http//www.youtube.com/c/MiledRizk
Message 11 of 18
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
Thank you for the video!

Quick correction: the cone has to extend from one sphere on the outside of the trajectory instead of the inside (if 0 is the tip of my line, 1 is my first sphere and 2 is my second sphere, I need the cone to be outgoing between 0 and 1, not 1 and 2). Also, can I extend the line beyond the sphere longer? Sometimes I have to make it up to 100 ft long with the cone extending to the tip from the sphere.
0 Likes

Thank you for the video!

Quick correction: the cone has to extend from one sphere on the outside of the trajectory instead of the inside (if 0 is the tip of my line, 1 is my first sphere and 2 is my second sphere, I need the cone to be outgoing between 0 and 1, not 1 and 2). Also, can I extend the line beyond the sphere longer? Sometimes I have to make it up to 100 ft long with the cone extending to the tip from the sphere.
Message 12 of 18
miledrizk
in reply to: Anonymous

miledrizk
Advisor
Advisor

Hi,

 

For the Cylinder length you can update the text by going to the second chunk, responsible for positioning the cylinder,

 

And the second line "target_cyl.height = length(dir)+(obj1.radius + obj2.radius)*2"

 

Keep the part "target_cyl.height = length(dir)" as it makes the cylinder's height equals the distance between the centers of the spheres,

 

Then type "+" (without the quotation marks) and add the amount you like. Just remember to update the Cylinder, you need to choose all the chunk

 

responsible for the Cylinder Position and click the Shift+Enter not just this line.

 

For the first request i'll try to update it.

 

So if i understood correctly you need the Cone's tip to be at the beginning of the Cylinder(close to sphere 1)  and extends

 

only to this near sphere(sphere 1), no Cone between the two spheres.

 

------------------------------------------------------
miledrizk@gmail.com
3DS Max 2021, V-Ray 5.2
3DS Max user since 2003 (3DS Max 7)
V-Ray user since 2008 (V-Ray 1.47)
My YouTube Channel http//www.youtube.com/c/MiledRizk
0 Likes

Hi,

 

For the Cylinder length you can update the text by going to the second chunk, responsible for positioning the cylinder,

 

And the second line "target_cyl.height = length(dir)+(obj1.radius + obj2.radius)*2"

 

Keep the part "target_cyl.height = length(dir)" as it makes the cylinder's height equals the distance between the centers of the spheres,

 

Then type "+" (without the quotation marks) and add the amount you like. Just remember to update the Cylinder, you need to choose all the chunk

 

responsible for the Cylinder Position and click the Shift+Enter not just this line.

 

For the first request i'll try to update it.

 

So if i understood correctly you need the Cone's tip to be at the beginning of the Cylinder(close to sphere 1)  and extends

 

only to this near sphere(sphere 1), no Cone between the two spheres.

 

------------------------------------------------------
miledrizk@gmail.com
3DS Max 2021, V-Ray 5.2
3DS Max user since 2003 (3DS Max 7)
V-Ray user since 2008 (V-Ray 1.47)
My YouTube Channel http//www.youtube.com/c/MiledRizk
Message 13 of 18
Anonymous
in reply to: miledrizk

Anonymous
Not applicable

Not quite. Attaching a simple drawing to explain what I needUntitled.png

0 Likes

Not quite. Attaching a simple drawing to explain what I needUntitled.png

Message 14 of 18
miledrizk
in reply to: Anonymous

miledrizk
Advisor
Advisor

Ah ok,

 

So the Tip starts at the sphere and the base goes at the end of the Cylinder,

 

I'll try to update it as soon as possible.

 

Now try the Cylinder Fix,

 

I need to relax a little, very tired! :))

------------------------------------------------------
miledrizk@gmail.com
3DS Max 2021, V-Ray 5.2
3DS Max user since 2003 (3DS Max 7)
V-Ray user since 2008 (V-Ray 1.47)
My YouTube Channel http//www.youtube.com/c/MiledRizk
0 Likes

Ah ok,

 

So the Tip starts at the sphere and the base goes at the end of the Cylinder,

 

I'll try to update it as soon as possible.

 

Now try the Cylinder Fix,

 

I need to relax a little, very tired! :))

------------------------------------------------------
miledrizk@gmail.com
3DS Max 2021, V-Ray 5.2
3DS Max user since 2003 (3DS Max 7)
V-Ray user since 2008 (V-Ray 1.47)
My YouTube Channel http//www.youtube.com/c/MiledRizk
Message 15 of 18
miledrizk
in reply to: Anonymous

miledrizk
Advisor
Advisor

Hi,

 

You'll find attached an updated version of the script:

 

https://drive.google.com/file/d/1Ttg04aTn8nhFcyMAzhyU-6r69xiBXKWa/view?usp=sharing

 

And another Screencast 

 

 

------------------------------------------------------
miledrizk@gmail.com
3DS Max 2021, V-Ray 5.2
3DS Max user since 2003 (3DS Max 7)
V-Ray user since 2008 (V-Ray 1.47)
My YouTube Channel http//www.youtube.com/c/MiledRizk
0 Likes

Hi,

 

You'll find attached an updated version of the script:

 

https://drive.google.com/file/d/1Ttg04aTn8nhFcyMAzhyU-6r69xiBXKWa/view?usp=sharing

 

And another Screencast 

 

 

------------------------------------------------------
miledrizk@gmail.com
3DS Max 2021, V-Ray 5.2
3DS Max user since 2003 (3DS Max 7)
V-Ray user since 2008 (V-Ray 1.47)
My YouTube Channel http//www.youtube.com/c/MiledRizk
Message 16 of 18
Anonymous
in reply to: miledrizk

Anonymous
Not applicable

Tried your scripts, they work really well, thank you!

 

Another question.

 

Anyway for me to link the cylinder to both spheres simultaniously? so that when they move the cylinder moves with them?

0 Likes

Tried your scripts, they work really well, thank you!

 

Another question.

 

Anyway for me to link the cylinder to both spheres simultaniously? so that when they move the cylinder moves with them?

Message 17 of 18
miledrizk
in reply to: Anonymous

miledrizk
Advisor
Advisor

Hi,

 

First welcome and glad it helped! 🙂

 

Now for the linking thing, there is a quick way and that's for me to update the script and make it

 

In a way that the two spheres and the cylinder become a group,

 

But in this case the three of them will move, rotate and scale at the same time,

 

But if you're thinking of moving only one, let's say one sphere to the left and make the Cylinder follows by rotating

 

And keep it's relation with both spheres the same. If that's the case it will complicate things and it will take more time

 

I have lots of work the coming two days, i give private lessons in Rhino so i need to prepare, maybe after that i can think

 

of something, if this is what you're thinking of, 

 

Otherwise, if grouping is good enough for you i can update it for you

------------------------------------------------------
miledrizk@gmail.com
3DS Max 2021, V-Ray 5.2
3DS Max user since 2003 (3DS Max 7)
V-Ray user since 2008 (V-Ray 1.47)
My YouTube Channel http//www.youtube.com/c/MiledRizk
0 Likes

Hi,

 

First welcome and glad it helped! 🙂

 

Now for the linking thing, there is a quick way and that's for me to update the script and make it

 

In a way that the two spheres and the cylinder become a group,

 

But in this case the three of them will move, rotate and scale at the same time,

 

But if you're thinking of moving only one, let's say one sphere to the left and make the Cylinder follows by rotating

 

And keep it's relation with both spheres the same. If that's the case it will complicate things and it will take more time

 

I have lots of work the coming two days, i give private lessons in Rhino so i need to prepare, maybe after that i can think

 

of something, if this is what you're thinking of, 

 

Otherwise, if grouping is good enough for you i can update it for you

------------------------------------------------------
miledrizk@gmail.com
3DS Max 2021, V-Ray 5.2
3DS Max user since 2003 (3DS Max 7)
V-Ray user since 2008 (V-Ray 1.47)
My YouTube Channel http//www.youtube.com/c/MiledRizk
Message 18 of 18
Anonymous
in reply to: miledrizk

Anonymous
Not applicable
No trouble at all. There is no rush.




Unfortunately I would prefer the second option that is more complicated.




Thank you!



0 Likes

No trouble at all. There is no rush.




Unfortunately I would prefer the second option that is more complicated.




Thank you!



Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report