QPair<CubicSegment, CubicSegment> CubicSegment::split(double t) { // first pass QPointF secondPointFirstSegment = interpolatedPoint(t, firstControlPoint().coordinate(), secondControlPoint().coordinate()); QPointF firstIntermediatPoint = interpolatedPoint(t, secondControlPoint().coordinate(), thirdControlPoint().coordinate()); QPointF thirdPointSecondSegment = interpolatedPoint(t, thirdControlPoint().coordinate(), fourthControlPoint().coordinate()); // second pass QPointF thirdPointFirstSegment = interpolatedPoint(t, secondPointFirstSegment, firstIntermediatPoint); QPointF secondPointSecondSegment = interpolatedPoint(t, firstIntermediatPoint, thirdPointSecondSegment); // third pass QPointF midPoint = interpolatedPoint(t, thirdPointFirstSegment, secondPointSecondSegment); ControlPoint midControlPoint(midPoint); CubicSegment firstCubicSegment = CubicSegment::create(); firstCubicSegment.setFirstControlPoint(firstControlPoint().coordinate()); firstCubicSegment.setSecondControlPoint(secondPointFirstSegment); firstCubicSegment.setThirdControlPoint(thirdPointFirstSegment); firstCubicSegment.setFourthControlPoint(midControlPoint); CubicSegment secondCubicSegment = CubicSegment::create(); secondCubicSegment.setFirstControlPoint(midControlPoint); secondCubicSegment.setSecondControlPoint(secondPointSecondSegment); secondCubicSegment.setThirdControlPoint(thirdPointSecondSegment); secondCubicSegment.setFourthControlPoint(fourthControlPoint().coordinate()); qDebug() << firstCubicSegment << secondCubicSegment; return qMakePair(firstCubicSegment, secondCubicSegment); }
void Spline::render(unique_ptr<Shader> &shader, bool showPoints, Config conf) { if (m_points.size() <= 1) return; vector<RenderableObject::Vertex> pointData; vector<RenderableObject::Vertex> lineData; glm::vec4 pColor(1.0f, 1.0f, 0.0f, 0.5f); // Interpolated Points for (float f = 0; f <= 1.0f; f += 0.01f) { glm::vec3 v = interpolatedPoint(f, conf); RenderableObject::Vertex newPt; newPt.Position = v; newPt.Color = pColor; lineData.push_back(newPt); } // Base Points for (uint i = 0; i < m_points.size(); ++i) { glm::vec3 v = m_points[i]; RenderableObject::Vertex newPt; newPt.Position = v; newPt.Color = pColor; pointData.push_back(newPt); } // Phantom Points std::vector<RenderableObject::Vertex> phantomPoints; float phantomPtSize = 3.0f; glm::vec3 p1 = m_phantomStart; glm::vec3 p2 = m_phantomEnd; RenderableObject::Vertex newPt1, newPt2; newPt1.Position = p1; newPt1.Color = glm::vec4(1.0f, 0.0f, 1.0f, 0.5f); newPt2.Position = p2; newPt2.Color = glm::vec4(0.0f, 1.0f, 1.0f, 0.5f); pointData.push_back(newPt1); pointData.push_back(newPt2); m_vboLines->setData(lineData, GL_LINE_STRIP); m_vboPoints->setData(pointData, GL_POINTS); if(showPoints) { m_vboLines->render(); glPointSize(m_ptSize); m_vboPoints->render(); glPointSize(1.0f); } }
TEST(InterpolatorTests, ShouldInterpolateNumbers){ Vector p1(-7, 5, 3); int p1Value = 10; Vector p2(3, 2, 3); int p2Value = 2; Vector p3(-2, -2, 3); int p3Value = -20; Vector interpolatedPoint(-1, 0, 3); Triangle3DInterpolator<double> interpolator(p1, p1Value, p2, p2Value, p3, p3Value); double interpolatedValue = interpolator.Interpolate(interpolatedPoint); EXPECT_NEAR(interpolatedValue, -9.928, 0.001); }