Skip to main content

Drawing a 3D curve

9 replies [Last post]
oliveira_dias
Offline
Joined: 2006-09-21

Hi folks,

I need a simple help, in Java3D programming. I have a sample code with draw a line using 2 dots, but I need drawing a curve 3D using a class Point3f or other.
I have a simple sample code here:

Point3f[] dotPts = new Point3f[2];
dotPts[0] = new Point3f(-0.4f, -0.7f, 0.0f);
dotPts[1] = new Point3f(-0.0f, 0.7f, 0.0f);

When I insert a new Point, the program don't compile.

Plese, help me folks.

Eduardo Dias

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Andre Bialojahn

Have a look at the API:

LineArray:
"The LineArray object draws the array of vertices as individual line
segments. Each pair of vertices defines a line to be drawn."

The vertices must appear _in pairs_.
Since "three" is no even multiple of "two", you receive the exception.
Add another point and it should work, but observe the way that
LineArray is drawn. It is a collection of lines, *not* a polygon line.

Have a closer look at the API documentation and maybe another one at
the J3D tutorial.

André

java3d-interest@javadesktop.org wrote:
> Hi Dmitri
>
> I insert the new point thus:
>
> Point3f[] dotPts = new Point3f[3];
> dotPts[0] = new Point3f(-0.4f, -0.7f, 0.0f);
> dotPts[1] = new Point3f(-0.0f, 0.7f, 0.0f);
> dotPts[2] = new Point3f(0.4f, 0.7f, 0.0f);
>
> And the error message is this:
> ______________
> java.lang.IllegalArgumentException: LineArray: illegal vertexCount
[...]
> LineArray dot = new LineArray(3, LineArray.COORDINATES);
[...]

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net

Dmitri Darine

java3d-interest@javadesktop.org wrote:
>
> When I insert a new Point, the program don't compile.
>
>
How do you insert it? Post more code.

--

Best regards
Dmitri Darine

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net

oliveira_dias
Offline
Joined: 2006-09-21

Hi Dmitri

I insert the new point thus:

Point3f[] dotPts = new Point3f[3];
dotPts[0] = new Point3f(-0.4f, -0.7f, 0.0f);
dotPts[1] = new Point3f(-0.0f, 0.7f, 0.0f);
dotPts[2] = new Point3f(0.4f, 0.7f, 0.0f);

And the error message is this:
______________
java.lang.IllegalArgumentException: LineArray: illegal vertexCount
at javax.media.j3d.LineArray.(LineArray.java:52)
at LineTypes.createLineTypes(LineTypes.java:108)
at LineTypes.createSceneGraph(LineTypes.java:148)
at LineTypes.init(LineTypes.java:204)
at com.sun.j3d.utils.applet.MainFrame.run(MainFrame.java:262)
at java.lang.Thread.run(Thread.java:536)
_______--

Most code is in here:
Group createLineTypes() {

Group lineGroup = new Group();

Appearance app = new Appearance();
ColoringAttributes ca = new ColoringAttributes(black,
ColoringAttributes.SHADE_FLAT);
app.setColoringAttributes(ca);

// line pattern dot
Point3f[] dotPts = new Point3f[3];
dotPts[0] = new Point3f(-0.4f, -0.7f, 0.0f);
dotPts[1] = new Point3f(-0.0f, 0.7f, 0.0f);
dotPts[2] = new Point3f(0.4f, 0.7f, 0.0f);
LineArray dot = new LineArray(3, LineArray.COORDINATES);
dot.setCoordinates(0, dotPts);
LineAttributes dotLa = new LineAttributes();
dotLa.setLineWidth(2.0f);
dotLa.setLinePattern(LineAttributes.PATTERN_DOT);
Appearance dotApp = new Appearance();
dotApp.setLineAttributes(dotLa);
dotApp.setColoringAttributes(ca);
Shape3D dotShape = new Shape3D(dot, dotApp);
lineGroup.addChild(dotShape);

return lineGroup;

}

