TARGETZerlegen eines Vektors in 2 Vektoren gleicher Länge
NICHT FERTIG !!!
PROBLEMS
Das Mathematische wissen blieb in der HTL und mußte aufgefrischt werden - LINK, LINK.
USED PROCESSING-FUNCTIONS- size()
- smooth()
- background()
- strokeWeight()
- stroke()
- line()
- fill()
- createFont()
- textFont()
- text()
EXPERIENCE
| CODEPFont fontOut; LegSegment legSeg1, legSeg2;
float centerx = 250; float centery = 250; float a2x = 250; float a2y = 250; float mx, my; float seg1Len= 120; float seg2Len= 70;
void setup() { size(500, 500); background(226); smooth(); strokeWeight(20.0); fontOut = createFont("arial", 20); textFont(fontOut, 10); legSeg1= new LegSegment( seg1Len, centerx, centery ); legSeg2= new LegSegment( seg2Len, centerx, centery ); }
void draw() { fill(0); background(226); mx= mouseX; my= mouseY; drawMouse(); float m_angle=calcMouseAngle();
float deltaX= mx - a2x; float deltaY= my - a2y; float legSeg1A= atan2( deltaY, deltaX ); float tempX= mx - seg2Len * cos(m_angle); float tempY= my - seg2Len * cos(m_angle); deltaX= tempX - centerx; deltaY= tempY - centery; float legSeg2A= atan2( deltaY, deltaX ); a2x= centerx + seg2Len * cos(legSeg2A); a2y= centery + seg2Len * sin(legSeg2A); legSeg1.setAngle( legSeg1A ); legSeg1.setXY( a2x, a2y); legSeg2.setAngle( legSeg2A ); legSeg2.setXY( centerx, centery ); legSeg1.drawSegment(); legSeg2.drawSegment(); }
void drawMouse () {
// draws the green line to the mouse stroke( 50, 200, 50, 100); line( a2x, a2y, mx, my); // draws the blue sin-line stroke( 50, 50, 200, 100); line( mx, my, mx, a2y); // drawa the red cos-line stroke( 200, 50, 50, 100); line( a2x, a2y, mx, a2y); // gives us data text("mx: "+round(mx), mx+5, my+2); text("my: "+round(my), mx+5, my+14);
float m_angle= calcMouseAngle(); float m_len= calcMouseLen(); text("v: "+round(degrees(m_angle)), mx+50, my+2); text("l: "+round(m_len), mx+50, my+14); }
float calcMouseAngle () { float m_n_dx = mx - a2x; float m_n_dy = my - a2y; return atan2(m_n_dy, m_n_dx); }
float calcMouseLen() { float m_n_dx = mx - a2x; float m_n_dy = my - a2y; return sqrt( m_n_dx * m_n_dx + m_n_dy * m_n_dy ); }
class LegSegment { float x; float y; float x2; float y2; float segAngle; float segLength; int r; int g; int b; int segAlpha; LegSegment( float ssegLength, float sx, float sy ) { segLength = ssegLength; x = sx; y = sy; segAngle = 0; setColor( 100, 100, 100 ); setAlpha( 100 ); calcXY(); } void setAngle( float sangle ) { segAngle= sangle; drawSegment(); } void setLength( float slen ) { segLength= slen; drawSegment(); } void setXY( float sx, float sy ) { x= sx; y= sy; drawSegment(); } void calcXY() { x2= x + segLength * cos( segAngle ); y2= y + segLength * sin( segAngle ); } void setAlpha( int salpha ) { segAlpha= salpha; } void setColor( int sr, int sg, int sb ) { r= sr; g= sg; b= sb; } void drawSegment() { calcXY(); stroke( r, g , b, segAlpha ); line ( x, y, x2, y2 ); } } |