javascript - Quadratic Bezier Curve with inner Triangle -


recently building javascript module add convenience functions draw quadratic bezier curve. function have source point, target point , control point , create svg path this:

<path id="active" d="m"+sourcepoint+" q "+controlpoint+" "+ targetpoint+" " fill="orange"  fill-opacity="0.8" stroke="steelblue" stroke-width="2px" cursor="move"> 

the point have mention is, control point change dynamically, when change have figure this:

 note

i downloaded image this link.

this regular way draw quadratic curve outer triangle "imagine triangle p0,p1,p2 points".i don't know if there ways calculate b point on curve?

my goal draw quadratic curve inner triangle p1 on curve this:

enter image description here

is there way draw kind of quadratic curve or calculate b point on first picture?

formula find coordinates of point b @ needed value t on quadratic bezier curve (apply formula each coordinates x , y)

b(t) = p0 * (1-t)^2 + 2 * p1 * t * (1-t) + p2 * t^2

geometric subdivision approach:

let's q0 divides p0-p1 segment in t/(1-t) proportion

|p0q0|/|q0p1| = t/(1-t)

let's q1 divides p1-p2 segment in (1-t)/t proportion

|p1q1|/|q1p2| = (1-t)/t

b divides q0-q1 segment in t/(1-t) proportion

|q0b|/|bq1| = t/(1-t)

if want build curve through points p0 (start), c (somewhere in middle), , p2 (end), choose value of t point c, apply formula given, , find unknown control point p1. example, if t=1/2

c(1/2)=p0/4+2p1/4+p2/4 p1 = (4c - p0 - p2) / 2 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -