PDA

View Full Version : Draw line with a triangle at the end


Chrissy2009
08-05-2009, 07:46 AM
Hi,

I want to draw a line and at the end of this line I want to draw an arrow.

I've made:

viz.startlayer(viz.LINES)
viz.linewidth(5)
viz.vertexcolor(0,0.6,0)
viz.vertex(punkt1)
viz.vertex(punkt2)
viz.startlayer(viz.TRIANGLES)
viz.vertex(1,0,0)
viz.vertex(-1,0,0)
viz.vertex(0,1,0)
name = viz.endlayer(scene=szene)

But now I've got the problem, that the triangle should be drawn in the local coordinate sytem of the line. So that the arrows shows allways at the right direction.

I looked at the tutorial "Hierarchical Models", but this does not help.

I want to draw a line and at the end of this line there should be an arrow.

And it should be possible to rotate the line along with the arrow.

Can anybody help me - please?

Thanks a lot!

Jeff
08-05-2009, 01:05 PM
You can set the triangle's parent to be the line and then when you move or rotate the line the triangle will follow.
triangle = viz.endlayer(parent=line)

Chrissy2009
08-06-2009, 04:08 AM
Hey,
I've done this, but it does not work:

viz.startlayer(viz.LINES)
viz.linewidth(5)
viz.vertexcolor(0,0.6,0)
viz.vertex(punkt1)
viz.vertex(punkt2)

viz.startlayer(viz.TRIANGLES)
viz.vertex(1,0,0)
viz.vertex(-1,0,0)
viz.vertex(0,1,0)
name = viz.endlayer(scene=szene)
triangle = viz.endlayer(parent=name)

name.center(punkt1)

01.bmp shows my actual program. But the arrow isn't at the right position.

In 02.bmp I've described my problem. I want to draw a line and afterthat I want to draw the triangle in the local coordinate system of the line.

So, that I'm able to set the triangle allways on
viz.vertex(1,0,0)
viz.vertex(-1,0,0)
viz.vertex(0,1,0)

regardless of which is the direction of the line.

Hope somebody can help me.

Chrissy2009
08-11-2009, 01:41 AM
Oh, is there nobody who can help me??? :( :confused:

GiudiceLab
08-11-2009, 07:03 AM
I don't know if it would work, but could you make the triangle vertices a function of the line vertex? Something like this:


viz.startlayer(viz.TRIANGLES)
v1 = line.getVertex(1)
viz.vertex(v1[0]+1,v1[1],v1[2])
viz.vertex(v1[0]-1,v1[1],v1[2])
viz.vertex(v1[0],v1[1]+1,v1[2])
triangle = viz.endlayer(parent=line)

Chrissy2009
08-11-2009, 08:49 AM
No, that does not work! Sorry! :mad:

Chrissy2009
08-12-2009, 11:27 PM
Oh, the arrows are so important for my project.

Is there no possibility to draw these? :confused::confused::confused:

farshizzo
08-13-2009, 10:39 AM
Here is a sample script that draws arbitrary arrows on the screen. Hope this helps:import viz
import vizmat
viz.go()

def addArrow(begin,end):

ARROW_SIZE = 0.015

#Find distance between points
d = vizmat.Distance(begin,end)

#Draw arrow line
viz.startlayer(viz.LINES)
viz.linewidth(5)
viz.vertex(0,0,0)
viz.vertex(0,d,0)

#Draw arrow tip
viz.startlayer(viz.TRIANGLES)
viz.vertex(-ARROW_SIZE,d,0)
viz.vertex(0,d+(2*ARROW_SIZE),0)
viz.vertex(ARROW_SIZE,d,0)

#Finish drawing arrow
arrow = viz.endlayer(parent=viz.SCREEN)

#Place/rotate arrow to match begin end points
arrow.setPosition(begin)
arrow.setEuler(0,0,-vizmat.AngleToPoint(begin,end))

return arrow

arrow1 = addArrow([0.2,0.2,0],[0.4,0.4,0])
arrow1.color(viz.GREEN)

arrow2 = addArrow([0.6,0.2,0],[0.8,0.9,0])
arrow2.color(viz.RED)

Chrissy2009
08-20-2009, 09:36 AM
Oh yes, thanks a lot!

If I draw one line, it works fine.
If I draw one line and afterthat I draw a second one it works fine, too.

But:
If I draw the two lines and turn this lines around the y-axis and afterthat I want to draw a third line from the end of the first line to the end of the second line, than it doesn't work.

I've found out, that the problem is the vizmat.AngleToPoint calculation. It works fine, if the two points are at the z-position 0. But If I turn the lines around so that the z-value is for example -0.5 then the calculation is wrong.

How can I solve this problem?

I want to draw to lines and turn this around the y-axis. And then I want to calculate the third line from the end of line1 to the end of line2.

Thanks a lot....

Chrissy2009
08-24-2009, 11:12 AM
Is there no way to solve my problem??? :confused::confused::confused::confused: