3#include <igl/predicates/predicates.h>
10 const Eigen::MatrixXd X_rest,
11 const Eigen::MatrixXd X)
12 : X_rest_(X_rest), X_(X)
18 igl::predicates::exactinit();
21 igl::predicates::Orientation res = igl::predicates::orient2d(
22 Eigen::Vector2d(x1.head<2>()),
23 Eigen::Vector2d(
X_rest_.row(1).head<2>()),
24 Eigen::Vector2d(
X_rest_.row(2).head<2>()));
27 return res == igl::predicates::Orientation::POSITIVE;
31 const Eigen::Vector2d &x0_rest,
32 const Eigen::Vector2d &x1_rest,
33 const Eigen::Vector2d &x2_rest,
34 const Eigen::Vector2d &x0,
35 const Eigen::Vector2d &x1,
36 const Eigen::Vector2d &x2)
39 x0_rest.x(), x0_rest.y(),
40 x1_rest.x(), x1_rest.y(),
41 x2_rest.x(), x2_rest.y(),
61 assert(
x.size() == 3);
62 throw std::runtime_error(
"AMIPSForm::first_derivative_unweighted not implemented for 3D");
67 const Eigen::VectorXd &
x, Eigen::VectorXd &grad)
const
69 grad.resize(
x.size());
84 assert(
x.size() == 3);
85 throw std::runtime_error(
"AMIPSForm::first_derivative_unweighted not implemented for 3D");
92 Eigen::MatrixXd H(
x.size(),
x.size());
107 assert(
x.size() == 3);
108 throw std::runtime_error(
"AMIPSForm::second_derivative_unweighted not implemented for 3D");
110 hessian = H.sparseView();
116 double AMIPS2D_energy(
double x0_rest,
double y0_rest,
double x1_rest,
double y1_rest,
double x2_rest,
double y2_rest,
double x0,
double y0,
double x1,
double y1,
double x2,
double y2)
118 const auto t0 = x0 * y1 - x0 * y2 - x1 * y0 + x1 * y2 + x2 * y0 - x2 * y1;
119 const auto t1 = 1.0 / (x0_rest * y1_rest - x0_rest * y2_rest - x1_rest * y0_rest + x1_rest * y2_rest + x2_rest * y0_rest - x2_rest * y1_rest);
120 const auto t2 = x0 - x1;
121 const auto t3 = x0_rest - x2_rest;
122 const auto t4 = x0 - x2;
123 const auto t5 = x0_rest - x1_rest;
124 const auto t6 = y0_rest - y2_rest;
125 const auto t7 = y0_rest - y1_rest;
126 const auto t8 = y0 - y2;
127 const auto t9 = y0 - y1;
128 return ((t0 * t1 > 0) ? (
129 t1 * (std::pow(t2 * t3 - t4 * t5, 2) + std::pow(t2 * t6 - t4 * t7, 2) + std::pow(-t3 * t9 + t5 * t8, 2) + std::pow(t6 * t9 - t7 * t8, 2)) / t0)
131 std::numeric_limits<double>::infinity()));
134 void AMIPS2D_gradient(
double x0_rest,
double y0_rest,
double x1_rest,
double y1_rest,
double x2_rest,
double y2_rest,
double x0,
double y0,
double x1,
double y1,
double x2,
double y2,
double g[2])
136 const auto t0 = x0 - x1;
137 const auto t1 = -y2_rest;
138 const auto t2 = t1 + y0_rest;
140 const auto t4 = t3 + x0;
141 const auto t5 = y0_rest - y1_rest;
142 const auto t6 = t4 * t5;
143 const auto t7 = t0 * t2 - t6;
144 const auto t8 = std::pow(t7, 2);
145 const auto t9 = 1.0 / (x0_rest * y1_rest - x0_rest * y2_rest - x1_rest * y0_rest + x1_rest * y2_rest + x2_rest * y0_rest - x2_rest * y1_rest);
146 const auto t10 = t1 + y1_rest;
147 const auto t11 = t10 * t9;
148 const auto t12 = 2 * t11;
149 const auto t13 = y0 - y1;
150 const auto t14 = -y2;
151 const auto t15 = t14 + y0;
152 const auto t16 = t15 * t5;
153 const auto t17 = t13 * t2 - t16;
154 const auto t18 = std::pow(t17, 2);
155 const auto t19 = -x2_rest;
156 const auto t20 = t19 + x0_rest;
157 const auto t21 = t0 * t20;
158 const auto t22 = x0_rest - x1_rest;
159 const auto t23 = t22 * t4;
160 const auto t24 = t21 - t23;
161 const auto t25 = t3 + x1;
162 const auto t26 = t13 * t20;
163 const auto t27 = t15 * t22 - t26;
164 const auto t28 = t14 + y1;
165 const auto t29 = std::pow(t27, 2);
166 const auto t30 = t18 + t29 + t8;
167 const auto t31 = x0 * y1 - x0 * y2 - x1 * y0 + x1 * y2 + x2 * y0 - x2 * y1;
168 const auto t32 = t9 / t31;
169 const auto t33 = t31 * t9 > 0;
170 const auto t34 = std::pow(t24, 2);
171 const auto t35 = t19 + x1_rest;
172 const auto t36 = t35 * t9;
173 const auto t37 = 2 * t36;
176 g[0] = t32 * (t10 * t9 * (std::pow(t24, 2) + t30) - t12 * t18 - t12 * t8 - 2 * t24 * (t11 * t21 - t11 * t23 + t25) - 2 * t27 * (t10 * t15 * t22 * t9 - t11 * t26 - t28));
184 g[1] = t32 * (2 * t17 * (t13 * t2 * t35 * t9 - t16 * t36 - t28) + t29 * t37 + t34 * t37 - t36 * (t30 + t34) + 2 * t7 * (t0 * t2 * t35 * t9 - t25 - t36 * t6));
192 void AMIPS2D_hessian(
double x0_rest,
double y0_rest,
double x1_rest,
double y1_rest,
double x2_rest,
double y2_rest,
double x0,
double y0,
double x1,
double y1,
double x2,
double y2,
double H[4])
194 const auto t0 = x0 - x1;
195 const auto t1 = -y2_rest;
196 const auto t2 = t1 + y0_rest;
198 const auto t4 = t3 + x0;
199 const auto t5 = y0_rest - y1_rest;
200 const auto t6 = t4 * t5;
201 const auto t7 = t0 * t2 - t6;
202 const auto t8 = std::pow(t7, 2);
203 const auto t9 = t1 + y1_rest;
204 const auto t10 = x0_rest * y1_rest - x0_rest * y2_rest - x1_rest * y0_rest + x1_rest * y2_rest + x2_rest * y0_rest - x2_rest * y1_rest;
205 const auto t11 = std::pow(t10, -2);
206 const auto t12 = 3 * t11;
207 const auto t13 = t12 * std::pow(t9, 2);
208 const auto t14 = y0 - y1;
209 const auto t15 = -y2;
210 const auto t16 = t15 + y0;
211 const auto t17 = t16 * t5;
212 const auto t18 = t14 * t2 - t17;
213 const auto t19 = std::pow(t18, 2);
214 const auto t20 = -x2_rest;
215 const auto t21 = t20 + x0_rest;
216 const auto t22 = t0 * t21;
217 const auto t23 = 1.0 / t10;
218 const auto t24 = t23 * t9;
219 const auto t25 = t22 * t24;
220 const auto t26 = x0_rest - x1_rest;
221 const auto t27 = t26 * t4;
222 const auto t28 = t24 * t27;
223 const auto t29 = t3 + x1;
224 const auto t30 = t25 - t28 + t29;
225 const auto t31 = t14 * t21;
226 const auto t32 = t24 * t31;
227 const auto t33 = t15 + y1;
228 const auto t34 = t16 * t23 * t26 * t9 - t32 - t33;
229 const auto t35 = t22 - t27;
230 const auto t36 = t30 * t35;
231 const auto t37 = 2 * t24;
232 const auto t38 = t16 * t26 - t31;
233 const auto t39 = t34 * t38;
234 const auto t40 = t19 * t24 + t24 * t8 + t36 + t39;
235 const auto t41 = x0 * y1 - x0 * y2 - x1 * y0 + x1 * y2 + x2 * y0 - x2 * y1;
236 const auto t42 = 2 / t41;
237 const auto t43 = t23 * t42;
238 const auto t44 = t23 * t41 > 0;
239 const auto t45 = t20 + x1_rest;
240 const auto t46 = t23 * t45;
241 const auto t47 = t46 * t6;
242 const auto t48 = t0 * t2 * t23 * t45 - t29 - t47;
243 const auto t49 = t48 * t7;
244 const auto t50 = t17 * t46;
245 const auto t51 = t14 * t2 * t23 * t45 - t33 - t50;
246 const auto t52 = t18 * t51;
247 const auto t53 = std::pow(t38, 2);
248 const auto t54 = t46 * t53 + t49 + t52;
249 const auto t55 = ((t44) ? (
250 t11 * t42 * (-t18 * t9 * (2 * t14 * t2 * t23 * t45 - t33 - 2 * t50) - t35 * t45 * (2 * t25 - 2 * t28 + t29) - t36 * t45 - t38 * t45 * (2 * t16 * t23 * t26 * t9 - 2 * t32 - t33) - t39 * t45 + t40 * t45 - t49 * t9 - t52 * t9 - t7 * t9 * (2 * t0 * t2 * t23 * t45 - t29 - 2 * t47) + t9 * (std::pow(t35, 2) * t46 + t54)))
253 const auto t56 = std::pow(t35, 2);
254 const auto t57 = t12 * std::pow(t45, 2);
255 const auto t58 = 2 * t46;
258 H[0] = t43 * (t13 * t19 + t13 * t8 + std::pow(t30, 2) + std::pow(t34, 2) + t36 * t37 + t37 * t39 - t37 * t40);
268 H[3] = t43 * (std::pow(t48, 2) + t49 * t58 + std::pow(t51, 2) + t52 * t58 + t53 * t57 + t56 * t57 - t58 * (t46 * t56 + t54));
void AMIPS2D_hessian(double x0_rest, double y0_rest, double x1_rest, double y1_rest, double x2_rest, double y2_rest, double x0, double y0, double x1, double y1, double x2, double y2, double H[4])
void AMIPS2D_gradient(double x0_rest, double y0_rest, double x1_rest, double y1_rest, double x2_rest, double y2_rest, double x0, double y0, double x1, double y1, double x2, double y2, double g[2])
double AMIPS2D_energy(double x0_rest, double y0_rest, double x1_rest, double y1_rest, double x2_rest, double y2_rest, double x0, double y0, double x1, double y1, double x2, double y2)
Eigen::SparseMatrix< double, Eigen::ColMajor > StiffnessMatrix