Thanks for help me

Eduardo Dias

Dmitri Darine

java3d-interest@javadesktop.org wrote:
> Hi Dmitri
>
> I insert the new point thus:
>
>
> Point3f[] dotPts = new Point3f[3];
> dotPts[0] = new Point3f(-0.4f, -0.7f, 0.0f);
> dotPts[1] = new Point3f(-0.0f, 0.7f, 0.0f);
> dotPts[2] = new Point3f(0.4f, 0.7f, 0.0f);
>
>

public class *LineArray*
extends GeometryArray

The LineArray object draws the array of vertices as individual line
segments. _*Each pair(!!!)*_ of vertices defines a line to be drawn.

Modify the code like this:

Point3f[] dotPts = new Point3f[4];
dotPts[0] = new Point3f(-0.4f, -0.7f, 0.0f);
dotPts[1] = new Point3f(-0.0f, 0.7f, 0.0f);
dotPts[2] = new Point3f(-0.0f, 0.7f, 0.0f);
dotPts[3] = new Point3f(0.4f, 0.7f, 0.0f);
LineArray dot = new LineArray(4, LineArray.COORDINATES);

--

Best regards
Dmitri Darine

[att1.html]

oliveira_dias
Offline
Joined: 2006-09-21

Dmitri,

The program running perfect, but I need drawing the curve, and the programm plots 2 lines.
How I make to draw a curve in the plane?
I have many points for drawing a curve, not a line.

Very thanks

Eduardo Dias

Dmitri Darine

java3d-interest@javadesktop.org wrote:
> Dmitri,
>
> The program running perfect, but I need drawing the curve, and the programm plots 2 lines.
> How I make to draw a curve in the plane?
> I have many points for drawing a curve, not a line.
>
> Very thanks
>
>
>
dotPts[0] = new Point3f(-0.4f, -0.7f, 0.0f);
dotPts[1] = new Point3f(-0.0f, 0.7f, 0.0f);
dotPts[2] = new Point3f(-0.0f, 0.7f, 0.0f);
dotPts[3] = new Point3f(0.4f, 0.7f, 0.0f);

dotPts[1] and dotPts[2] are located in the same place in the space, so
these two lines will be connected.
If you have a curve consisted of points A,B,C,D,E,F, then you can draw
it this way: AB BC CD DE EF

--

Best regards
Dmitri Darine

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net

Andre Bialojahn

Dmitri Darine wrote:
> java3d-interest@javadesktop.org wrote:
>> Dmitri,
>>
>> The program running perfect, but I need drawing the curve, and the
>> programm plots 2 lines.
>> How I make to draw a curve in the plane? I have many points for
>> drawing a curve, not a line.
>>
>> Very thanks
>
> dotPts[0] = new Point3f(-0.4f, -0.7f, 0.0f);
> dotPts[1] = new Point3f(-0.0f, 0.7f, 0.0f);
> dotPts[2] = new Point3f(-0.0f, 0.7f, 0.0f);
> dotPts[3] = new Point3f(0.4f, 0.7f, 0.0f);
>
> dotPts[1] and dotPts[2] are located in the same place in the space, so
> these two lines will be connected.
> If you have a curve consisted of points A,B,C,D,E,F, then you can draw
> it this way: AB BC CD DE EF

Or just use the javax.media.j3d.LineStripArray which is specialised
for this case:
"The LineStripArray object draws an array of vertices as a set of
connected line strips."
;-)

André

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net

oliveira_dias
Offline
Joined: 2006-09-21

Hi Dmitri,

The programm running ok now.
Thanks all folks, for help me and sorry for the stupid questions!!!!

Eduardo Dias

oliveira_dias
Offline
Joined: 2006-09-21

And...
If I need plot the points in a cartesian plane, how can I do?

But the points needs cartesian orientation.

Thanks folks.

Eduardo Dias