Forum > OpenGL
Graduated colour depending on offset from original position
wp:
This is OpenGL - simply add the colors to the OpenGL model of the lines, like I showed in the previous post.
ranny:
Sorry, I should have mentioned before, all graphics in this project are OpenGl. It's taking me quite a while to get an understanding it but I am pleased with the results.
For your suggestion I will find a way of linearly moving from, say, red to blue then compare to each orthogonally displaced point. Will keep me busy for a wee while.
Thanks.
wp:
In TAChart, there is a function for interpolating colors between two end colors weighted by a factor ACoeff (0..1):
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function InterpolateRGB(AColor1, AColor2: Integer; ACoeff: Double): Integer;type TBytes = packed array [1..4] of Byte;var c1: TBytes absolute AColor1; c2: TBytes absolute AColor2; r: TBytes absolute Result; i: Integer;begin ACoeff := EnsureRange(ACoeff, 0.0, 1.0); for i := 1 to 4 do r[i] := Round(c1[i] + (c2[i] - c1[i]) * ACoeff);end;
Adapting to your project, I would say, that ACoeff is the relative displacement (displacement at a vertex / max displacement). So, when you want to draw a segment between vertices V1 and V2, calculate the interpolated colors for both vertices and add them to the OpenGL command:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---const MinDisplColor = clBlue; MaxDisplColor = clRed;var MaxDisplacement: Double; procedure DrawSegment(V1, V1: TPoint3d; Displ1, Displ2: Double);var col1, col2: TColor;begin col1 := InterpolateRGB(MinDisplColor, MaxDisplColor, Displ1/MaxDisplacement); col2 := InterpolateRGB(MinDisplColor, MaxDisplColor, Displ2/MaxDisplacement); glBegin(GL_LINES); glColor3f(Red(col1)/255, Green(col1)/255, Blue(col1)/255); glVertex3f(V1.X, V1.Y, V1.Z); glColor3f(Red(col2)/255, Green(col2)/255, Blue(col2)/255); glVertex3f(V2.X, V2.Y, V2.Z); glEnd;end;
ranny:
That's exactly what I am looking for! Yesterday I spent the time getting the maximum values for displacement from the array of adjoining nodes and achieved some progress with colour graduation.
Going forward, your routine will be useable for displaying maximum stresses in the structure as well.
Thanks again, I' on the road to getting one of my projects close to completion, and genuinely useful!
Navigation
[0] Message Index
[*] Previous page