Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8554961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:00:26+00:00 2026-06-11T15:00:26+00:00

I am developing a small application that renders spheres in a Java 3D SimpleUniverse,

  • 0

I am developing a small application that renders spheres in a Java 3D SimpleUniverse, and then, connects some of the spheres with lines. Creating the spheres is working, also creating lines. Trouble comes when involving movement in the recipe.
Moving spheres is quite easy using Transform3D objects and giving new coordinates. But, I want to update the lines connecting two distant spheres, and it’s important to mention that both spheres may have moved an arbitrary amount of space in any direction, and calculations are updated dozens of times per second, and they keep updating for a rather long time (more than 5 minutes).
Is there any simple way to update line coordinates in Java3D (LineArray objects I am using)?
Here is some part of the code I am working on right now:

TransformGroup [] segments;

public void createLines(SphereSet sphereSet, BranchGroup branchGroup) {
    segments = new TransformGroup[sphereSet.getEdgeSet().size()]; //Each edge connects two spheres in the sphereSet.
    Point3f [] source_dest = new Point3f[2];
    int lineIndex = 0;
    for (Edge e : sphereSet.getEdgeSet()) {
        segments[lineIndex] = new TransformGroup();
        segments[lineIndex].setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
/**
 *  Now create the Point3f pair that represents a segment connecting two spheres.
 */
        source_dest[0] = new Point3f();
        source_dest[1] = new Point3f();
        source_dest[0].setX(e.getSource().getCoordinates()[0]);
        source_dest[0].setY(e.getSource().getCoordinates()[1]);
        source_dest[0].setZ(e.getSource().getCoordinates()[2]);
        source_dest[1].setX(e.getTarget().getCoordinates()[0]);
        source_dest[1].setY(e.getTarget().getCoordinates()[1]);
        source_dest[1].setZ(e.getTarget().getCoordinates()[2]);

        LineArray line = new LineArray(2, LineArray.COORDINATES);
        line.setCoordinates(0, source_dest);

        Appearance lineApp = new Appearance();
        LineAttributes lineAttr = new LineAttributes(2, LineAttributes.PATTERN_SOLID, true);
        lineApp.setLineAttributes(lineAttr);

        Shape3D lineShape = new Shape3D(line, lineApp);
        segments[lineIndex].addChild(lineShape);

        branchGroup.addChild(segments[lineIndex]);

        lineIndex++;
    }
}

//Now, spheres' coordinates are updated... and we need to update lines' coordinates.

public void updateLines(SphereSet sphereSet) {

    int segmentIndex = 0;
    for (Edge e : sphereSet.getEdgeSet()) {
        //MYSTERIOUS CODE GOES HERE
        segmentIndex++;
    }
}

Thanks in advance.
P.S.: Maybe I need to do it via a transform Matrix. In such case, advise on how to calculate it will be very helpful. Also in such case, I’d like to know if after an arbitrary big nuber of iterations, due to loss of precission, lines’ ends are likely to not match the spheres’ centers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:00:28+00:00Added an answer on June 11, 2026 at 3:00 pm

    1) Create a class derived from javax.media.j3d.Behavior, e.g.:

    public class MyBehavior extends Behavior {
    
        private WakeupCondition wc = new WakeupOnElapsedTime(100); // Every 0.1 sec.
    
        public void initialize() {
    
          wakeupOn(wc);
        }
    
        public void processStimulus(Enumeration criteria) {
    
          double[] p = { 0, 0, 0 };
          for(int i = 0;i < nLinePoints;i++) {
              line.getCoordinate(i,p);
              p[0] += RandGenerator.randUniform(-0.1,0.1);
              p[1] += RandGenerator.randUniform(-0.1,0.1);
              p[2] += RandGenerator.randUniform(-0.1,0.1);
              line.setCoordinate(i,p);
          }
          wakeupOn(wc);
        }
    }
    

    2) In your createLines() method, allow coordinates to be read and written:

    line.setCapability(LineArray.ALLOW_COORDINATE_READ);
    line.setCapability(LineArray.ALLOW_COORDINATE_WRITE);
    

    3) Attach the behavior to your scene graph:

    MyBehavior randomEffect = new MyBehavior();
    randomEffect.setSchedulingBounds(new BoundingSphere(new Point3d(0.0, 0.0,0.0), 100.0));
    rootBranchGroup.addChild(randomEffect);
    

    BoundingSphere defines a subspace where the behavior is actually executed

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a small C# application that scans a log file for lines containing
I'm developing an application that should encrypt some small (less than 1MB) and large
I am developing a small application and for that authentication is needed. That I'm
I am developing a small application to get some picture from a scanner. What
My Problem We are developing a locally-hosted web application for small businesses. We also
I am developing a small application that executes shell commands and displays the output
I am developing a small application that is going to serve as viewer (sort
I am developing a small application in Java. I am using Java2D Library for
I'm developing an application that is so far using HttpListener to provide a small
I'm currently developing an iPad application that integrates MapKit. But I have a small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.